summaryrefslogtreecommitdiff
path: root/lib/std/test/option.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-08-26 12:20:58 -0700
committerOri Bernstein <ori@eigenstate.org>2015-08-26 12:20:58 -0700
commit2bc852bda98762d3bc01548bf972e3f1b137fbfb (patch)
tree74831deed3c9057c5fe0cbb8790d220e855bc792 /lib/std/test/option.myr
parent3de952510eb2a23350d24ed926f19c0cf72a12f2 (diff)
downloadmc-2bc852bda98762d3bc01548bf972e3f1b137fbfb.tar.gz
Move Myrddin libs to lib/ subdirectory.
Diffstat (limited to 'lib/std/test/option.myr')
-rw-r--r--lib/std/test/option.myr43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/std/test/option.myr b/lib/std/test/option.myr
new file mode 100644
index 0000000..fa8c5c0
--- /dev/null
+++ b/lib/std/test/option.myr
@@ -0,0 +1,43 @@
+use std
+
+const f = {x
+ if x == 123
+ -> `std.Some 42
+ else
+ -> `std.None
+ ;;
+}
+
+type t = struct
+ next : std.option(int)
+;;
+
+const main = {
+ var v, s : t
+
+ match `std.Some 42
+ | `std.Some x: std.assert(x == 42, "created wrong value\n")
+ | `std.None: std.assert(false, "should not be reached\n")
+ ;;
+
+ match `std.None
+ | `std.Some x: std.assert(x, "should not be reached\n")
+ | `std.None: /* everything ok */
+ ;;
+
+ v = f(123)
+ match v
+ | `std.Some x: std.assert(x == 42, "created wrong value\n")
+ | `std.None: std.assert(false, "should not be reached\n")
+ ;;
+
+ v = f(666)
+ match v
+ | `std.Some x: std.assert(false, "should not be reached\n")
+ | `std.None: /* everything ok */
+ ;;
+
+ s = [.next = `std.None]
+ s = [.next = `std.Some 123]
+}
+