aboutsummaryrefslogtreecommitdiff
path: root/test/structs.tm
blob: c86f91022dcb87512b1f847d4f8db608a2bae001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

struct Pair(x,y:Int)
struct Mixed(x:Int, text:Text)

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()