aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-21 16:28:57 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-21 16:28:57 -0400
commitfd74479a2bf2e4ccc35d1c2fa206de8f28be1e54 (patch)
tree0cdf5c4659264b612b5f3fbb4ce6a3b11dd736f5 /test
parent92185a002a2e8b669add454a945c0ecdc0904993 (diff)
Deprecate optional '?' postfix operator
Diffstat (limited to 'test')
-rw-r--r--test/iterators.tm8
-rw-r--r--test/lists.tm8
-rw-r--r--test/nums.tm4
-rw-r--r--test/optionals.tm50
-rw-r--r--test/paths.tm2
-rw-r--r--test/reductions.tm6
-rw-r--r--test/serialization.tm2
-rw-r--r--test/tables.tm10
-rw-r--r--test/when.tm2
9 files changed, 47 insertions, 45 deletions
diff --git a/test/iterators.tm b/test/iterators.tm
index c48e572b..ed08f73d 100644
--- a/test/iterators.tm
+++ b/test/iterators.tm
@@ -3,17 +3,17 @@ struct Pair(x:Text, y:Text)
func pairwise(strs:[Text] -> func(->Pair?))
i := 1
- return func()
+ return func(-> Pair?)
i += 1
- return Pair(strs[i-1] or return none, strs[i] or return none)?
+ return Pair(strs[i-1] or return none, strs[i] or return none)
func range(first:Int, last:Int -> func(->Int?))
i := first
- return func()
+ return func(->Int?)
if i > last
return none
i += 1
- return (i-1)?
+ return (i-1)
func main()
values := ["A", "B", "C", "D"]
diff --git a/test/lists.tm b/test/lists.tm
index 05001f19..2342c570 100644
--- a/test/lists.tm
+++ b/test/lists.tm
@@ -162,23 +162,23 @@ func main()
= [1, 2, 3, 4, 5]
>> ["a", "b", "c"].find("b")
- = 2?
+ = 2
>> ["a", "b", "c"].find("XXX")
= none
>> [10, 20].where(func(i:&Int) i.is_prime())
= none
>> [4, 5, 6].where(func(i:&Int) i.is_prime())
- = 2?
+ = 2
do
>> nums := &[10, 20, 30, 40, 50]
>> nums.pop()
- = 50?
+ = 50
>> nums[]
= [10, 20, 30, 40]
>> nums.pop(2)
- = 20?
+ = 20
>> nums[]
= [10, 30, 40]
>> nums.clear()
diff --git a/test/nums.tm b/test/nums.tm
index 362f590f..1ca09d7b 100644
--- a/test/nums.tm
+++ b/test/nums.tm
@@ -51,7 +51,9 @@ func main()
= no
>> Num32.sqrt(16)
- = Num32(4)?
+ = Num32(4)
+ >> Num32.sqrt(-1)
+ = none
>> (0.25).mix(10, 20)
= 12.5
diff --git a/test/optionals.tm b/test/optionals.tm
index 1f7d640e..dcec904d 100644
--- a/test/optionals.tm
+++ b/test/optionals.tm
@@ -57,28 +57,28 @@ func maybe_lambda(should_i:Bool-> func()?)
func maybe_c_string(should_i:Bool->CString?)
if should_i
- return ("hi".as_c_string())?
+ return "hi".as_c_string()
else
return none
func main()
- >> 5?
- = 5?
+ >> optional : Int? = 5
+ = 5
>> if no
x : Int? = none
x
else
5
- = 5?
+ = 5
- >> 5? or -1
+ >> optional or -1
= 5
- >> 5? or fail("Non-none is falsey")
+ >> optional or fail("Non-none is falsey")
= 5
- >> 5? or exit("Non-none is falsey")
+ >> optional or exit("Non-none is falsey")
= 5
>> none_int : Int? = none
@@ -88,7 +88,7 @@ func main()
do
say("Ints:")
>> yep := maybe_int(yes)
- = 123?
+ = 123
>> nope := maybe_int(no)
= none
>> if yep
@@ -102,7 +102,7 @@ func main()
do
say("Int64s:")
>> yep := maybe_int64(yes)
- = Int64(123)?
+ = Int64(123)
>> nope := maybe_int64(no)
= none
>> if yep
@@ -116,7 +116,7 @@ func main()
do
say("Lists:")
>> yep := maybe_list(yes)
- = [10, 20, 30]?
+ = [10, 20, 30]
>> nope := maybe_list(no)
= none
>> if yep
@@ -131,7 +131,7 @@ func main()
say("...")
say("Bools:")
>> yep := maybe_bool(yes)
- = no?
+ = no
>> nope := maybe_bool(no)
= none
>> if yep
@@ -146,7 +146,7 @@ func main()
say("...")
say("Text:")
>> yep := maybe_text(yes)
- = "Hello"?
+ = "Hello"
>> nope := maybe_text(no)
= none
>> if yep
@@ -161,7 +161,7 @@ func main()
say("...")
say("Nums:")
>> yep := maybe_num(yes)
- = 12.3?
+ = 12.3
>> nope := maybe_num(no)
= none
>> if yep
@@ -191,7 +191,7 @@ func main()
say("...")
say("Structs:")
>> yep := Struct.maybe(yes)
- = Struct(x=123, y="hello")?
+ = Struct(x=123, y="hello")
>> nope := Struct.maybe(no)
= none
>> if yep
@@ -206,7 +206,7 @@ func main()
say("...")
say("Enums:")
>> yep := Enum.maybe(yes)
- = Enum.Y(123)?
+ = Enum.Y(123)
>> nope := Enum.maybe(no)
= none
>> if yep
@@ -221,7 +221,7 @@ func main()
say("...")
say("C Strings:")
>> yep := maybe_c_string(yes)
- = CString("hi")?
+ = CString("hi")
>> nope := maybe_c_string(no)
= none
>> if yep
@@ -241,16 +241,16 @@ func main()
= 123
# Test comparisons, hashing, equality:
- assert none != 5?
- assert 5? == 5?
+ assert none != optional
+ assert optional == 5
>> nones : {Int?=Bool} = {none=yes, none=yes}
>> nones.keys
= [none]
- >> [5?, none, none, 6?].sorted()
+ >> [5, none, none, 6].sorted()
= [none, none, 5, 6]
do
- >> value := if var := 5?
+ >> value := if var := optional
var
else
0
@@ -264,7 +264,7 @@ func main()
= 0
do
- >> opt := 5?
+ >> opt : Int? = 5
>> if opt
>> opt
else
@@ -277,17 +277,17 @@ func main()
else
>> opt
- >> not 5?
+ >> not optional
= no
>> nah : Int? = none
>> not nah
= yes
- >> [Struct(5,"A")?, Struct(6,"B"), Struct(7,"C")]
- = [Struct(x=5, y="A")?, Struct(x=6, y="B")?, Struct(x=7, y="C")?]
+ >> [none, Struct(5,"A"), Struct(6,"B"), Struct(7,"C")]
+ = [none, Struct(x=5, y="A"), Struct(x=6, y="B"), Struct(x=7, y="C")]
- if 5? or no
+ if optional or no
say("Binary op 'or' works with optionals")
else
fail("Failed to do binary op 'or' on optional")
diff --git a/test/paths.tm b/test/paths.tm
index d92d4623..22f79c7b 100644
--- a/test/paths.tm
+++ b/test/paths.tm
@@ -20,7 +20,7 @@ func main()
>> tmpfile.write("Hello world")
>> tmpfile.append("!")
>> tmpfile.read()
- = "Hello world!"?
+ = "Hello world!"
>> tmpfile.read_bytes()!
= [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21]
assert tmpdir.files().has(tmpfile)
diff --git a/test/reductions.tm b/test/reductions.tm
index 3ec2ef5e..15c3d454 100644
--- a/test/reductions.tm
+++ b/test/reductions.tm
@@ -2,7 +2,7 @@ struct Foo(x,y:Int)
func main()
>> (+: [10, 20, 30])
- = 60?
+ = 60
>> empty_ints : [Int]
>> (+: empty_ints)
@@ -15,10 +15,10 @@ func main()
= 0
>> (_max_: [3, 5, 2, 1, 4])
- = 5?
+ = 5
>> (_max_.abs(): [1, -10, 5])
- = -10?
+ = -10
>> (_max_: [Foo(0, 0), Foo(1, 0), Foo(0, 10)])!
= Foo(x=1, y=0)
diff --git a/test/serialization.tm b/test/serialization.tm
index e2fa38a3..0e5be1ae 100644
--- a/test/serialization.tm
+++ b/test/serialization.tm
@@ -62,7 +62,7 @@ func main()
assert deserialize(bytes -> MyEnum) == obj
do
- >> obj := "Hello"?
+ >> obj : Text? = "Hello"
>> bytes := obj.serialized()
assert deserialize(bytes -> Text?) == obj
diff --git a/test/tables.tm b/test/tables.tm
index 587a02c8..66318f11 100644
--- a/test/tables.tm
+++ b/test/tables.tm
@@ -3,9 +3,9 @@ func main()
= {"one"=1, "two"=2}
>> t["one"]
- = 1?
+ = 1
>> t["two"]
- = 2?
+ = 2
>> t["???"]
= none
>> t["one"]!
@@ -33,16 +33,16 @@ func main()
= {"three"=3; fallback={"one"=1, "two"=2}}
>> t2["one"]
- = 1?
+ = 1
>> t2["three"]
- = 3?
+ = 3
>> t2["???"]
= none
>> t2.length
= 1
>> t2.fallback
- = {"one"=1, "two"=2}?
+ = {"one"=1, "two"=2}
t2_str := ""
for k,v in t2
diff --git a/test/when.tm b/test/when.tm
index d18f5276..57de4c2c 100644
--- a/test/when.tm
+++ b/test/when.tm
@@ -15,4 +15,4 @@ func main()
>> when n is 1 Int64(1)
is 2 Int64(2)
is 21 + 2 Int64(23)
- = Int64(23)?
+ = Int64(23)