aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-10 16:03:41 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-10 16:03:41 -0400
commitb37bd70b602b7ac6427dcf29f7cd9241b0a7ae09 (patch)
treeafa3ba4caebb728c43b96e176b8a569b3ad5f469 /test
parent671f81137ee2e5de632526109e02c4b79197e432 (diff)
For tables, deprecate support for square bracket indexing and .default
values, replacing them with a `:bump()` function for tables with numeric values. This means that counters can be implemented easily without the need to mask complexity.
Diffstat (limited to 'test')
-rw-r--r--test/enums.tm10
-rw-r--r--test/structs.tm22
-rw-r--r--test/tables.tm32
3 files changed, 28 insertions, 36 deletions
diff --git a/test/enums.tm b/test/enums.tm
index 553fcf84..65ef6398 100644
--- a/test/enums.tm
+++ b/test/enums.tm
@@ -36,11 +36,11 @@ func main():
= yes
>> x := Foo.One(123)
- >> t := {x:"found"; default="missing"}
- >> t[x]
- = "found"
- >> t[Foo.Zero]
- = "missing"
+ >> t := {x}
+ >> t:has(x)
+ = yes
+ >> t:has(Foo.Zero)
+ = no
>> choose_text(Foo.Zero)
= "Zero"
diff --git a/test/structs.tm b/test/structs.tm
index 4fdec6ae..c9022ede 100644
--- a/test/structs.tm
+++ b/test/structs.tm
@@ -29,11 +29,11 @@ func test_metamethods():
>> x < Pair(11, 20)
= yes
- >> t2 := {x:"found"; default="missing"}
- >> t2[x]
- = "found"
- >> t2[y]
- = "missing"
+ >> set := {x}
+ >> set:has(x)
+ = yes
+ >> set:has(y)
+ = no
func test_mixed():
>> x := Mixed(10, "Hello")
@@ -46,11 +46,11 @@ func test_mixed():
= no
>> x < Mixed(11, "Hello")
= yes
- >> t := {x:"found"; default="missing"}
- >> t[x]
- = "found"
- >> t[y]
- = "missing"
+ >> set := {x}
+ >> set:has(x)
+ = yes
+ >> set:has(y)
+ = no
func main():
test_literals()
@@ -63,7 +63,7 @@ func main():
= Password(...)
>> users_by_password := {my_pass:"User1", Password("xxx"):"User2"}
= {Password(...):"User1", Password(...):"User2"}
- >> users_by_password[my_pass]
+ >> users_by_password:get(my_pass)
= "User1"
>> CorecursiveA(@CorecursiveB())
diff --git a/test/tables.tm b/test/tables.tm
index 6dbc1b78..d02a5272 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -1,12 +1,12 @@
func main():
- >> t := {"one":1, "two":2; default=999}
- = {"one":1, "two":2; default=999}
+ >> t := {"one":1, "two":2}
+ = {"one":1, "two":2}
- >> t["one"]
+ >> t:get("one", 999)
= 1
- >> t["two"]
+ >> t:get("two", 999)
= 2
- >> t["???"]
+ >> t:get("???", 999)
= 999
t_str := ""
@@ -17,8 +17,6 @@ func main():
>> #t
= 2
- >> t.default
- = @%999?
>> t.fallback
= !{Text:Int}
@@ -28,21 +26,19 @@ func main():
= [1, 2]
>> t2 := {"three":3; fallback=t}
- = {"three":3; fallback={"one":1, "two":2; default=999}}
+ = {"three":3; fallback={"one":1, "two":2}}
- >> t2["one"]
+ >> t2:get("one", 999)
= 1
- >> t2["three"]
+ >> t2:get("three", 999)
= 3
- >> t2["???"]
+ >> t2:get("???", 999)
= 999
>> #t2
= 1
- >> t2.default
- = !Int
>> t2.fallback
- = @%{"one":1, "two":2; default=999}?
+ = @%{"one":1, "two":2}?
t2_str := ""
for k,v in t2:
@@ -64,6 +60,8 @@ func main():
do:
>> plain := {1:10, 2:20, 3:30}
+ >> plain:get(2)
+ = 20
>> plain:get(2, -999)
= 20
>> plain:get(456, -999)
@@ -79,9 +77,3 @@ func main():
>> fallback:get(1, -999)
= 10
- >> default := {5:50; default=0}
- >> default:has(28273)
- = yes
- >> default:get(28273, -999)
- = 0
-