diff options
author | Vincent Ambo <tazjin@google.com> | 2019-08-08T22·41+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-08-28T13·36+0100 |
commit | ef4ded7b98f503b6d39c9e2fb843fb8de94279d9 (patch) | |
tree | 1cacfd6106ba037f3d0b8243ef80997754709790 /z-yants-tests.nix | |
parent | 5949663fcd843fe746f602f4a2509a11d8a94f06 (diff) |
docs: Add defun to README
Diffstat (limited to 'z-yants-tests.nix')
-rw-r--r-- | z-yants-tests.nix | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/z-yants-tests.nix b/z-yants-tests.nix new file mode 100644 index 000000000000..e089aab4670a --- /dev/null +++ b/z-yants-tests.nix @@ -0,0 +1,54 @@ +with (import ./yants.nix {}); +with builtins; + +# Note: Derivations are not included in the tests below as they cause +# issues with deepSeq. + +deepSeq rec { + # Test that all primitive types match + primitives = [ + (int 15) + (bool false) + (float 13.37) + (string "Hello!") + (function (x: x * 2)) + ]; + + # Test that polymorphic types work as intended + poly = [ + (option int null) + (list string [ "foo" "bar" ]) + (either int float 42) + ]; + + # Test that structures work as planned. + person = struct "person" { + name = string; + age = int; + + contact = option (struct { + email = string; + phone = option string; + }); + }; + + testPerson = person { + name = "Brynhjulf"; + age = 42; + contact.email = "brynhjulf@yants.nix"; + }; + + # Test enum definitions & matching + colour = enum "colour" [ "red" "blue" "green" ]; + testMatch = colour.match "red" { + red = "It is in fact red!"; + blue = throw "It should not be blue!"; + green = throw "It should not be green!"; + }; + + # Test curried function definitions + func = defun [ string int string ] + (name: age: "${name} is ${toString age} years old"); + + testFunc = func "Brynhjulf" 42; +} "All tests passed!\n" |