aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-09 19:03:35 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-03-09 19:03:35 -0500
commit170c0a419794d184a941654b3b06ca12bbb9e194 (patch)
treefdbb91db6d628de9a7510b61ac22c61df7b72f75
parentcbdd357b41b4685c669755bfdd29c822d5dcc8c6 (diff)
Add lang tests
-rw-r--r--test/lang.tm33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/lang.tm b/test/lang.tm
new file mode 100644
index 00000000..509a4ec6
--- /dev/null
+++ b/test/lang.tm
@@ -0,0 +1,33 @@
+lang HTML
+ HEADER := $HTML{}"<!DOCTYPE HTML>"
+ func escape(t:Text)->HTML
+ t = t:replace("&", "&amp;")
+ t = t:replace("<", "&lt;")
+ t = t:replace(">", "&gt;")
+ t = t:replace('"', "&quot;")
+ t = t:replace("'", "&#39;")
+ return HTML.from_unsafe_text(t)
+
+ func escape_int(i:Int)->HTML
+ return HTML.from_unsafe_text("{i}")
+
+ func paragraph(content:HTML)->HTML
+ return $HTML{}"<p>{content}</p>"
+
+>> HTML.HEADER
+= $HTML"<!DOCTYPE HTML>"
+
+>> user := "I <3 hax"
+>> html := $HTML{}"Hello {user}!"
+= $HTML"Hello I &lt;3 hax!"
+>> html ++ $HTML{}"<br>"
+= $HTML"Hello I &lt;3 hax!<br>"
+
+>> $HTML{}"{1 + 2}"
+= $HTML"3"
+
+>> $HTML{}"{3_i8}"
+= $HTML"3"
+
+>> html:paragraph()
+= $HTML"<p>Hello I &lt;3 hax!</p>"