code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(66 lines)
2 struct Single(x:Int)
3 struct Pair(x,y:Int)
4 struct Mixed(x:Int, text:Text)
5 struct LinkedList(x:Int, next:@LinkedList?=none)
6 struct Password(text:Text; secret)
8 struct CorecursiveA(other:@CorecursiveB?)
9 struct CorecursiveB(other:@CorecursiveA?=none)
11 func test_literals()
12 assert Single(123) == Single(123)
13 x := Pair(10, 20)
14 assert x == Pair(x=10, y=20)
15 y := Pair(y=20, 10)
16 assert y == Pair(x=10, y=20)
17 assert x == y
18 assert x != Pair(-1, -2)
20 func test_metamethods()
21 >> x := Pair(10, 20)
22 >> y := Pair(100, 200)
23 assert x == y == no
24 assert x == Pair(10, 20)
25 assert x != Pair(10, 30)
27 assert x < Pair(11, 20)
28 >> set := {x: yes}
29 assert set.has(x) == yes
30 assert set.has(y) == no
32 func test_mixed()
33 >> x := Mixed(10, "Hello")
34 >> y := Mixed(99, "Hello")
35 assert x == y == no
36 assert x == Mixed(10, "Hello")
37 assert x != Mixed(10, "Bye")
38 assert x < Mixed(11, "Hello")
39 >> set := {x: yes}
40 assert set.has(x) == yes
41 assert set.has(y) == no
43 func test_text()
44 >> b := @CorecursiveB()
45 >> a := @CorecursiveA(b)
46 >> b.other = a
47 >> a
48 # = @CorecursiveA(@CorecursiveB(@~1))
50 func main()
51 test_literals()
52 test_metamethods()
53 test_mixed()
54 test_text()
56 >> @LinkedList(10, @LinkedList(20))
58 >> my_pass := Password("Swordfish")
59 assert my_pass == Password("Swordfish")
60 assert "$my_pass" == "Password(...)"
61 >> users_by_password := {my_pass: "User1", Password("xxx"): "User2"}
62 assert "$users_by_password" == '{Password(...): "User1", Password(...): "User2"}'
63 assert users_by_password[my_pass]! == "User1"
65 >> CorecursiveA(@CorecursiveB())