-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
marshal.test.gr
95 lines (78 loc) 路 1.98 KB
/
marshal.test.gr
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module MarshalTest
from "marshal" include Marshal
use Marshal.*
from "bytes" include Bytes
from "result" include Result
let roundtripOk = value => unmarshal(marshal(value)) == Ok(value)
assert roundtripOk(void)
assert roundtripOk(true)
assert roundtripOk(42)
assert roundtripOk(42l)
assert roundtripOk(42L)
assert roundtripOk(42ul)
assert roundtripOk(42uL)
assert roundtripOk(42.0)
assert roundtripOk(42.0f)
assert roundtripOk(42.0d)
assert roundtripOk(-1s)
assert roundtripOk(-1S)
assert roundtripOk(42us)
assert roundtripOk(42uS)
assert roundtripOk(1/3)
assert roundtripOk('c')
assert roundtripOk("unicode string 馃挴馃尵馃檹馃徑")
assert roundtripOk(Bytes.fromString("unicode string 馃挴馃尵馃檹馃徑"))
assert roundtripOk((14, false, "hi"))
assert roundtripOk([> 1, 2, 3])
assert roundtripOk([> 1l, 2l, 3l])
assert roundtripOk([1, 2, 3])
assert roundtripOk([1l, 2l, 3l])
enum rec Foo<a> {
Bar,
Baz(a),
Qux(String, a),
Quux(Foo<a>),
}
assert roundtripOk(Bar)
assert roundtripOk(Baz("baz"))
assert roundtripOk(Qux("qux", 42l))
assert roundtripOk(Quux(Qux("qux", 42l)))
record Bing<a> {
bang: Void,
bop: a,
swish: (String, a),
pow: Foo<Int32>,
}
assert roundtripOk(
{ bang: void, bop: "bee", swish: ("bit", "but"), pow: Quux(Qux("qux", 42l)) }
)
let make5 = () => "five"
let closureTest = () => {
let val = make5()
let foo = () => val
assert Result.unwrap(unmarshal(marshal(foo)))() == "five"
}
closureTest()
record rec Cyclic {
mut self: List<Cyclic>,
}
let cyclic = { self: [], }
cyclic.self = [cyclic, cyclic, cyclic]
assert roundtripOk(cyclic)
assert Result.isErr(unmarshal(Bytes.empty))
let truncatedString = Bytes.slice(0, 16, marshal("beep boop bop"))
assert Result.isErr(unmarshal(truncatedString))
let truncatedRecord = Bytes.slice(
0,
64,
marshal(
{
bang: void,
bop: "bee",
swish: ("bit", "but"),
pow: Quux(Qux("qux", 42l)),
}
)
)
assert Result.isErr(unmarshal(truncatedRecord))
assert Marshal.marshal("馃尵") == Marshal.marshal("馃尵")