From 8ff14cacb69dce491c81a629595087525b455a3f Mon Sep 17 00:00:00 2001 From: sterni Date: Wed, 3 Mar 2021 01:57:00 +0100 Subject: 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 --- users/sterni/nix/flow/default.nix | 2 -- users/sterni/nix/flow/tests/default.nix | 10 ---------- users/sterni/nix/int/tests/default.nix | 3 +-- users/sterni/nix/string/default.nix | 4 ++++ users/sterni/nix/string/tests/default.nix | 12 ++++++++++++ 5 files changed, 17 insertions(+), 14 deletions(-) (limited to 'users/sterni/nix') diff --git a/users/sterni/nix/flow/default.nix b/users/sterni/nix/flow/default.nix index 838e65bfb20e..a9fe3c673532 100644 --- a/users/sterni/nix/flow/default.nix +++ b/users/sterni/nix/flow/default.nix @@ -44,11 +44,9 @@ let # TODO(sterni): condf or magic # like - match = val: matcher: matcher."${val}"; in { inherit cond - match ; } diff --git a/users/sterni/nix/flow/tests/default.nix b/users/sterni/nix/flow/tests/default.nix index 0bec4a3bd779..54cea01858e7 100644 --- a/users/sterni/nix/flow/tests/default.nix +++ b/users/sterni/nix/flow/tests/default.nix @@ -33,17 +33,7 @@ let ])) ]; - testMatch = it "tests match" [ - (assertEq "basic match usage" 42 - (match "answer" { - "answer" = 42; - "banana" = dontEval; - "maleur" = dontEval; - })) - ]; - in runTestsuite "nix.flow" [ testCond - testMatch ] diff --git a/users/sterni/nix/int/tests/default.nix b/users/sterni/nix/int/tests/default.nix index 966ac5a1289e..fac45dd251e1 100644 --- a/users/sterni/nix/int/tests/default.nix +++ b/users/sterni/nix/int/tests/default.nix @@ -12,7 +12,6 @@ let int string fun - flow ; testBounds = it "checks minBound and maxBound" [ @@ -113,7 +112,7 @@ let checkShift = { a, b, c, op }@args: let - f = flow.match op { + f = string.match op { "<<" = int.bitShiftL; ">>" = int.bitShiftR; }; diff --git a/users/sterni/nix/string/default.nix b/users/sterni/nix/string/default.nix index 782f86b7f79b..e2b27571c73f 100644 --- a/users/sterni/nix/string/default.nix +++ b/users/sterni/nix/string/default.nix @@ -55,6 +55,9 @@ let then s else pad { inherit char; "${side}" = diff; } s; + # pattern matching for strings only + match = val: matcher: matcher."${val}"; + in { inherit take @@ -67,5 +70,6 @@ in { fromChars pad fit + match ; } diff --git a/users/sterni/nix/string/tests/default.nix b/users/sterni/nix/string/tests/default.nix index 576952673471..2caecbfa7b3f 100644 --- a/users/sterni/nix/string/tests/default.nix +++ b/users/sterni/nix/string/tests/default.nix @@ -45,9 +45,21 @@ let 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 runTestsuite "nix.string" [ testTakeDrop testIndexing testFinding + testMatch ] -- cgit 1.4.1