code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(87 lines)
2 struct Foo(name:Text, next:@Foo?=none)
4 enum MyEnum(Zero, One(x:Int), Two(x:Num, y:Text))
6 func main()
7 do
8 >> obj := Int64(123)
9 >> bytes : [Byte] = obj
10 >> roundtrip : Int64 = bytes
11 assert roundtrip == obj
13 do
14 >> obj := 5
15 >> bytes : [Byte] = obj
16 >> roundtrip : Int = bytes
17 assert roundtrip == obj
19 do
20 >> obj := 9999999999999999999999999999999999999999999999999999
21 >> bytes : [Byte] = obj
22 >> roundtrip : Int = bytes
23 assert roundtrip == obj
25 do
26 >> obj := "Héllo"
27 >> bytes : [Byte] = obj
28 >> roundtrip : Text = bytes
29 assert roundtrip == obj
31 do
32 >> obj := [Int64(10), Int64(20), Int64(30)].reversed()
33 >> bytes : [Byte] = obj
34 >> roundtrip : [Int64] = bytes
35 assert roundtrip == obj
37 do
38 >> obj := yes
39 >> bytes : [Byte] = obj
40 >> roundtrip : Bool = bytes
41 assert roundtrip == obj
43 do
44 >> obj := @[10, 20]
45 >> bytes : [Byte] = obj
46 >> roundtrip : @[Int] = bytes
47 assert roundtrip != obj
48 assert roundtrip[] == obj[]
50 do
51 >> obj := {"A":10, "B":20; fallback={"C":30}}
52 >> bytes : [Byte] = obj
53 >> roundtrip : {Text:Int} = bytes
54 assert roundtrip == obj
55 assert roundtrip.fallback == obj.fallback
57 do
58 >> obj := @Foo("root")
59 >> obj.next = @Foo("abcdef", next=obj)
60 >> bytes : [Byte] = obj
61 >> roundtrip : @Foo = bytes
62 assert "$roundtrip" == "$obj"
64 do
65 >> obj := MyEnum.Two(123, "OKAY")
66 >> bytes : [Byte] = obj
67 >> roundtrip : MyEnum = bytes
68 assert roundtrip == obj
70 do
71 >> obj : Text? = "Hello"
72 >> bytes : [Byte] = obj
73 >> roundtrip : Text? = bytes
74 assert roundtrip == obj
76 do
77 >> obj : Num? = none
78 >> bytes : [Byte] = obj
79 >> roundtrip : Num? = bytes
80 assert roundtrip == obj
82 do
83 cases := [0, -1, 1, 10, 100000, 999999999999999999999999999]
84 for i in cases
85 >> bytes : [Byte] = i
86 >> roundtrip : Int = bytes
87 assert roundtrip == i