about summary refs log tree commit diff
path: root/yants-tests.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-08-08T21·20+0100
committerVincent Ambo <tazjin@google.com>2019-08-28T13·36+0100
commit1da22249bd65ffeb6de1382d0a39da9240e63091 (patch)
tree7b94587747d704b4211e0d154fdf0209c15e237f /yants-tests.nix
parent08116dbf51a771e148b11ed3486632a6ac11bca7 (diff)
test: Add some simple tests for type-checks
Does not currently test check failures, which makes it sort of not as
useful as you'd think.
Diffstat (limited to 'yants-tests.nix')
-rw-r--r--yants-tests.nix48
1 files changed, 48 insertions, 0 deletions
diff --git a/yants-tests.nix b/yants-tests.nix
new file mode 100644
index 0000000000..8847758ced
--- /dev/null
+++ b/yants-tests.nix
@@ -0,0 +1,48 @@
+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!";
+  };
+} "All tests passed!\n"