tomo/test/enums.tm

36 lines
482 B
Plaintext
Raw Normal View History

2024-02-24 12:24:44 -08:00
enum Foo(Zero, One(x:Int), Two(x,y:Int))
2024-04-12 10:09:31 -07:00
func main()
>> Foo.Zero
= Foo.Zero
>> Foo.One(123)
= Foo.One(x=123)
>> Foo.Two(123, 456)
= Foo.Two(x=123, y=456)
>> Foo.One(10) == Foo.One(10)
= yes
>> Foo.One(10) == Foo.Zero
= no
>> Foo.One(10) == Foo.One(-1)
= no
>> Foo.One(10) < Foo.Two(1, 2)
= yes
>> x := Foo.One(123)
>> t := {x:"found"; default="missing"}
2024-04-12 10:09:31 -07:00
>> t[x]
= "found"
>> t[Foo.Zero]
= "missing"
when x is o:One
>> o.x
= 123
else
fail("Oops")
2024-03-17 18:48:53 -07:00