diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 15:50:54 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-30 15:50:54 -0500 |
| commit | 40c33987fa0a91a8525d960f8494ca9ddf12806d (patch) | |
| tree | fa89233cbd7096de735348b39704e1ddb97dfe0c /test | |
| parent | f3fc7558bb425c4bd59b55527d2fafaa744fe0aa (diff) | |
Bring back `table[key]` syntax
Diffstat (limited to 'test')
| -rw-r--r-- | test/structs.tm | 2 | ||||
| -rw-r--r-- | test/tables.tm | 31 |
2 files changed, 20 insertions, 13 deletions
diff --git a/test/structs.tm b/test/structs.tm index ae5bec0f..afbb1a86 100644 --- a/test/structs.tm +++ b/test/structs.tm @@ -74,7 +74,7 @@ func main(): = Password(...) >> users_by_password := {my_pass:"User1", Password("xxx"):"User2"} = {Password(...):"User1", Password(...):"User2"} - >> users_by_password:get(my_pass)! + >> users_by_password[my_pass]! = "User1" >> CorecursiveA(@CorecursiveB()) diff --git a/test/tables.tm b/test/tables.tm index acda0eb5..0d8954a2 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -2,15 +2,15 @@ func main(): >> t := {"one":1, "two":2} = {"one":1, "two":2} - >> t:get("one") + >> t["one"] = 1 : Int? - >> t:get("two") + >> t["two"] = 2 : Int? - >> t:get("???") + >> t["???"] = NONE : Int? - >> t:get("one")! + >> t["one"]! = 1 - >> t:get("???") or -1 + >> t["???"] or -1 = -1 t_str := "" @@ -32,11 +32,11 @@ func main(): >> t2 := {"three":3; fallback=t} = {"three":3; fallback={"one":1, "two":2}} - >> t2:get("one") + >> t2["one"] = 1 : Int? - >> t2:get("three") + >> t2["three"] = 3 : Int? - >> t2:get("???") + >> t2["???"] = NONE : Int? >> t2.length @@ -64,11 +64,11 @@ func main(): do: >> plain := {1:10, 2:20, 3:30} - >> plain:get(2)! + >> plain[2]! = 20 - >> plain:get(2)! + >> plain[2]! = 20 - >> plain:get(456) or -999 + >> plain[456] or -999 = -999 >> plain:has(2) = yes @@ -78,6 +78,13 @@ func main(): >> fallback := {4:40; fallback=plain} >> fallback:has(1) = yes - >> fallback:get(1) or -999 + >> fallback[1] or -999 = 10 + do: + >> t4 := {"one": 1} + >> t4["one"] = 999 + >> t4["two"] = 222 + >> t4 + = {"one":999, "two":222} + |
