From 7b735ab6fc3e0bb368f1ca484168eaefbbe3ce9c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 4 Apr 2025 18:29:09 -0400 Subject: Misc fixes --- test/arrays.tm | 10 +++++----- test/iterators.tm | 4 ++-- test/nums.tm | 8 ++++---- test/optionals.tm | 44 +++++++++++++++++++++++--------------------- test/serialization.tm | 4 ++-- test/structs.tm | 4 ++-- test/tables.tm | 4 ++-- test/text.tm | 2 +- 8 files changed, 41 insertions(+), 39 deletions(-) (limited to 'test') diff --git a/test/arrays.tm b/test/arrays.tm index 5816c359..5aaaa155 100644 --- a/test/arrays.tm +++ b/test/arrays.tm @@ -107,7 +107,7 @@ func main(): sorted : @[Int] = @[] repeat: sorted:insert(heap:heap_pop() or stop) - >> sorted == sorted:sorted() + >> sorted[] == sorted:sorted() = yes for i in 10: heap:heap_push((i*13337) mod 37) @@ -115,7 +115,7 @@ func main(): sorted = @[] repeat: sorted:insert(heap:heap_pop() or stop) - >> sorted == sorted:sorted() + >> sorted[] == sorted:sorted() = yes do: @@ -162,10 +162,10 @@ func main(): >> ["a", "b", "c"]:find("b") = 2? >> ["a", "b", "c"]:find("XXX") - = none:Int + = none >> [10, 20]:first(func(i:&Int): i:is_prime()) - = none:Int + = none >> [4, 5, 6]:first(func(i:&Int): i:is_prime()) = 2? @@ -183,4 +183,4 @@ func main(): >> nums = &[] >> nums:pop() - = none:Int + = none diff --git a/test/iterators.tm b/test/iterators.tm index 0b6c2a89..a8316aba 100644 --- a/test/iterators.tm +++ b/test/iterators.tm @@ -4,7 +4,7 @@ struct Pair(x:Text, y:Text) func pairwise(strs:[Text] -> func(->Pair?)): i := 1 return func(): - if i + 1 > strs.length: return none:Pair + if i + 1 > strs.length: return none i += 1 return Pair(strs[i-1], strs[i])? @@ -12,7 +12,7 @@ func range(first:Int, last:Int -> func(->Int?)): i := first return func(): if i > last: - return none:Int + return none i += 1 return (i-1)? diff --git a/test/nums.tm b/test/nums.tm index 1dc83cee..e36ae573 100644 --- a/test/nums.tm +++ b/test/nums.tm @@ -22,8 +22,8 @@ func main(): >> Num.INF:isinf() = yes - >> nan := none : Num - = none:Num + >> nan : Num = none + = none >> nan == nan = yes >> nan < nan @@ -46,10 +46,10 @@ func main(): = Int32(-1) >> nan + 1 - = none:Num + = none >> 0./0. - = none:Num + = none >> Num.PI:cos()!:near(-1) = yes diff --git a/test/optionals.tm b/test/optionals.tm index a1b0dcd6..703e74e9 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -66,7 +66,8 @@ func main(): = 5? >> if no: - none:Int + x : Int? = none + x else: 5 = 5? @@ -80,7 +81,8 @@ func main(): >> 5? or exit("Non-null is falsey") = 5 - >> (none:Int) or -1 + >> none_int : Int? = none + >> none_int or -1 = -1 do: @@ -88,7 +90,7 @@ func main(): >> yep := maybe_int(yes) = 123? >> nope := maybe_int(no) - = none:Int + = none >> if yep: >> yep = 123 @@ -103,7 +105,7 @@ func main(): >> yep := maybe_int64(yes) = Int64(123)? >> nope := maybe_int64(no) - = none:Int64 + = none >> if yep: >> yep = Int64(123) @@ -118,7 +120,7 @@ func main(): >> yep := maybe_array(yes) = [10, 20, 30]? >> nope := maybe_array(no) - = none:[Int] + = none >> if yep: >> yep = [10, 20, 30] @@ -133,7 +135,7 @@ func main(): >> yep := maybe_bool(yes) = no? >> nope := maybe_bool(no) - = none:Bool + = none >> if yep: >> yep = no @@ -148,7 +150,7 @@ func main(): >> yep := maybe_text(yes) = "Hello"? >> nope := maybe_text(no) - = none:Text + = none >> if yep: >> yep = "Hello" @@ -163,7 +165,7 @@ func main(): >> yep := maybe_num(yes) = 12.3? >> nope := maybe_num(no) - = none:Num + = none >> if yep: >> yep = 12.3 @@ -178,7 +180,7 @@ func main(): # >> yep := maybe_lambda(yes) # = func() [optionals.tm:54] : func()? >> nope := maybe_lambda(no) - = none : func() + = none # >> if yep: # >> yep # = func() [optionals.tm:54] @@ -193,7 +195,7 @@ func main(): >> yep := Struct.maybe(yes) = Struct(x=123, y="hello")? >> nope := Struct.maybe(no) - = none:Struct + = none >> if yep: >> yep = Struct(x=123, y="hello") @@ -208,7 +210,7 @@ func main(): >> yep := Enum.maybe(yes) = Enum.Y(123)? >> nope := Enum.maybe(no) - = none : Enum + = none >> if yep: >> yep = Enum.Y(123) @@ -223,7 +225,7 @@ func main(): >> yep := maybe_c_string(yes) = CString("hi")? >> nope := maybe_c_string(no) - = none : CString + = none >> if yep: >> yep = CString("hi") @@ -241,16 +243,15 @@ func main(): = 123 # Test comparisons, hashing, equality: - >> (none:Int == 5?) + >> (none == 5?) = no >> (5? == 5?) = yes - >> {none:Int, none:Int} - = {none:Int} >> nones : {Int?} = {none, none} - = {none} - >> [5?, none:Int, none:Int, 6?]:sorted() - = [none:Int, none:Int, 5, 6] + >> also_nones : {Int?} = {none} + >> nones == also_nones + >> [5?, none, none, 6?]:sorted() + = [none, none, 5, 6] do: >> value := if var := 5?: @@ -260,7 +261,7 @@ func main(): = 5 do: - >> value := if var := none:Int: + >> value := if var : Int? = none: var else: 0 @@ -274,7 +275,7 @@ func main(): >> opt do: - >> opt := none:Int + >> opt : Int? = none >> if opt: >> opt else: @@ -283,7 +284,8 @@ func main(): >> not 5? = no - >> not none:Int + >> nah : Int? = none + >> not nah = yes >> [Struct(5,"A")?, Struct(6,"B"), Struct(7,"C")] diff --git a/test/serialization.tm b/test/serialization.tm index 2027cb90..9e3ac368 100644 --- a/test/serialization.tm +++ b/test/serialization.tm @@ -1,5 +1,5 @@ -struct Foo(name:Text, next=none:@Foo) +struct Foo(name:Text, next:@Foo?=none) enum MyEnum(Zero, One(x:Int), Two(x:Num, y:Text)) @@ -82,7 +82,7 @@ func main(): = yes do: - >> obj := none:Num + >> obj : Num? = none >> bytes := obj:serialized() >> deserialize(bytes -> Num?) == obj = yes diff --git a/test/structs.tm b/test/structs.tm index b546488c..c1d2f7b0 100644 --- a/test/structs.tm +++ b/test/structs.tm @@ -2,11 +2,11 @@ struct Single(x:Int) struct Pair(x,y:Int) struct Mixed(x:Int, text:Text) -struct LinkedList(x:Int, next=none:@LinkedList) +struct LinkedList(x:Int, next:@LinkedList?=none) struct Password(text:Text; secret) struct CorecursiveA(other:@CorecursiveB?) -struct CorecursiveB(other=none:@CorecursiveA) +struct CorecursiveB(other:@CorecursiveA?=none) func test_literals(): >> Single(123) diff --git a/test/tables.tm b/test/tables.tm index 144b93e5..e75788bb 100644 --- a/test/tables.tm +++ b/test/tables.tm @@ -7,7 +7,7 @@ func main(): >> t["two"] = 2? >> t["???"] - = none:Int + = none >> t["one"]! = 1 >> t["???"] or -1 @@ -37,7 +37,7 @@ func main(): >> t2["three"] = 3? >> t2["???"] - = none:Int + = none >> t2.length = 1 diff --git a/test/text.tm b/test/text.tm index ae91050f..0316a96f 100644 --- a/test/text.tm +++ b/test/text.tm @@ -59,7 +59,7 @@ func main(): >> Text.from_bytes([0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65])! = "Amélie" >> Text.from_bytes([Byte(0xFF)]) - = none:Text + = none amelie2 := "Am$(\U65\U301)lie" >> amelie2:split() -- cgit v1.2.3