diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-05-01 13:53:51 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-05-01 13:53:51 -0400 |
| commit | c2daf6a92895d9835ecf75118f7fa1f25ff0395f (patch) | |
| tree | 98786db0bd2246874e362475bca5da5a95d15c77 /test | |
| parent | e3ad5fdaaae075b4080c86bd243f5c7f3b09972b (diff) | |
Clean up 'when' syntax
Diffstat (limited to 'test')
| -rw-r--r-- | test/enums.tm | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/test/enums.tm b/test/enums.tm index 1bc26203..9f700410 100644 --- a/test/enums.tm +++ b/test/enums.tm @@ -1,4 +1,19 @@ -enum Foo(Zero, One(x:Int), Two(x,y:Int)) +enum Foo(Zero, One(x:Int), Two(x:Int, y:Int), Three(x:Int, y:Text, z:Bool), Four(x,y,z,w:Int), Last(t:Text)) + +func choose_text(f:Foo)->Text: + >> f + when f is Zero: + return "Zero" + is One(one): + return "One: {one}" + is Two(x, y): + return "Two: x={x}, y={y}" + is Three(three): + return "Three: {three}" + is Four: + return "Four" + else: + return "else: {f}" func main(): >> Foo.Zero @@ -27,9 +42,16 @@ func main(): >> t[Foo.Zero] = "missing" - when x is o:One: - >> o.x - = 123 - else: - fail("Oops") + >> choose_text(Foo.Zero) + = "Zero" + >> choose_text(Foo.One(123)) + = "One: 123" + >> choose_text(Foo.Two(123, 456)) + = "Two: x=123, y=456" + >> choose_text(Foo.Three(123, "hi", yes)) + = "Three: Three(x=123, y=\"hi\", z=yes)" + >> choose_text(Foo.Four(1,2,3,4)) + = "Four" + >> choose_text(Foo.Last("XX")) + = "else: Foo.Last(t=\"XX\")" |
