ref: 2176941003e95b0c595fc37ca1a7a85e21f10d54
parent: b77533cb3d625cd5bc7a8779a07f033d4b81b687
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Apr 21 11:54:09 EDT 2015
Move tests from test/ directory to libstd/test/
Use mbld to run this shit.
--- /dev/null
+++ b/libstd/test/option.myr
@@ -1,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]
+}
+
--- /dev/null
+++ b/libstd/test/pathjoin.myr
@@ -1,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)
+ ;;
+}
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1726,7 +1726,7 @@
if (t->type == Tyvar && !noerr) {if (debugopt['T'])
dump(file, stdout);
- lfatal(t->loc, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(st, ctx));
+ fatal(ctx, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(st, ctx));
}
if (debugopt['u'] && !tyeq(orig, t)) {--- a/test/stdbigint.myr
+++ /dev/null
@@ -1,136 +1,0 @@
-use std
-
-type cmd = union
- `Add (cmd#, cmd#)
- `Sub (cmd#, cmd#)
- `Mul (cmd#, cmd#)
- `Div (cmd#, cmd#)
- `Mod (cmd#, cmd#)
- `Shl (cmd#, cmd#)
- `Shr (cmd#, cmd#)
- `Modpow (cmd#, cmd#, cmd#)
- `Val byte[:]
- `Res cmd#
-;;
-
-const main = {- var a, b, c, d, e
- var buf : byte[64], n
-
- /* a few combined ops */
- a = std.mkbigint(1234)
- b = std.mkbigint(0x7fffffff)
- c = std.mkbigint(7919)
- d = std.mkbigint(113051)
- e = std.mkbigint(11)
-
- std.bigmul(a, b)
- std.bigmul(a, b)
- std.bigadd(a, c)
- std.bigsub(a, d)
- std.bigdiv(a, e)
-
- std.bigfree(b)
- std.bigfree(c)
- std.bigfree(d)
- std.bigfree(e)
-
- n = std.bigbfmt(buf[:], a, 0)
- std.put("%s\n", buf[:n])-
- /* make sure we format '0' correctly */
- run(std.mk(`Res (std.mk(`Val "0"))))
- /* smoke test for division */
- run(std.mk(`Res \
- std.mk(`Div (\
- std.mk(`Val "1234_5678_1234_6789_6666_7777_8888"), \
- std.mk(`Val "1234_5678_1234_6789_6666_7777")))))
- run(std.mk(`Res \
- std.mk(`Div (\
- std.mk(`Val "0xffff_1234_1234_1234_1234"), \
- std.mk(`Val "0xf010_1234_2314")))))
- run(std.mk(`Res \
- std.mk(`Div (\
- std.mk(`Val "5192296858534810493479828944327220"), \
- std.mk(`Val "75557863709417659441940")))))
- run(std.mk(`Res \
- std.mk(`Div (\
- std.mk(`Val "75557863709417659441940"), \
- std.mk(`Val "5192296858534810493479828944327220")))))
-
- /* smoke test for mod */
- run(std.mk(`Res \
- std.mk(`Mod (\
- std.mk(`Val "5192296858534810493479828944327220"), \
- std.mk(`Val "75557863709417659441940")))))
-
- run(std.mk(`Res \
- std.mk(`Modpow (\
- std.mk(`Val "1"), \
- std.mk(`Val "3"), \
- std.mk(`Val "2")))))
-
- run(std.mk(`Res \
- std.mk(`Modpow (\
- std.mk(`Val "5192296858534810493479828944327220"), \
- std.mk(`Val "75557863709417659441940"), \
- std.mk(`Val "755578")))))
- run(std.mk(`Res \
- std.mk(`Modpow (\
- std.mk(`Val "7220"), \
- std.mk(`Val "755578"), \
- std.mk(`Val "75557863709417659441940")))))
-
-}
-
-const run = {e : cmd#- var buf : byte[2048]
- var a, b, c /* scratch vars */
- var n /* buf len */
-
- match e#
- | `Add (x, y): -> binop("+", std.bigadd, x, y)- | `Sub (x, y): -> binop("-", std.bigsub, x, y)- | `Mul (x, y): -> binop("*", std.bigmul, x, y)- | `Div (x, y): -> binop("/", std.bigdiv, x, y)- | `Mod (x, y): -> binop("%", std.bigmod, x, y)- | `Shl (x, y): -> binop("<<", std.bigshl, x, y)- | `Shr (x, y): -> binop(">>", std.bigshr, x, y)- | `Val x:
- a = try(std.bigparse(x))
- n = std.bigbfmt(buf[:], a, 0)
- std.put("%s", buf[:n])- -> a
- | `Res r:
- a = run(r)
- n = std.bigbfmt(buf[:], a, 0)
- std.put(" == %s\n", buf[:n])- -> a
- | `Modpow (x, y, z):
- std.put("("); - a = run(x)
- std.put(" ^ ")- b = run(y)
- std.put(") %% ")- c = run(z)
- -> std.bigmodpow(a, b, c)
- ;;
-}
-
-const binop = {name, op, x, y- var a, b
-
- a = run(x)
- std.put(" %s ", name)- b = run(y)
- op(a, b)
- std.bigfree(b)
- -> a
-}
-
-generic try = {x : std.option(@a)- match x
- | `std.Some v: -> v
- | `std.None: std.die("failed to get val")- ;;
-}
--- a/test/stdchartype.myr
+++ /dev/null
@@ -1,23 +1,0 @@
-use std
-
-const main = {- std.assert(std.isalpha('a'), "a should be alpha\n")- std.assert(std.isupper('A'), "A should be upper\n")- std.assert(std.islower('a'), "a should be lower\n")- std.assert(std.isdigit('0'), "0 should be isdigit\n")- std.assert(std.isnum('\u{0c66}'), "\u{0c66} should be isnum\n")- std.assert(std.isalnum('a'), "a should be isalnum\n")- std.assert(std.isalnum('0'), "0 should be isalnum\n")- std.assert(std.isspace(' '), "' ' should be isspace\n")- std.assert(std.isblank(' '), "' ' should be isblank\n")-
- std.assert(!std.isalpha('0'), "0 should not be alpha\n")- std.assert(!std.isupper('a'), "a should not be upper\n")- std.assert(!std.islower('A'), "A should not be lower\n")- std.assert(!std.isdigit('a'), "a should not be isdigit\n")- std.assert(!std.isnum('a'), " should not be isnum\n")- std.assert(!std.isalnum('}'), "a should not be isalnum\n")- std.assert(!std.isalnum('!'), "! should not be isalnum\n")- std.assert(!std.isspace('@'), "@ should not be isspace\n")- std.assert(!std.isblank('@'), "@ should not be isblank\n")-}
--- a/test/stdfmtpad.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-
-const main = {- std.put("%10s\n", "abcd")- std.put("%010s\n", "bdcae")- std.put("%010s\n", "abcdefghijkl")- std.put("%01s\n", "a")- std.put("%10i\n", 10)- std.put("%010i\n", 10)- std.put("%010ui\n", -1)- std.put("%010i\n", -1)- std.put("%10i\n", -1)- std.put("%3i\n", 100000)-}
--- a/test/stdopt-mk.myr
+++ /dev/null
@@ -1,20 +1,0 @@
-use std
-
-const f = {x- if x == 123
- -> `std.Some 42
- else
- -> `std.None
- ;;
-}
-
-const main = {- var v
-
- v = f(123)
- match v
- | `std.Some x: std.exit(x)
- | `std.None: std.exit(123)
- ;;
-}
-
--- a/test/stdopt-none.myr
+++ /dev/null
@@ -1,13 +1,0 @@
-use std
-
-const f = {- -> `std.None
-}
-
-const main = {- match f()
- | `std.Some x: std.exit(x)
- | `std.None: std.exit(42)
- ;;
-}
-
--- a/test/stdopt-some.myr
+++ /dev/null
@@ -1,9 +1,0 @@
-use std
-
-const main = {- match `std.Some 42
- | `std.Some x: std.exit(x)
- | `std.None: std.exit(1)
- ;;
-}
-
--- a/test/stdopt-struct.myr
+++ /dev/null
@@ -1,9 +1,0 @@
-use std
-
-type t = struct
- next : std.option(int)
-;;
-
-const main = {- std.exit(42)
-}
--- a/test/stdpathnorm.myr
+++ /dev/null
@@ -1,46 +1,0 @@
-use std
-
-const main = {- /* untouched */
- std.put("%s\n", std.pathnorm(""))- std.put("%s\n", std.pathnorm("foo"))- std.put("%s\n", std.pathnorm("foo/bar"))- std.put("%s\n", std.pathnorm("/foo/bar"))- std.put("%s\n", std.pathnorm("."))-
- /* empty path becomes "." */
- std.put("%s\n", std.pathnorm("."))-
- /* delete //, trailing / */
- std.put("%s\n", std.pathnorm("foo/"))- std.put("%s\n", std.pathnorm("foo//bar/baz"))- std.put("%s\n", std.pathnorm("//foo//bar/"))-
- /* delete '.' */
- std.put("%s\n", std.pathnorm("foo/./bar"))- std.put("%s\n", std.pathnorm("/foo/bar/."))- std.put("%s\n", std.pathnorm("./foo/bar/."))-
- /* elide '..' */
- std.put("%s\n", std.pathnorm("/../foo/bar"))- std.put("%s\n", std.pathnorm("../../foo/bar"))- std.put("%s\n", std.pathnorm("foo/bar/.."))- std.put("%s\n", std.pathnorm("foo/bar/../.."))- std.put("%s\n", std.pathnorm("foo/../bar/../.."))- std.put("%s\n", std.pathnorm("/foo/../bar/../.."))-
- /* mix all of the above */
- std.put("%s\n", std.pathnorm("/../foo//bar"))- std.put("%s\n", std.pathnorm("..//../foo/bar"))- std.put("%s\n", std.pathnorm("foo//./bar/.."))- std.put("%s\n", std.pathnorm("foo/bar/.././.."))- std.put("%s\n", std.pathnorm("//foo/../bar/../.."))- std.put("%s\n", std.pathnorm("foo/../bar/../.."))-
- /* vanilla pathjoin */
- std.put("%s\n", std.pathcat("a", "b"))- std.put("%s\n", std.pathjoin(["a", "b", "c"][:]))- /* pathjoin with empty dirs */
- std.put("%s\n", std.pathcat("", "foo"))- std.put("%s\n", std.pathjoin(["", "foo", "bar"][:]))-}
--- a/test/stdsearch.myr
+++ /dev/null
@@ -1,34 +1,0 @@
-use std
-
-const sl = [1, 3, 5, 8, 9, 33]
-
-const main = {-
- expect(std.lsearch(sl[:], 1, std.numcmp), `std.Some 0)
- expect(std.lsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
- expect(std.lsearch(sl[:], 5, std.numcmp), `std.Some 2)
- expect(std.lsearch(sl[:], 6, std.numcmp), `std.None)
-
- expect(std.bsearch(sl[:], 1, std.numcmp), `std.Some 0)
- expect(std.bsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
- expect(std.bsearch(sl[:], 5, std.numcmp), `std.Some 2)
- expect(std.bsearch(sl[:], 6, std.numcmp), `std.None)
-}
-
-const expect = {a, b- match a
- | `std.None:
- match b
- | `std.Some x: std.fatal(1, "Expected `std.None, `std.None, got `std.None, `std.Some %i\n", x)
- | `std.None: /* nothing */
- ;;
- | `std.Some x:
- match b
- | `std.None: std.fatal(1, "Expected `std.Some %i, `std.Some %i, got `std.Some %i, `std.None\n", x, x, x)
- | `std.Some y:
- if x != y
- std.fatal(1, "Expected `std.Some %i, `std.Some %i, got `std.Some %i, `std.Some %i\n", x, x, x, y)
- ;;
- ;;
- ;;
-}
--- a/test/stdslcp.myr
+++ /dev/null
@@ -1,19 +1,0 @@
-use std
-
-const main = {- var a = [1,2,3,4,5]
- var b = [6,7,8,9,10]
-
-
- std.slcp(a[:a.len-2], a[2:])
- std.slcp(b[2:], b[:b.len-2])
-
- for x in a
- std.put("%i ", x)- ;;
- std.put("\n")- for x in b
- std.put("%i ", x)- ;;
- std.put("\n")-}
--- a/test/stdsort.myr
+++ /dev/null
@@ -1,40 +1,0 @@
-use std
-
-const main = {- var a = [
- 3, 5, 4, 9, 7, 2, 6, 0, 1, 8,
- ]
- var b = [
- 3, 4, 5, 1, 2, 6, 7, 8, 9, 10
- ]
- var c = [
- "a", "aa", "b", "C", "Cc", "cC", "d", "f", "fuckit", "go",
- ]
-
- std.sort(a[:], intcmp)
- for v in a
- std.put("%i\n", v)- ;;
- std.put("---\n")- std.sort(b[:], std.numcmp)
- for v in b
- std.put("%i\n", v)- ;;
- std.put("---\n")- std.sort(c[:], std.strcmp)
- for v in c
- std.put("%s\n", v)- ;;
-}
-
-const intcmp = {a, b- if a < b
- -> `std.Before
- elif a == b
- -> `std.Equal
- else
- -> `std.After
- ;;
-}
-
-
--- a/test/stdtry.myr
+++ /dev/null
@@ -1,8 +1,0 @@
-use std
-
-const main = {- var x = `std.Some 123
- std.try(x)
- x = `std.None
- std.try(x)
-}
--- a/test/tests
+++ b/test/tests
@@ -92,10 +92,6 @@
# B genericchain P 'val = 123' ## BUGGERED
B genericmake P 'val = 123'
B genericuret E 42
-B stdopt-some E 42
-B stdopt-none E 42
-B stdopt-mk E 42
-B stdopt-struct E 42
B sizeof E 4
B gsizeof E 5
B matchint E 84
@@ -125,20 +121,12 @@
B import-type E 0
B helloworld P Hello-世界
B encodechar P 1世界äa
-B stdsearch E 0
-B stdchartype E 0
-B stdtry C
B strtab C
B catfile C
-B stdsort C
B strstrip C
B strsplit C
B strfind C
B strjoin C
-B stdslcp C
-B stdfmtpad C
-B stdpathnorm C
-B stdbigint C
B exporttrait
# B local-labels E 10 ## BUGGERED
F declmismatch
--
⑨