feat(users/sterni/nix): move flow.match to string.match

After all it only matches strings.

Change-Id: I3d2e5221ef43f692de69028e78ed98b6b11f82d1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2586
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
sterni 2021-03-03 01:57:00 +01:00
parent ed3fce2b19
commit 8ff14cacb6
5 changed files with 17 additions and 14 deletions

View file

@ -44,11 +44,9 @@ let
# TODO(sterni): condf or magic # TODO(sterni): condf or magic
# like <nixpkgs/pkgs/build-support/coq/extra-lib.nix> # like <nixpkgs/pkgs/build-support/coq/extra-lib.nix>
match = val: matcher: matcher."${val}";
in { in {
inherit inherit
cond cond
match
; ;
} }

View file

@ -33,17 +33,7 @@ let
])) ]))
]; ];
testMatch = it "tests match" [
(assertEq "basic match usage" 42
(match "answer" {
"answer" = 42;
"banana" = dontEval;
"maleur" = dontEval;
}))
];
in in
runTestsuite "nix.flow" [ runTestsuite "nix.flow" [
testCond testCond
testMatch
] ]

View file

@ -12,7 +12,6 @@ let
int int
string string
fun fun
flow
; ;
testBounds = it "checks minBound and maxBound" [ testBounds = it "checks minBound and maxBound" [
@ -113,7 +112,7 @@ let
checkShift = { a, b, c, op }@args: checkShift = { a, b, c, op }@args:
let let
f = flow.match op { f = string.match op {
"<<" = int.bitShiftL; "<<" = int.bitShiftL;
">>" = int.bitShiftR; ">>" = int.bitShiftR;
}; };

View file

@ -55,6 +55,9 @@ let
then s then s
else pad { inherit char; "${side}" = diff; } s; else pad { inherit char; "${side}" = diff; } s;
# pattern matching for strings only
match = val: matcher: matcher."${val}";
in { in {
inherit inherit
take take
@ -67,5 +70,6 @@ in {
fromChars fromChars
pad pad
fit fit
match
; ;
} }

View file

@ -45,9 +45,21 @@ let
null) null)
]; ];
dontEval = builtins.throw "this should not get evaluated";
testMatch = it "tests match" [
(assertEq "basic match usage" 42
(string.match "answer" {
"answer" = 42;
"banana" = dontEval;
"maleur" = dontEval;
}))
];
in in
runTestsuite "nix.string" [ runTestsuite "nix.string" [
testTakeDrop testTakeDrop
testIndexing testIndexing
testFinding testFinding
testMatch
] ]