aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-12 00:55:43 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-12 00:55:43 -0400
commit327d466b9543aee3983277ca4158e5b7aa06fdf8 (patch)
tree64028cc0ca38b76461a85be02e3103db600f0bcc /test
parentfa7e52787f81f3673f9d57e9e4ba7fc015ca8432 (diff)
Table:get() now uses optional values instead of default or failure modes
Diffstat (limited to 'test')
-rw-r--r--test/structs.tm2
-rw-r--r--test/tables.tm34
2 files changed, 20 insertions, 16 deletions
diff --git a/test/structs.tm b/test/structs.tm
index c9022ede..53d356f5 100644
--- a/test/structs.tm
+++ b/test/structs.tm
@@ -63,7 +63,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:get(my_pass)!
= "User1"
>> CorecursiveA(@CorecursiveB())
diff --git a/test/tables.tm b/test/tables.tm
index e59283ed..50eb5ef5 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -2,12 +2,16 @@ func main():
>> t := {"one":1, "two":2}
= {"one":1, "two":2}
- >> t:get("one", 999)
+ >> t:get("one")
+ = 1?
+ >> t:get("two")
+ = 2?
+ >> t:get("???")
+ = !Int
+ >> t:get("one")!
= 1
- >> t:get("two", 999)
- = 2
- >> t:get("???", 999)
- = 999
+ >> t:get("???"):or_else(-1)
+ = -1
t_str := ""
for k,v in t:
@@ -28,12 +32,12 @@ func main():
>> t2 := {"three":3; fallback=t}
= {"three":3; fallback={"one":1, "two":2}}
- >> t2:get("one", 999)
- = 1
- >> t2:get("three", 999)
- = 3
- >> t2:get("???", 999)
- = 999
+ >> t2:get("one")
+ = 1?
+ >> t2:get("three")
+ = 3?
+ >> t2:get("???")
+ = !Int
>> t2.length
= 1
@@ -60,11 +64,11 @@ func main():
do:
>> plain := {1:10, 2:20, 3:30}
- >> plain:get(2)
+ >> plain:get(2)!
= 20
- >> plain:get(2, -999)
+ >> plain:get(2)!
= 20
- >> plain:get(456, -999)
+ >> plain:get(456):or_else(-999)
= -999
>> plain:has(2)
= yes
@@ -74,6 +78,6 @@ func main():
>> fallback := {4:40; fallback=plain}
>> fallback:has(1)
= yes
- >> fallback:get(1, -999)
+ >> fallback:get(1):or_else(-999)
= 10