diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/collections.nom | 23 | ||||
| -rw-r--r-- | tests/colors.nom | 3 | ||||
| -rw-r--r-- | tests/control_flow.nom | 80 | ||||
| -rw-r--r-- | tests/coroutines.nom | 10 | ||||
| -rw-r--r-- | tests/errors.nom | 2 | ||||
| -rw-r--r-- | tests/inner/inner.nom | 3 | ||||
| -rw-r--r-- | tests/math.nom | 3 | ||||
| -rw-r--r-- | tests/metaprogramming.nom | 31 | ||||
| -rw-r--r-- | tests/object.nom | 18 | ||||
| -rw-r--r-- | tests/operators.nom | 27 | ||||
| -rw-r--r-- | tests/os.nom | 3 | ||||
| -rw-r--r-- | tests/scopes.nom | 3 | ||||
| -rw-r--r-- | tests/text.nom | 37 |
13 files changed, 151 insertions, 92 deletions
diff --git a/tests/collections.nom b/tests/collections.nom index f8b813f..660fd1b 100644 --- a/tests/collections.nom +++ b/tests/collections.nom @@ -1,13 +1,14 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 #.. Tests for the stuff defined in core/control_flow.nom use "core" + assume ((2 nd to last in [1, 2, 3, 4, 5]) == 4) assume (3 is in [1, 2, 3, 4, 5]) assume (99 isn't in [1, 2, 3]) -assume ({x: no} has key "x") -assume ({x: no} doesn't have key "y") -assume (not ({x: no} doesn't have key "x")) +assume ({x:no} has key "x") +assume ({x:no} doesn't have key "y") +assume (not ({x:no} doesn't have key "x")) assume ((length of [1, 2, 3]) == 3) %list = [1, 2, 3, 4, 5] append 6 to %list @@ -17,20 +18,20 @@ assume ((last in %list) == 5) remove index 1 from %list assume ((first in %list) == 2) assume (((% * %) for % in [1, 2, 3]) == [1, 4, 9]) -assume ((%k = (%v * %v) for %k = %v in {x: 1, y: 2, z: 3}) == {x: 1, y: 4, z: 9}) -assume ((%k for %k = %v in {x: 1}) == ["x"]) -assume ((% = (% * %) for % in [1, 2, 3]) == {1: 1, 2: 4, 3: 9}) +assume ((%k = (%v * %v) for %k = %v in {x:1, y:2, z:3}) == {x:1, y:4, z:9}) +assume ((%k for %k = %v in {x:1}) == ["x"]) +assume ((% = (% * %) for % in [1, 2, 3]) == {1:1, 2:4, 3:9}) assume (([[1, 2], [3, 4]] flattened) == [1, 2, 3, 4]) -assume ((entries in {x: 1}) == [{key: "x", value: 1}]) -assume ((keys in {x: 1}) == ["x"]) -assume ((values in {x: 1}) == [1]) +assume ((entries in {x:1}) == [{key:"x", value:1}]) +assume ((keys in {x:1}) == ["x"]) +assume ((values in {x:1}) == [1]) assume ((sorted [3, 1, 2]) == [1, 2, 3]) %x = [3, 1, 2] sort %x assume (%x == [1, 2, 3]) sort %x by % = (- %) assume (%x == [3, 2, 1]) -%keys = {1: 999, 2: 0, 3: 50} +%keys = {1:999, 2:0, 3:50} sort %x by % = %keys.% assume (%x == [2, 3, 1]) assume ((unique [1, 2, 1, 3, 2, 3]) == [1, 2, 3]) diff --git a/tests/colors.nom b/tests/colors.nom index da1b2e3..042ba43 100644 --- a/tests/colors.nom +++ b/tests/colors.nom @@ -1,3 +1,4 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 use "lib/consolecolor.nom" + say (bright (green "Color test passed."))
\ No newline at end of file diff --git a/tests/control_flow.nom b/tests/control_flow.nom index 6312d77..7a6a743 100644 --- a/tests/control_flow.nom +++ b/tests/control_flow.nom @@ -1,19 +1,27 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 # Tests for the stuff defined in core/control_flow.nom use "core" + do nothing action [test conditionals]: if (yes): %loc1 = (yes) - if (no): barf "entered if 'no' conditional" - unless (yes): barf "entered unless 'yes' conditional" + if (no): + barf "entered if 'no' conditional" + + unless (yes): + barf "entered unless 'yes' conditional" + if (yes): %loc2 = (yes) - ..else: barf "entered if 'yes' else conditional" + ..else: + barf "entered if 'yes' else conditional" unless (no) (%loc3 = (yes)) else (barf "entered unless 'no' else conditional") -assume (all of [%loc1 == (nil), %loc2 == (nil), %loc3 == (nil)]) or barf "conditionals leaking locals" +assume (all of [%loc1 == (nil), %loc2 == (nil), %loc3 == (nil)]) or barf ".." + conditionals leaking locals + assume ((5 if (yes) else 1) == 5) assume ((5 if (no) else 1) == 1) action [return nil] (return (nil)) @@ -28,13 +36,14 @@ assume (%tot == 6) or barf "for-loop failed" repeat: %x += 1 if (%x == 3): stop repeating - if (%x > 3): barf "Failed to stop repeat loop" + if (%x > 3): + barf "Failed to stop repeat loop" assume (%x == 3) or barf "Failed to repeat" %x = 0 repeat 5 times: %x += 1 assume (%x == 5) or barf "Failed to repeat 5 times" -set {%x: 0, %y: 0} +set {%x:0, %y:0} for % in [1, 2, 3]: repeat 5 times: do next repeat @@ -43,7 +52,7 @@ for % in [1, 2, 3]: %y += 1 assume ([%x, %y] == [0, 3]) or barf "Failed to continue repeat" -set {%x: 0, %y: 0} +set {%x:0, %y:0} for % in [1, 2, 3]: repeat 5 times: do next % @@ -52,7 +61,7 @@ for % in [1, 2, 3]: %y += 1 assume ([%x, %y] == [0, 0]) or barf "Failed to continue for" -set {%x: 0, %y: 0} +set {%x:0, %y:0} for % in [1, 2, 3]: repeat 5 times: stop repeating @@ -61,7 +70,7 @@ for % in [1, 2, 3]: %y += 1 assume ([%x, %y] == [0, 3]) or barf "Failed to stop repeat" -set {%x: 0, %y: 0} +set {%x:0, %y:0} for % in [1, 2, 3]: repeat 5 times: stop % @@ -83,59 +92,70 @@ assume (%x == 6) or barf "Numeric for range failed" for %i in 3 to 1 via -1: %x += %i assume (%x == 6) or barf "backwards numeric for range failed" %result = {} -for %key = %value in {x: 1, y: 2}: %result."\%key\%key" = (%value * 11) -assume (%result == {xx: 11, yy: 22}) or barf "key/value iteration failed" -for %key = %value in {x: 1, y: 2}: +for %key = %value in {x:1, y:2}: + %result."\%key\%key" = (%value * 11) + +assume (%result == {xx:11, yy:22}) or barf "key/value iteration failed" +for %key = %value in {x:1, y:2}: stop %key barf "stopping key failed" -for %key = %value in {x: 1, y: 2}: +for %key = %value in {x:1, y:2}: stop %value barf "stopping value failed" -for %key = %value in {x: 1}: +for %key = %value in {x:1}: stop %key stop %value do next %key do next %value -for %key = %value in {x: 1, y: 2}: +for %key = %value in {x:1, y:2}: do next %key barf "skipping key failed" -for %key = %value in {x: 1, y: 2}: +for %key = %value in {x:1, y:2}: do next %value barf "skipping value failed" -action [barfer]: barf "this should never be reached" +action [barfer]: + barf "this should never be reached" + if: (no): barf "'when' fail" - (no) (3 > 4): barf "'when' fail 2" + (no) (3 > 4): + barf "'when' fail 2" + (yes) (barfer): do nothing - (99 > 1): barf "Fell through incorrectly" + (99 > 1): + barf "Fell through incorrectly" %else_worked = (no) if: (no): barf - else: %else_worked = (yes) - - + else: + %else_worked = (yes) assume %else_worked or barf "when..else failed" action [test when scope]: if (yes): %leaked = (yes) + test when scope assume (not %leaked) or barf "'when' is leaking locals" %when_worked = (no) if 4 is: - 1 2: barf "'when = ?' fail" - 3 4 (barfer): %when_worked = (yes) + 1 2: + barf "'when = ?' fail" + + 3 4 (barfer): + %when_worked = (yes) assume %when_worked %when_worked = (no) if 5 is: 6: barf - else: %when_worked = (yes) + else: + %when_worked = (yes) assume %when_worked %x = 1 @@ -147,12 +167,14 @@ assume (..) %n = 0 for % in [1, 2, 3]: %n += % return %n - .. == 6 + ..== 6 + %t = [1, [2, [[3], 4], 5, [[[6]]]]] %flat = [] for % in recursive %t: - if ((type of %) is "table"): for %2 in %: recurse % on %2 + if ((type of %) is "table"): + for %2 in %: recurse % on %2 ..else: add % to %flat assume ((sorted %flat) == [1, 2, 3, 4, 5, 6]) -say "Control flow test passed." +say "Control flow test passed."
\ No newline at end of file diff --git a/tests/coroutines.nom b/tests/coroutines.nom index a67e1c8..288ba90 100644 --- a/tests/coroutines.nom +++ b/tests/coroutines.nom @@ -1,10 +1,16 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 # Tests for the stuff defined in core/control_flow.nom use "core" + %nums = [] -%co = (coroutine (: -> 4; -> 5; repeat 3 times: -> 6)) +%co = (..) + coroutine: + -> 4 + -> 5 + repeat 3 times: -> 6 + for % in coroutine %co (add % to %nums) assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed" say "Coroutines test passed."
\ No newline at end of file diff --git a/tests/errors.nom b/tests/errors.nom index af918a6..766225d 100644 --- a/tests/errors.nom +++ b/tests/errors.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 # Tests for the stuff defined in core/errors.nom diff --git a/tests/inner/inner.nom b/tests/inner/inner.nom index 903e0c0..5a4fc63 100644 --- a/tests/inner/inner.nom +++ b/tests/inner/inner.nom @@ -1,3 +1,4 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 use "core" + say "Inner directory 'use' test passed."
\ No newline at end of file diff --git a/tests/math.nom b/tests/math.nom index f740315..48468ce 100644 --- a/tests/math.nom +++ b/tests/math.nom @@ -1,7 +1,8 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 #.. Tests for the stuff defined in core/control_flow.nom use "core" + assume (all of [inf, pi, tau, golden ratio, e]) or barf "math constants failed" %nan = (NaN) assume (%nan != %nan) or barf "NaN failed" diff --git a/tests/metaprogramming.nom b/tests/metaprogramming.nom index b8dfde0..30c42ed 100644 --- a/tests/metaprogramming.nom +++ b/tests/metaprogramming.nom @@ -1,8 +1,9 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 # Tests for the stuff defined in core/metaprogramming.nom use "core" + compile [five] to (Lua value "5") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -41,16 +42,24 @@ parse [V] as (five) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assume ((V) == 5) or barf "Parse as compile action failed." -parse [swap %x and %y] as (do (: %tmp = %x; %x = %y; %y = %tmp)) +parse [swap %x and %y] as (..) + do: + %tmp = %x + %x = %y + %y = %tmp ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -set {%1: 1, %2: 2} +set {%1:1, %2:2} swap %1 and %2 -assume ((%1 == 2) and (%2 == 1)) or barf "'parse % as %' failed on 'swap % and %'" -set {%tmp: 1, %tmp2: 2} +assume ((%1 == 2) and (%2 == 1)) or barf ".." + 'parse % as %' failed on 'swap % and %' + +set {%tmp:1, %tmp2:2} swap %tmp and %tmp2 -assume ((%tmp == 2) and (%tmp2 == 1)) or barf "'parse % as %' variable mangling failed." +assume ((%tmp == 2) and (%tmp2 == 1)) or barf ".." + 'parse % as %' variable mangling failed. + # remove action (foo %) @@ -58,10 +67,14 @@ assume ((%tmp == 2) and (%tmp2 == 1)) or barf "'parse % as %' variable mangling ..and if it succeeds: barf "Failed to delete action" assume ((\(5 + 5) as value) == 10) or barf "%tree as value failed." -assume ("\(\(foo %x) as nomsu)" == "foo %x") or barf "action source code failed." -assume ("\(\(%x) as nomsu)" == "%x") or barf "var source code failed." +assume ("\(\(foo %x) as nomsu)" == "foo %x") or barf ".." + action source code failed. + +assume ("\(\%x as nomsu)" == "%x") or barf "var source code failed." assume ((type of {}) == "table") or barf "type of failed." -assume ("\(\(%x) as lua identifier)" == "_x") or barf "converting to identifier failed." +assume ("\(\%x as lua identifier)" == "_x") or barf ".." + converting to identifier failed. + assume ((run "return 99") == 99) or barf "run % failed." %code = (Lua "global_x = true;") lua> %code diff --git a/tests/object.nom b/tests/object.nom index 186957d..d29fcdd 100644 --- a/tests/object.nom +++ b/tests/object.nom @@ -1,9 +1,10 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 # Tests for the object model defined in lib/object.nom use "core" use "lib/object.nom" + object "Dog": (class Dog).genus = "Canus" method [initialize %] (%.barks or= 0) @@ -13,7 +14,7 @@ object "Dog": method [get pissed off] ((me).barks += 1) -%d = (new Dog {barks: 2}) +%d = (new Dog {barks:2}) as %d: assume ((me) == %d) assume ((me).barks == 2) @@ -28,17 +29,18 @@ assume ("\(%d.class)" == "Dog") assume (%d.genus == "Canus") assume (%d.barks == 3) as (new Dog) (assume ((me).barks == 0) or barf "Default initializer failed") -as (new Dog {barks: 1}) (assume ((bark) == "Bark!")) -action [foo] (as (new Dog {barks: 23}) (return (me).barks)) +as (new Dog {barks:1}) (assume ((bark) == "Bark!")) +action [foo] (as (new Dog {barks:23}) (return (me).barks)) assume ((foo) == 23) or barf "Oops, \(foo) != 23" -as (new Dog {barks: 101}): - try (as (new Dog {barks: 8}) (barf)) and if it succeeds (barf) - assume ((me).barks == 101) or barf "Error in nested 'as % %' failed to properly reset 'self'" +as (new Dog {barks:101}): + try (as (new Dog {barks:8}) (barf)) and if it succeeds (barf) + assume ((me).barks == 101) or barf ".." + Error in nested 'as % %' failed to properly reset 'self' object "Corgi" extends (class Dog) (method [sploot] "splooted") %corg = (new Corgi) assume (%corg.barks == 0) -as (new Corgi {barks: 1}): +as (new Corgi {barks:1}): assume ((sploot) == "splooted") or barf "subclass method failed" assume ((bark) == "Bark!") or barf "inheritance failed" assume ((woof) == "Bark!") diff --git a/tests/operators.nom b/tests/operators.nom index a8f7bfd..6a9cced 100644 --- a/tests/operators.nom +++ b/tests/operators.nom @@ -1,10 +1,11 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 #.. Tests for the stuff defined in core/operators.nom use "core" -set {%x: 10, %y: 20} + +set {%x:10, %y:20} assume ((%x == 10) and (%y == 20)) or barf "mutli-assignment failed." -set {%x: %y, %y: %x} +set {%x:%y, %y:%x} assume ((%y == 10) and (%x == 20)) or barf "swapping vars failed." % = [..] %x < %y, %x <= %y, %x > %y, %x >= %y, %x == %y, %x is %y, %x != %y, %x isn't %y @@ -12,30 +13,34 @@ assume ((%y == 10) and (%x == 20)) or barf "swapping vars failed." assume ({} is {}) or barf "Equality check failed." assume (({} 's id) is not ({} 's id)) or barf "Identity check failed." -set {%foozle: "outer", %y: "outer"} +set {%foozle:"outer", %y:"outer"} action [set global x local y]: external %foozle = "inner" %y = "inner" set global x local y assume ((%foozle == "inner") and (%y == "outer")) or barf "external failed." -set {%foozle: "outer", %y: "outer"} +set {%foozle:"outer", %y:"outer"} action [set global x local y] (..) with external [%foozle]: %foozle = "inner" %y = "inner" set global x local y -assume ((%foozle == "inner") and (%y == "outer")) or barf "'with external' failed." -set {%x: 1, %y: 2} -with {%z: nil, %x: 999}: +assume ((%foozle == "inner") and (%y == "outer")) or barf ".." + 'with external' failed. + +set {%x:1, %y:2} +with {%z:nil, %x:999}: %z = 999 assume (%z == 999) or barf "'with' failed." assume (%x == 999) or barf "'with' assignment failed." assume (%x == 1) or barf "'with' scoping failed" assume (%z == (nil)) or barf "'with' scoping failed" -assume ((1 + 2 * 3 - 4 / 2 ^ 2) == 6) or barf "math expressions not working properly" +assume ((1 + 2 * 3 - 4 / 2 ^ 2) == 6) or barf ".." + math expressions not working properly + assume ((5 wrapped around 2) == 1) or barf "mod not working" assume (1 <= 2 < 3) or barf "chained operator fail." %value = -999 @@ -43,7 +48,9 @@ action [flipflop]: external %value = (- %value) return %value -assume (not (1 < (flipflop) < 1)) or barf "3-way inequality evaluated middle term twice" +assume (not (1 < (flipflop) < 1)) or barf ".." + 3-way inequality evaluated middle term twice + assume (((yes) and (yes)) == (yes)) action [barfer] (barf "short circuiting failed") assume (((no) and (barfer)) == (no)) diff --git a/tests/os.nom b/tests/os.nom index c96306b..c0a2403 100644 --- a/tests/os.nom +++ b/tests/os.nom @@ -1,9 +1,10 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 # Tests for the stuff defined in lib/os.nom use "core" use "lib/os.nom" + %lines = (lines in (read file "tests/os.nom")) assume (%lines.3 == " Tests for the stuff defined in lib/os.nom") %n = 0 diff --git a/tests/scopes.nom b/tests/scopes.nom index 4d20dd7..9af8383 100644 --- a/tests/scopes.nom +++ b/tests/scopes.nom @@ -1,5 +1,6 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 use "core" + %x = "outer" with local %x: %x = "inner" diff --git a/tests/text.nom b/tests/text.nom index a002445..d680560 100644 --- a/tests/text.nom +++ b/tests/text.nom @@ -1,43 +1,46 @@ -#!/usr/bin/env nomsu -V2.4.4.3 +#!/usr/bin/env nomsu -V2.5.4.3 #.. Tests for the stuff defined in core/text.nom use "core" + assume ((["x", "y"] joined with ",") == "x,y") or barf "joined with failed" assume ((["x", "y"] joined) == "xy") or barf "joined failed" assume (("asdf" capitalized) == "Asdf") or barf "capitalized failed" -assume (("asdf" with "X" instead of "s") == "aXdf") or barf "substitution failed" -assume (..) - "\n" == (newline) -..or barf "Text literals failed." +assume (("asdf" with "X" instead of "s") == "aXdf") or barf ".." + substitution failed +assume ("\n" == (newline)) or barf "Text literals failed." assume (("x" + "y") == "xy") assume (..) (..) - lines in "one\ntwo" + lines in ".." + one + two ..== ["one", "two"] parse [アクション %spec %body] as (action %spec %body) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -%こんにちは = "\227\129\147\227\130\147\227\129\171\227\129\161\227\129\175" -アクション [% と言う] "\(%)\228\184\150\231\149\140" -assume (..) - (%こんにちは と言う) == ".." - こんにちは世界 -..or barf "Unicode doesn't work" +%こんにちは = "こんにちは" +アクション [% と言う] "\(%)世界" +assume ((%こんにちは と言う) == "こんにちは世界") or barf ".." + Unicode doesn't work %s = "one two\\nthreefour" -assume (..) - %s == "one two\\nthreefour" -..or barf "%s = \(quote %s), not \(quote "one two\\nthreefour")" +assume (%s == "one two\\nthreefour") or barf ".." + %s = \(quote %s), not \(quote "one two\\nthreefour") %s = "list:\[1, 2, 3]" assume (%s == "list:[1, 2, 3]") assume ("foo = \(1 + 2)!" == "foo = 3!") assume (..) - "one\ntwo" - ..== "one\ntwo" + ".." + one + two + ..== ".." + one + two assume ("nogap" == "nogap") |
