From 6ec8f20fc506af4af5513803fb9a708e4f7b5040 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 2 Apr 2025 16:14:20 -0400 Subject: Syntax change: table types are now: `{K=V; default=...}` and tables use `{:K=V, ...; default=...}` --- test/for.tm | 6 +++--- test/serialization.tm | 2 +- test/tables.tm | 21 ++++++++++++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'test') 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} -- cgit v1.2.3