aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/text.nom2
-rw-r--r--tests/control_flow.nom23
-rw-r--r--tests/coroutines.nom18
-rw-r--r--tests/errors.nom22
-rw-r--r--tests/os.nom10
-rw-r--r--tests/text.nom5
6 files changed, 56 insertions, 24 deletions
diff --git a/core/text.nom b/core/text.nom
index e6065c1..8b26ccb 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -20,7 +20,7 @@ compile [%text with %sub instead of %patt, %text s/%patt/%sub] to
action [lines in %text, lines of %text]
lua> ".."
- local result = {}
+ local result = list{}
for line in (\%text):gmatch('[^\n]+') do
result[#result+1] = line
end
diff --git a/tests/control_flow.nom b/tests/control_flow.nom
index 238bcbf..56c99a0 100644
--- a/tests/control_flow.nom
+++ b/tests/control_flow.nom
@@ -159,32 +159,11 @@ when 5 = ?
* else: %when_worked <- (yes)
assume %when_worked
-try: barf
-..and if it succeeds: barf "try failed."
-
-%worked <- (no)
-try: barf
-..and if it barfs: %worked <- (yes)
-assume %worked or barf "try/catch failed"
-
%x <- 1
do
%x <- 2
assume (%x = 2) or barf "'do' is redefining locals"
-%x <- 1
-try
- %x <- 2
- do
- barf
- ..then always
- %x <- 3
-..and if it barfs: do nothing
-lua> "collectgarbage()"
-assume (%x = 3) or barf "do/then always failed"
-
-say "Control flow test passed."
-
assume
(..)
result of
@@ -192,4 +171,6 @@ assume
for % in [1,2,3]: %n +<- %
return %n
..= 6
+..or barf "'result of %' failed"
+say "Control flow test passed."
diff --git a/tests/coroutines.nom b/tests/coroutines.nom
new file mode 100644
index 0000000..8d58170
--- /dev/null
+++ b/tests/coroutines.nom
@@ -0,0 +1,18 @@
+#
+ Tests for the stuff defined in core/control_flow.nom
+
+use "core"
+
+%nums <- []
+%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."
diff --git a/tests/errors.nom b/tests/errors.nom
new file mode 100644
index 0000000..1788a34
--- /dev/null
+++ b/tests/errors.nom
@@ -0,0 +1,22 @@
+#
+ Tests for the stuff defined in core/errors.nom
+
+try: barf
+..and if it succeeds: barf "try failed."
+
+%worked <- (no)
+try: barf
+..and if it barfs: %worked <- (yes)
+assume %worked or barf "try/catch failed"
+
+%x <- 1
+try
+ %x <- 2
+ do
+ barf
+ ..then always
+ %x <- 3
+..and if it barfs: do nothing
+assume (%x = 3) or barf "do/then always failed"
+
+say "Error handling test passed."
diff --git a/tests/os.nom b/tests/os.nom
new file mode 100644
index 0000000..f96009f
--- /dev/null
+++ b/tests/os.nom
@@ -0,0 +1,10 @@
+#
+ 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.2 = " Tests for the stuff defined in lib/os.nom"
+
+say "OS test passed."
diff --git a/tests/text.nom b/tests/text.nom
index 134fff2..a74ac5b 100644
--- a/tests/text.nom
+++ b/tests/text.nom
@@ -10,8 +10,7 @@ assume (("asdf" with "X" instead of "s") = "aXdf") or barf "substitution failed"
assume ("\n" = (newline)) or barf "Text literals failed."
%x <- "\(green)hello\(reset color)"
assume (("x" + "y") = "xy")
-
-say "Text test passed."
+assume ((lines in "one\ntwo") = ["one", "two"])
immediately
parse [アクション %spec %body] as: action %spec %body
@@ -52,3 +51,5 @@ assume
block comment
..gap
..= "nogap"
+
+say "Text test passed."