aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-18 14:44:15 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-18 14:44:15 -0400
commitf4b04a1b8cd882e25fee592c819650c9b7e8566b (patch)
treedcecb8b4f83d569ebb00beb79988222d195b8f4c /test
parent04603308af3a2984d42eaa9e301cac0ffbded2a4 (diff)
Improved syntax for dollar-string literals
Diffstat (limited to 'test')
-rw-r--r--test/arrays.tm4
-rw-r--r--test/corecursive_func.tm8
-rw-r--r--test/defer.tm4
-rw-r--r--test/enums.tm8
-rw-r--r--test/for.tm8
-rw-r--r--test/integers.tm4
-rw-r--r--test/iterators.tm6
-rw-r--r--test/lambdas.tm4
-rw-r--r--test/lang.tm14
-rw-r--r--test/tables.tm4
-rw-r--r--test/text.tm22
11 files changed, 51 insertions, 35 deletions
diff --git a/test/arrays.tm b/test/arrays.tm
index c870ce04..76507c5b 100644
--- a/test/arrays.tm
+++ b/test/arrays.tm
@@ -23,7 +23,7 @@ func main():
str := ""
for i,x in arr:
- str ++= "({i},{x})"
+ str ++= "($i,$x)"
>> str
= "(1,10)(2,20)(3,30)"
@@ -148,7 +148,7 @@ func main():
xs := ["A", "B", "C", "D"]
for i,x in xs:to(-2):
for y in xs:from(i+1):
- say("{x}{y}")
+ say("$(x)$(y)")
do:
>> nums := [-7, -4, -1, 2, 5]
diff --git a/test/corecursive_func.tm b/test/corecursive_func.tm
index a5c13dde..168300d4 100644
--- a/test/corecursive_func.tm
+++ b/test/corecursive_func.tm
@@ -1,14 +1,14 @@
func ping(x:Int)->[Text]:
if x > 0:
- return ["ping: {x}"] ++ pong(x-1)
+ return ["ping: $x"] ++ pong(x-1)
else:
- return ["ping: {x}"]
+ return ["ping: $x"]
func pong(x:Int)->[Text]:
if x > 0:
- return ["pong: {x}"] ++ ping(x-1)
+ return ["pong: $x"] ++ ping(x-1)
else:
- return ["pong: {x}"]
+ return ["pong: $x"]
func main():
>> ping(3)
diff --git a/test/defer.tm b/test/defer.tm
index 121878b1..deccaa70 100644
--- a/test/defer.tm
+++ b/test/defer.tm
@@ -16,7 +16,7 @@ func main():
for word in ["first", "second", "third"]:
defer:
- say("Got {word} deferred")
+ say("Got $word deferred")
if word == "second":
say("<skipped>")
@@ -27,7 +27,7 @@ func main():
for i in 3:
defer:
- say("Inner loop deferred {i}")
+ say("Inner loop deferred $i")
if i == 2:
say("<skipped inner>")
diff --git a/test/enums.tm b/test/enums.tm
index 65ef6398..b734d487 100644
--- a/test/enums.tm
+++ b/test/enums.tm
@@ -5,15 +5,15 @@ func choose_text(f:Foo)->Text:
when f is Zero:
return "Zero"
is One(one):
- return "One: {one}"
+ return "One: $one"
is Two(x, y):
- return "Two: x={x}, y={y}"
+ return "Two: x=$x, y=$y"
is Three(three):
- return "Three: {three}"
+ return "Three: $three"
is Four:
return "Four"
else:
- return "else: {f}"
+ return "else: $f"
func main():
>> Foo.Zero
diff --git a/test/for.tm b/test/for.tm
index a050c892..6ac77be6 100644
--- a/test/for.tm
+++ b/test/for.tm
@@ -2,7 +2,7 @@
func all_nums(nums:[Int])->Text:
result := ""
for num in nums:
- result ++= "{num},"
+ result ++= "$num,"
else:
return "EMPTY"
return result
@@ -10,7 +10,7 @@ func all_nums(nums:[Int])->Text:
func labeled_nums(nums:[Int])->Text:
result := ""
for i,num in nums:
- result ++= "{i}:{num},"
+ result ++= "$i:$num,"
else:
return "EMPTY"
return result
@@ -18,14 +18,14 @@ func labeled_nums(nums:[Int])->Text:
func table_str(t:{Text:Text})->Text:
str := ""
for k,v in t:
- str ++= "{k}:{v},"
+ str ++= "$k:$v,"
else: return "EMPTY"
return str
func table_key_str(t:{Text:Text})->Text:
str := ""
for k in t:
- str ++= "{k},"
+ str ++= "$k,"
else: return "EMPTY"
return str
diff --git a/test/integers.tm b/test/integers.tm
index 36119f01..11603b22 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -28,7 +28,7 @@ func main():
nums := ""
for x in 5:
- nums ++= "{x},"
+ nums ++= "$x,"
>> nums
= "1,2,3,4,5,"
@@ -79,6 +79,6 @@ func main():
for in 20:
>> n := Int.random(-999999, 999999)
>> d := Int.random(-999, 999)
- //! n={n}, d={d}:
+ //! n=$n, d=$d:
>> (n/d)*d + (n mod d) == n
= yes
diff --git a/test/iterators.tm b/test/iterators.tm
index 999194d9..1f7ce342 100644
--- a/test/iterators.tm
+++ b/test/iterators.tm
@@ -19,15 +19,15 @@ func range(first:Int, last:Int)->func()->RangeIteration:
func main():
values := ["A", "B", "C", "D"]
- >> ((++) "({foo}{baz})" for foo, baz in pairwise(values))
+ >> ((++) "($(foo)$(baz))" for foo, baz in pairwise(values))
= "(AB)(BC)(CD)"
- >> ["{foo}{baz}" for foo, baz in pairwise(values)]
+ >> ["$(foo)$(baz)" for foo, baz in pairwise(values)]
= ["AB", "BC", "CD"]
do:
result := [:Text]
for foo, baz in pairwise(values):
- result:insert("{foo}{baz}")
+ result:insert("$(foo)$(baz)")
>> result
= ["AB", "BC", "CD"]
diff --git a/test/lambdas.tm b/test/lambdas.tm
index 40f24abb..8d543bfc 100644
--- a/test/lambdas.tm
+++ b/test/lambdas.tm
@@ -12,7 +12,7 @@ func main():
>> add_one(10)
= 11
- >> shout := func(msg:Text): say("{msg:upper()}!")
+ >> shout := func(msg:Text): say("$(msg:upper())!")
>> shout("hello")
>> asdf := add_one
@@ -36,7 +36,7 @@ func main():
fn := func():
return func():
return func():
- defer: //! {outer}
+ defer: //! $outer
return outer
>> fn()()()
= "Hello"
diff --git a/test/lang.tm b/test/lang.tm
index 01551e27..dfe1c663 100644
--- a/test/lang.tm
+++ b/test/lang.tm
@@ -1,5 +1,5 @@
lang HTML:
- HEADER := $HTML$"<!DOCTYPE HTML>"
+ HEADER := $HTML"<!DOCTYPE HTML>"
func escape(t:Text)->HTML:
t = t:replace("&", "&amp;")
t = t:replace("<", "&lt;")
@@ -9,25 +9,25 @@ lang HTML:
return HTML.from_unsafe_text(t)
func escape_int(i:Int)->HTML:
- return HTML.from_unsafe_text("{i}")
+ return HTML.from_unsafe_text("$i")
func paragraph(content:HTML)->HTML:
- return $HTML$"<p>$content</p>"
+ return $HTML"<p>$content</p>"
func main():
>> HTML.HEADER
= $HTML"<!DOCTYPE HTML>"
>> user := "I <3 hax"
- >> html := $HTML$"Hello $user!"
+ >> html := $HTML"Hello $user!"
= $HTML"Hello I &lt;3 hax!"
- >> html ++ $HTML$"<br>"
+ >> html ++ $HTML"<br>"
= $HTML"Hello I &lt;3 hax!<br>"
- >> $HTML{}"{1 + 2}"
+ >> $HTML"$(1 + 2)"
= $HTML"3"
- >> $HTML{}"{3_i8}"
+ >> $HTML"$(3_i8)"
= $HTML"3"
>> html:paragraph()
diff --git a/test/tables.tm b/test/tables.tm
index d02a5272..7f8383d8 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -11,7 +11,7 @@ func main():
t_str := ""
for k,v in t:
- t_str ++= "({k}:{v})"
+ t_str ++= "($k:$v)"
>> t_str
= "(one:1)(two:2)"
@@ -42,7 +42,7 @@ func main():
t2_str := ""
for k,v in t2:
- t2_str ++= "({k}:{v})"
+ t2_str ++= "($k:$v)"
>> t2_str
= "(three:3)"
diff --git a/test/text.tm b/test/text.tm
index 4051a16f..2666b6c8 100644
--- a/test/text.tm
+++ b/test/text.tm
@@ -1,6 +1,6 @@
func main():
>> str := "Hello Amélie!"
- //! Testing strings like {str}
+ //! Testing strings like $str
>> str:upper()
= "HELLO AMÉLIE!"
@@ -19,7 +19,7 @@ func main():
>> \UE9 == \U65\U301
= yes
- >> amelie := "Am{\UE9}lie"
+ >> amelie := "Am$(\UE9)lie"
>> amelie:clusters()
= ["A", "m", "é", "l", "i", "e"] : [Text]
>> amelie:codepoints()
@@ -35,7 +35,7 @@ func main():
>> amelie:num_bytes()
= 8
- >> amelie2 := "Am{\U65\U301}lie"
+ >> amelie2 := "Am$(\U65\U301)lie"
>> amelie2:clusters()
= ["A", "m", "é", "l", "i", "e"] : [Text]
>> amelie2:codepoints()
@@ -103,3 +103,19 @@ func main():
"
= "line one\nline two"
+ //! Interpolation tests:
+ >> "A $(1+2)"
+ = "A 3"
+ >> 'A $(1+2)'
+ = "A $(1+2)"
+ >> `A $(1+2)`
+ = "A 3"
+
+ >> $"A $(1+2)"
+ = "A 3"
+ >> $$"A $(1+2)"
+ = "A $(1+2)"
+ >> $="A =(1+2)"
+ = "A 3"
+ >> $(one (nested) two $(1+2))
+ = "one (nested) two 3"