about summary refs log tree commit diff
path: root/nix/yants/tests
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-01-01T20·36+0100
committerProfpatsch <mail@profpatsch.de>2021-01-03T15·53+0000
commit4af195c5f294699340e349e936f994813a7112e4 (patch)
tree8a73883bdd3796dae6e4490b36aa8e0d5f22a394 /nix/yants/tests
parent2f063bc5b0b9ef7a077ce11910fde78bfe45f29b (diff)
feat(nix/yants): add restrict r/2050
`restrict` uses a predicate function to restrict a type, giving the
restricting a descriptive name in the process.

First, the wrapped type definition is checked (e.g. int) and then the
value is checked with the predicate, so the predicate can already
depend on the value being of the wrapped type.

Change-Id: Ic3edde45a8f34c31bc164414580d0a1aa5a821d5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2312
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'nix/yants/tests')
-rw-r--r--nix/yants/tests/default.nix7
1 files changed, 7 insertions, 0 deletions
diff --git a/nix/yants/tests/default.nix b/nix/yants/tests/default.nix
index da539ca3562b..8ad306df932b 100644
--- a/nix/yants/tests/default.nix
+++ b/nix/yants/tests/default.nix
@@ -92,4 +92,11 @@ deepSeq rec {
     (struct { a = int; b = option string; })
     (sum { a = int; b = option string; })
   ];
+
+  testRestrict = [
+    ((restrict "< 42" (i: i < 42) int) 25)
+    ((restrict "not too long" (l: builtins.length l < 3) (list int)) [ 1 2 ])
+    (list (restrict "eq 5" (v: v == 5) any) [ 5 5 5 ])
+  ];
+
 } (pkgs.writeText "yants-tests" "All tests passed!")