diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-11-23 13:28:48 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-11-23 13:28:48 -0500 |
| commit | 0fa9a52090eb5d9ce88220c0134a8d2af6eb8d94 (patch) | |
| tree | 87a3181238da384a94077f401b0ba49eb8eb1e7e /test/enums.tm | |
| parent | 1c77d596b28ee45e0234cfa7c5f5679492f2178e (diff) | |
Accessing enum fields now gives an optional value instead of a boolean
Diffstat (limited to 'test/enums.tm')
| -rw-r--r-- | test/enums.tm | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/test/enums.tm b/test/enums.tm index fe767ebf..80f66ed8 100644 --- a/test/enums.tm +++ b/test/enums.tm @@ -1,4 +1,5 @@ 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)) +enum OnlyTags(A, B, C, D) func choose_text(f:Foo->Text) >> f @@ -33,10 +34,6 @@ func main() assert Foo.One(123) == Foo.One(123) assert Foo.Two(123, 456) == Foo.Two(x=123, y=456) - >> one := Foo.One(123) - assert one.One == yes - assert one.Two == no - assert Foo.One(10) == Foo.One(10) assert Foo.One(10) == Foo.Zero == no @@ -99,3 +96,35 @@ func main() assert EnumFields(A) == EnumFields(x=A) + do + e := OnlyTags.A + assert e.A == EMPTY + assert e.B == none + + do + e := Foo.Zero + assert e.Zero == EMPTY + assert e.One == none + assert e.Two == none + + ep := @Foo.Zero + assert ep.Zero == EMPTY + assert ep.One == none + assert ep.Two == none + + do + e := Foo.Two(123, 456) + assert e.Zero == none + assert e.One == none + assert e.Two != none + + ep := Foo.Two(123, 456) + assert ep.Zero == none + assert ep.One == none + assert ep.Two != none + + two := e.Two! + when e is Two(x,y) + assert two.x == x + assert two.y == y + else fail("Unreachable") |
