aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-22 16:30:49 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-22 16:30:49 -0700
commit4c1f0aca7af9eaedd66ce1244557358d9d36411c (patch)
tree42b4c2d43ae458bad7564704b648089b307c2448 /core
parent04d7edefa372f80160603ddd9039a7120527e4bc (diff)
Moving all the rest of the tests over to inline versions.
Diffstat (limited to 'core')
-rw-r--r--core/text.nom44
1 files changed, 44 insertions, 0 deletions
diff --git a/core/text.nom b/core/text.nom
index 83c25f7..9b6fe06 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -5,7 +5,34 @@
use "core/metaprogramming.nom"
+test:
+ assume (("x" + "y") == "xy")
+ %s = "list:\[1, 2, 3]"
+ assume (%s == "list:[1, 2, 3]")
+ assume ("foo = \(1 + 2)!" == "foo = 3!")
+ assume (..)
+ ".."
+ one
+ two
+ ..== "one\ntwo"
+ assume (..)
+ ".."
+ no\
+ ..gap
+ ..== "nogap"
+ parse [アクション %spec %body] as (action %spec %body)
+
+test:
+ %こんにちは = "こんにちは"
+ アクション [% と言う] "\(%)世界"
+ assume ((%こんにちは と言う) == "こんにちは世界") or barf ".."
+ Unicode doesn't work
+
# Text functions
+test:
+ assume ((["x", "y"] joined with ",") == "x,y") or barf "joined with failed"
+ assume ((["x", "y"] joined) == "xy") or barf "joined failed"
+
action [%texts joined with %glue] (..)
lua> ".."
local text_bits = {}
@@ -13,9 +40,15 @@ action [%texts joined with %glue] (..)
return table.concat(text_bits, \%glue)
parse [joined %texts, %texts joined] as (%texts joined with "")
+test:
+ assume (("asdf" capitalized) == "Asdf") or barf "capitalized failed"
+
compile [capitalized %text, %text capitalized] to (..)
Lua value "((\(%text as lua expr)):gsub('%l', string.upper, 1))"
+test:
+ assume (("asdf" with "X" instead of "s") == "aXdf") or barf ".."
+ substitution failed
compile [..]
%text with %sub instead of %patt, %text with %patt replaced by %sub
%text s/ %patt / %sub
@@ -23,6 +56,14 @@ compile [..]
Lua value ".."
((\(%text as lua expr)):gsub(\(%patt as lua expr), \(%sub as lua expr)))
+test:
+ assume (..)
+ (..)
+ lines in ".."
+ one
+ two
+ ..== ["one", "two"]
+
action [lines in %text, lines of %text] (..)
lua> ".."
local result = list{}
@@ -56,6 +97,9 @@ compile [%text matches %pattern] to (..)
compile [%text matching %pattern] to (..)
Lua value "\(%text as lua expr):match(\(%pattern as lua expr))"
+test:
+ assume ("\n" == (newline)) or barf "Text literals failed."
+
# Text literals
lua> ".."
do