diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-24 16:07:52 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-24 16:07:52 -0500 |
| commit | 65f684fb6ab7791ac8641fe2682d7eb5f1c0dde2 (patch) | |
| tree | 2f18a92fafb1d406af93e2b7aa484889d68ace92 /test/structs.tm | |
| parent | c2228bf9861b38f2514d0cc8a270754bb3a03dd7 (diff) | |
Rename file extensions
Diffstat (limited to 'test/structs.tm')
| -rw-r--r-- | test/structs.tm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/structs.tm b/test/structs.tm new file mode 100644 index 00000000..a9bb545f --- /dev/null +++ b/test/structs.tm @@ -0,0 +1,52 @@ + +struct Pair(x,y:Int) +struct Mixed(x:Int, str:Str) + +func test_literals() + >> x := Pair(10, 20) + = Pair(x=10, y=20) + >> y := Pair(y=20, 10) + = Pair(x=10, y=20) + >> x == y + = yes + >> x == Pair(-1, -2) + = no +test_literals() + +func test_metamethods() + >> x := Pair(10, 20) + >> y := Pair(100, 200) + >> x == y + = no + >> x == Pair(10, 20) + = yes + >> x == Pair(10, 30) + = no + + >> x < Pair(11, 20) + = yes + >> t2 := {x=> "found"; default="missing"} + >> t2[x] + = "found" + >> t2[y] + = "missing" +test_metamethods() + +func test_mixed() + >> x := Mixed(10, "Hello") + >> y := Mixed(99, "Hello") + >> x == y + = no + >> x == Mixed(10, "Hello") + = yes + >> x == Mixed(10, "Bye") + = no + >> x < Mixed(11, "Hello") + = yes + >> t := {x=> "found"; default="missing"} + >> t[x] + = "found" + >> t[y] + = "missing" +test_mixed() + |
