summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-04-21 15:54:09 -0700
committerOri Bernstein <ori@eigenstate.org>2015-04-21 15:54:09 -0700
commitc2f307b1be950ca0a1e59b48143c41cde47a6cdd (patch)
tree117ebe3af04beb187ebe3226b052b912289c6237 /libstd
parenteb9b1b09df9967e63bfe4438e751bf2667793b8a (diff)
downloadmc-c2f307b1be950ca0a1e59b48143c41cde47a6cdd.tar.gz
Move tests from test/ directory to libstd/test/
Use mbld to run this shit.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/test/option.myr43
-rw-r--r--libstd/test/pathjoin.myr61
2 files changed, 104 insertions, 0 deletions
diff --git a/libstd/test/option.myr b/libstd/test/option.myr
new file mode 100644
index 0000000..fa8c5c0
--- /dev/null
+++ b/libstd/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]
+}
+
diff --git a/libstd/test/pathjoin.myr b/libstd/test/pathjoin.myr
new file mode 100644
index 0000000..18e313d
--- /dev/null
+++ b/libstd/test/pathjoin.myr
@@ -0,0 +1,61 @@
+use std
+
+const main = {
+ /* untouched */
+ norm("foo", "foo")
+ norm("foo/bar", "foo/bar")
+ norm("/foo/bar", "/foo/bar")
+ norm(".", ".")
+
+ /* empty path becomes "." */
+ norm("", ".")
+
+ /* delete //, trailing / */
+ norm("foo/", "foo")
+ norm("foo//bar/baz", "foo/bar/baz")
+ norm("//foo//bar/", "/foo/bar")
+
+ /* delete '.' */
+ norm("foo/./bar", "foo/bar")
+ norm("/foo/bar/.", "/foo/bar")
+ norm("./foo/bar/.", "foo/bar")
+
+ /* elide '..' */
+ norm("/../foo/bar", "/foo/bar")
+ norm("../../foo/bar", "../../foo/bar")
+ norm("foo/bar/..", "foo")
+ norm("foo/bar/../..", ".")
+ norm("foo/../bar/../..", "..")
+ norm("/foo/../bar/../..", "/")
+
+ /* mix all of the above */
+ norm("/../foo//bar", "/foo/bar")
+ norm("..//../foo/bar", "../../foo/bar")
+ norm("foo//./bar/..", "foo")
+ norm("foo/bar/.././..", ".")
+ norm("//foo/../bar/../..", "/")
+ norm("foo/../bar/../..", "..")
+
+ /* vanilla pathjoin */
+ eq(std.pathcat("a", "b"), "a/b")
+ eq(std.pathjoin(["a", "b", "c"][:]), "a/b/c")
+ /* pathjoin with empty dirs */
+ eq(std.pathcat("", "foo"), "foo")
+ eq(std.pathjoin(["", "foo", "bar"][:]), "foo/bar")
+}
+
+const norm = {a, b
+ var p
+
+ p = std.pathnorm(a)
+ if !std.sleq(p, b)
+ std.fatal(1, "mismatched paths: '%s' => '%s' != '%s'\n", a, p, b)
+ ;;
+ std.slfree(p)
+}
+
+const eq = {a, b
+ if !std.sleq(a, b)
+ std.fatal(1, "mismatched paths: '%s' != '%s'\n", a, b)
+ ;;
+}