aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-24 14:42:11 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-24 14:42:11 -0500
commitc7470346457550467bafd9199185c5d0e8481f02 (patch)
treebb09e8fc9911a9acd43c9dee510b01d57aa0bbf2 /tests
parente2520d817ce6dd3f4d2ef320b6648a7373e3674a (diff)
Add struct tests
Diffstat (limited to 'tests')
-rw-r--r--tests/structs.nl52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/structs.nl b/tests/structs.nl
new file mode 100644
index 00000000..dae69e9f
--- /dev/null
+++ b/tests/structs.nl
@@ -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 == Foo(10, "Hello")
+ = yes
+ >> x == Foo(10, "Bye")
+ = no
+ >> x < Foo(11, "Hello")
+ = yes
+ >> t := {x=> "found"; default="missing"}
+ >> t[x]
+ = "found"
+ >> t[y]
+ = "missing"
+test_mixed()
+