-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathsubtypes.test.did
167 lines (145 loc) · 9.98 KB
/
subtypes.test.did
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Encoding tests for subtype tests in decoders
Corresponding to spec version version 0.1.6
This test file contains tests for the subtype check that decoders are expected
to perform upon references.
The shortest way to trigger a test for `t1 <: t2` is to pass `(func () -> (t1))`
and decode at type `(opt func () -> (t2))`, and check if the result is a
`reference` or `null`.
The patterns idioms here are thus
assert blob "DIDL\01\6a\00\01XX00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (t2)) "t1 <: t2";
assert blob "DIDL\01\6a\00\01XX\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (t2)) "t1 </: t2";
where XX is the a primitive type index of t1, or
assert blob "DIDL\02\6a\00\01\01\00XX\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (t2)) "t1 <: t2";
assert blob "DIDL\02\6a\00\01\01\00XX\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (t2)) "t1 </: t2";
where XX is a type entry table for a non-primitive type t1
*/
type Vec = vec Vec;
type EmptyRecord = record { 0 : EmptyRecord };
type MuRecordOpt = record { 0 : opt MuRecordOpt };
type EmptyVariant = variant { 0: EmptyVariant };
// some reflexive cases
assert blob "DIDL\01\6a\00\01\7f\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (null)) "null <: null";
assert blob "DIDL\01\6a\00\01\7e\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (bool)) "bool <: bool";
assert blob "DIDL\01\6a\00\01\7d\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (nat)) "nat <: nat";
assert blob "DIDL\01\6a\00\01\7c\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (int)) "int <: int";
// more basic cases
assert blob "DIDL\01\6a\00\01\7d\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (int)) "nat <: int";
assert blob "DIDL\01\6a\00\01\7f\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (nat)) "int </: nat";
assert blob "DIDL\01\6a\00\01\7d\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (nat8)) "nat </: nat8";
assert blob "DIDL\01\6a\00\01\7b\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (nat)) "nat8 </: nat";
// options. They are supertypes of anything really
assert blob "DIDL\01\6a\00\01\7d\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (opt bool)) "nat <: opt bool";
assert blob "DIDL\02\6a\00\01\01\00\6e\7e\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (opt bool)) "opt bool <: opt bool";
assert blob "DIDL\01\6a\00\01\7e\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (opt bool)) "bool <: opt bool";
assert blob "DIDL\02\6a\00\01\01\00\6e\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (opt opt nat)) "µ opt <: opt opt nat";
// optional record fields
assert blob "DIDL\02\6a\00\01\01\00\6c\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (record {})) "record {} <: record {}";
assert blob "DIDL\02\6a\00\01\01\00\6c\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (record { a : opt empty })) "record {} <: record { a : opt empty }";
assert blob "DIDL\02\6a\00\01\01\00\6c\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (record { a : opt null })) "record {} <: record { a : opt null }";
assert blob "DIDL\02\6a\00\01\01\00\6c\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (record { a : reserved })) "record {} <: record { a : reserved }";
assert blob "DIDL\02\6a\00\01\01\00\6c\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (record { a : empty })) "record {} </: record { a : empty }";
assert blob "DIDL\02\6a\00\01\01\00\6c\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (record { a : nat })) "record {} </: record { a : nat }";
assert blob "DIDL\02\6a\00\01\01\00\6c\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (record { a : null })) "record {} <: record { a : null }";
// optional func results
assert blob "DIDL\02\6a\00\01\01\00\6a\00\00\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> ())) "func () -> () <: func () -> ()";
assert blob "DIDL\02\6a\00\01\01\00\6a\00\00\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> (opt empty))) "func () -> () <: func () -> (opt empty)";
assert blob "DIDL\02\6a\00\01\01\00\6a\00\00\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> (opt null))) "func () -> () <: func () -> (opt null)";
assert blob "DIDL\02\6a\00\01\01\00\6a\00\00\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> (reserved))) "func () -> () <: func () -> (reserved)";
assert blob "DIDL\02\6a\00\01\01\00\6a\00\00\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (func () -> (empty))) "func () -> () </: func () -> (empty)";
assert blob "DIDL\02\6a\00\01\01\00\6a\00\00\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (func () -> (nat))) "func () -> () </: func () -> (nat)";
assert blob "DIDL\02\6a\00\01\01\00\6a\00\00\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> (null))) "func () -> () <: func () -> (null)";
// optional func arguments
assert blob "DIDL\03\6a\00\01\01\00\6a\01\02\00\00\6e\6f\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> ())) "func (opt empty) -> () <: func () -> ()";
assert blob "DIDL\03\6a\00\01\01\00\6a\01\02\00\00\6e\7f\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> ())) "func (opt null) -> () <: func () -> ()";
assert blob "DIDL\02\6a\00\01\01\00\6a\01\70\00\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> ())) "func (reserved) -> () <: func () -> ()";
assert blob "DIDL\02\6a\00\01\01\00\6a\01\6f\00\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (func () -> ())) "func (empty) -> () </: func () -> ()";
assert blob "DIDL\02\6a\00\01\01\00\6a\01\7d\00\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (func () -> ())) "func (nat) -> () </: func () -> ()";
assert blob "DIDL\02\6a\00\01\01\00\6a\01\7f\00\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (func () -> ())) "func (null) -> () <: func () -> ()";
// variants
assert blob "DIDL\02\6a\00\01\01\00\6b\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (variant {})) "variant {} <: variant {}";
assert blob "DIDL\02\6a\00\01\01\00\6b\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (variant {0 : nat})) "variant {} <: variant {0 : nat}";
assert blob "DIDL\02\6a\00\01\01\00\6b\01\00\7d\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (variant {0 : nat})) "variant {0 : nat} <: variant {0 : nat}";
assert blob "DIDL\02\6a\00\01\01\00\6b\01\00\7e\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (variant {0 : nat})) "variant {0 : bool} </: variant {0 : nat}";
assert blob "DIDL\02\6a\00\01\01\00\6b\01\00\7e\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (variant {1 : bool})) "variant {0 : bool} </: variant {1 : bool}";
// infinite types
assert blob "DIDL\02\6a\00\01\01\00\6c\01\00\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (EmptyRecord)) "(µ record) <: (µ record)";
//assert blob "DIDL\02\6a\00\01\01\00\6c\01\00\01\01\00\01\01\00\01m"
// == "(null)" : (opt func () -> (empty)) "(µ record) </: empty";
assert blob "DIDL\01\6a\00\01\6f\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (EmptyRecord)) "empty <: (µ record)";
assert blob "DIDL\02\6a\00\01\01\00\6c\01\00\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (record {EmptyRecord})) "(µ record) <: record {µ record}";
assert blob "DIDL\03\6a\00\01\01\00\6c\01\00\02\6c\01\00\02\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (EmptyRecord)) "record {µ record} <: (µ record)";
assert blob "DIDL\02\6a\00\01\01\00\6c\01\00\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (MuRecordOpt)) "(µ record) <: (μ (record opt))";
assert blob "DIDL\02\6a\00\01\01\00\6b\01\00\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (EmptyVariant)) "(µ variant) <: (µ variant)";
assert blob "DIDL\02\6a\00\01\01\00\6b\01\00\01\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (empty)) "(µ variant) </: empty";
assert blob "DIDL\01\6a\00\01\6f\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (EmptyVariant)) "empty <: (µ variant)";
assert blob "DIDL\02\6a\00\01\01\00\6b\01\00\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (variant {0 : EmptyVariant})) "(µ variant) <: variant {µ variant}";
assert blob "DIDL\03\6a\00\01\01\00\6b\01\00\02\6b\01\00\02\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (EmptyVariant)) "variant {µ variant} <: (µ variant)";
assert blob "DIDL\02\6a\00\01\01\00\6d\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (Vec)) "(µ vec) <: (µ vec)";
assert blob "DIDL\02\6a\00\01\01\00\6d\01\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (empty)) "(µ vec) </: empty";
assert blob "DIDL\01\6a\00\01\6f\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (Vec)) "empty <: (µ vec)";
assert blob "DIDL\02\6a\00\01\01\00\6d\01\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (vec Vec)) "(µ vec) <: vec {µ vec}";
assert blob "DIDL\03\6a\00\01\01\00\6d\02\6d\02\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (Vec)) "vec {µ vec} <: (µ vec)";
// future types
// This uses 0x67 for the “future type”; bump (well, decrement) once that
// becomes a concrete future type
assert blob "DIDL\02\6a\00\01\01\00\67\00\01\00\01\01\00\01m"
== "(opt func \"aaaaa-aa\".m)" : (opt func () -> (opt empty)) "(future type) <: (opt empty)";
assert blob "DIDL\02\6a\00\01\01\00\67\00\01\00\01\01\00\01m"
== "(null)" : (opt func () -> (nat)) "(future type) </: (nat)";