diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-06 16:07:23 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-06 16:07:23 -0400 |
| commit | 6782cc5570e194791ca6cdd695b88897e9145564 (patch) | |
| tree | a428e9d954aca251212ec1cf15bd35e0badce630 /test/optionals.tm | |
| parent | 448e805293989b06e07878a4a87fdd378f7c6e02 (diff) | |
No more colons for blocks
Diffstat (limited to 'test/optionals.tm')
| -rw-r--r-- | test/optionals.tm | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/test/optionals.tm b/test/optionals.tm index bf3e1633..d81d065f 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -1,74 +1,74 @@ -struct Struct(x:Int, y:Text): - func maybe(should_i:Bool->Struct?): - if should_i: +struct Struct(x:Int, y:Text) + func maybe(should_i:Bool->Struct?) + if should_i return Struct(123, "hello") - else: + else return none -enum Enum(X, Y(y:Int)): - func maybe(should_i:Bool->Enum?): - if should_i: +enum Enum(X, Y(y:Int)) + func maybe(should_i:Bool->Enum?) + if should_i return Enum.Y(123) - else: + else return none -func maybe_int(should_i:Bool->Int?): - if should_i: +func maybe_int(should_i:Bool->Int?) + if should_i return 123 - else: + else return none -func maybe_int64(should_i:Bool->Int64?): - if should_i: +func maybe_int64(should_i:Bool->Int64?) + if should_i return Int64(123) - else: + else return none -func maybe_array(should_i:Bool->[Int]?): - if should_i: +func maybe_array(should_i:Bool->[Int]?) + if should_i return [10, 20, 30] - else: + else return none -func maybe_bool(should_i:Bool->Bool?): - if should_i: +func maybe_bool(should_i:Bool->Bool?) + if should_i return no - else: + else return none -func maybe_text(should_i:Bool->Text?): - if should_i: +func maybe_text(should_i:Bool->Text?) + if should_i return "Hello" - else: + else return none -func maybe_num(should_i:Bool->Num?): - if should_i: +func maybe_num(should_i:Bool->Num?) + if should_i return 12.3 - else: + else return none -func maybe_lambda(should_i:Bool-> func()?): - if should_i: - return func(): say("hi!") - else: +func maybe_lambda(should_i:Bool-> func()?) + if should_i + return func() say("hi!") + else return none -func maybe_c_string(should_i:Bool->CString?): - if should_i: +func maybe_c_string(should_i:Bool->CString?) + if should_i return ("hi".as_c_string())? - else: + else return none -func main(): +func main() >> 5? = 5? - >> if no: + >> if no x : Int? = none x - else: + else 5 = 5? @@ -85,157 +85,157 @@ func main(): >> none_int or -1 = -1 - do: + do say("Ints:") >> yep := maybe_int(yes) = 123? >> nope := maybe_int(no) = none - >> if yep: + >> if yep >> yep = 123 - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("Int64s:") >> yep := maybe_int64(yes) = Int64(123)? >> nope := maybe_int64(no) = none - >> if yep: + >> if yep >> yep = Int64(123) - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("Arrays:") >> yep := maybe_array(yes) = [10, 20, 30]? >> nope := maybe_array(no) = none - >> if yep: + >> if yep >> yep = [10, 20, 30] - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("...") say("Bools:") >> yep := maybe_bool(yes) = no? >> nope := maybe_bool(no) = none - >> if yep: + >> if yep >> yep = no - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("...") say("Text:") >> yep := maybe_text(yes) = "Hello"? >> nope := maybe_text(no) = none - >> if yep: + >> if yep >> yep = "Hello" - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("...") say("Nums:") >> yep := maybe_num(yes) = 12.3? >> nope := maybe_num(no) = none - >> if yep: + >> if yep >> yep = 12.3 - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("...") say("Lambdas:") # >> yep := maybe_lambda(yes) # = func() [optionals.tm:54] : func()? >> nope := maybe_lambda(no) = none - # >> if yep: + # >> if yep # >> yep # = func() [optionals.tm:54] - # else: fail("Falsey: $yep") - >> if nope: + # else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("...") say("Structs:") >> yep := Struct.maybe(yes) = Struct(x=123, y="hello")? >> nope := Struct.maybe(no) = none - >> if yep: + >> if yep >> yep = Struct(x=123, y="hello") - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("...") say("Enums:") >> yep := Enum.maybe(yes) = Enum.Y(123)? >> nope := Enum.maybe(no) = none - >> if yep: + >> if yep >> yep = Enum.Y(123) - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - do: + do say("...") say("C Strings:") >> yep := maybe_c_string(yes) = CString("hi")? >> nope := maybe_c_string(no) = none - >> if yep: + >> if yep >> yep = CString("hi") - else: fail("Falsey: $yep") - >> if nope: + else fail("Falsey: $yep") + >> if nope fail("Truthy: $nope") - else: say("Falsey: $nope") + else say("Falsey: $nope") - if yep := maybe_int(yes): + if yep := maybe_int(yes) >> yep = 123 - else: fail("Unreachable") + else fail("Unreachable") >> maybe_int(yes)! = 123 @@ -251,32 +251,32 @@ func main(): >> [5?, none, none, 6?].sorted() = [none, none, 5, 6] - do: - >> value := if var := 5?: + do + >> value := if var := 5? var - else: + else 0 = 5 - do: + do >> value := if var : Int? = none: var - else: + else 0 = 0 - do: + do >> opt := 5? - >> if opt: + >> if opt >> opt - else: + else >> opt - do: + do >> opt : Int? = none - >> if opt: + >> if opt >> opt - else: + else >> opt >> not 5? @@ -289,7 +289,7 @@ func main(): >> [Struct(5,"A")?, Struct(6,"B"), Struct(7,"C")] = [Struct(x=5, y="A")?, Struct(x=6, y="B")?, Struct(x=7, y="C")?] - if 5? or no: + if 5? or no say("Binary op 'or' works with optionals") - else: + else fail("Failed to do binary op 'or' on optional") |
