aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-02 16:14:20 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-02 16:14:20 -0400
commit6ec8f20fc506af4af5513803fb9a708e4f7b5040 (patch)
tree8b952073f6eda5b85c375a65c73647a85fa16f27 /test
parentecaf34247eb0728a913804033cf302dada417028 (diff)
Syntax change: table types are now: `{K=V; default=...}` and tables
use `{:K=V, ...; default=...}`
Diffstat (limited to 'test')
-rw-r--r--test/for.tm6
-rw-r--r--test/serialization.tm2
-rw-r--r--test/tables.tm21
3 files changed, 22 insertions, 7 deletions
diff --git a/test/for.tm b/test/for.tm
index e3774815..a67e9d5d 100644
--- a/test/for.tm
+++ b/test/for.tm
@@ -15,14 +15,14 @@ func labeled_nums(nums:[Int] -> Text):
return "EMPTY"
return result
-func table_str(t:{Text,Text} -> Text):
+func table_str(t:{Text=Text} -> Text):
str := ""
for k,v in t:
str ++= "$k:$v,"
else: return "EMPTY"
return str
-func table_key_str(t:{Text,Text} -> Text):
+func table_key_str(t:{Text=Text} -> Text):
str := ""
for k in t:
str ++= "$k,"
@@ -43,7 +43,7 @@ func main():
>> t := {"key1"="value1", "key2"="value2"}
>> table_str(t)
= "key1:value1,key2:value2,"
- >> table_str({:Text,Text})
+ >> table_str({:Text=Text})
= "EMPTY"
>> table_key_str(t)
diff --git a/test/serialization.tm b/test/serialization.tm
index 6d08552f..2027cb90 100644
--- a/test/serialization.tm
+++ b/test/serialization.tm
@@ -53,7 +53,7 @@ func main():
do:
>> obj := {"A"=10, "B"=20; fallback={"C"=30}}
>> bytes := obj:serialized()
- >> deserialize(bytes -> {Text,Int}) == obj
+ >> deserialize(bytes -> {Text=Int}) == obj
= yes
do:
diff --git a/test/tables.tm b/test/tables.tm
index 9749835d..140fd1cf 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -22,7 +22,7 @@ func main():
>> t.length
= 2
>> t.fallback
- = none : {Text,Int}
+ = none : {Text=Int}
>> t.keys
= ["one", "two"]
@@ -96,10 +96,25 @@ func main():
>> {1=1, 2=2} <> {2=2, 1=1}
= Int32(0)
- >> [{:Int,Int}, {0=0}, {99=99}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 2=-99, 3=3}, {1=1, 99=-99, 3=4}]:sorted()
- = [{:Int,Int}, {0=0}, {1=1, 2=-99, 3=3}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 99=-99, 3=4}, {99=99}]
+ >> [{:Int=Int}, {0=0}, {99=99}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 2=-99, 3=3}, {1=1, 99=-99, 3=4}]:sorted()
+ = [{:Int=Int}, {0=0}, {1=1, 2=-99, 3=3}, {1=1, 2=2, 3=3}, {1=1, 99=99, 3=3}, {1=1, 99=-99, 3=4}, {99=99}]
>> [{:Int}, {1}, {2}, {99}, {0, 3}, {1, 2}, {99}]:sorted()
= [{:Int}, {0, 3}, {1}, {1, 2}, {2}, {99}, {99}]
+ do:
+ # Default values:
+ counter := &{"x"=10; default=0}
+ >> counter["x"]
+ = 10
+ >> counter["y"]
+ = 0
+ >> counter:has("x")
+ = yes
+ >> counter:has("y")
+ = no
+ >> counter["y"] += 1
+ >> counter
+ >> counter
+ = &{"x"=10, "y"=1; default=0}