1;
2; Copyright (c) 2020 Nordic Semiconductor ASA
3;
4; SPDX-License-Identifier: Apache-2.0
5;
6
7Numbers = [
8	one: 1,
9	minustwo: -2,
10	fourtoten: 4..10,
11	twobytes: uint .size 2,
12	onetofourbytes: uint .size 0b1..0o4, ; Testing binary and octal
13	minusfivektoplustwohundred: -5000..200,
14	fourbillion: 0xEE6B2800,
15	negint: nint,
16	posint: uint,
17	tagged_int: #6.65535(int),
18]
19
20MyInt = int
21
22Numbers2 = [
23	threebytes: uint .size 4,
24	int32: int .size 4,
25	big_int: int .size 8,
26	big_uint: uint .gt 0x100000000,
27	big_uint2: uint .size 8,
28	big_nint: -0x80000001,
29	big_nint2: -0x80000000,
30	tagged_int: #6.1234(MyInt),
31]
32
33TaggedUnion = #6.4321(bool) // #6.2345(uint)
34
35; Using .size and .cbor together with maps.
36NumberMap = {
37	"byte" => uint .size 1,
38	? "opt_short" => uint .size 2,
39	? "opt_cbor" => bstr .size 5 .cbor (uint .size 4),
40}
41
42Strings = [
43	hello: "hello",
44	threehundrebytebstr: bstr .size 300,
45	#6.0(tentothirtybytetstr: tstr .size 10..30),
46	cborNumbers: bstr .cbor Numbers,
47	cborseqSimples: bstr .cborseq Simples,
48	?optCborStrings: bstr .cbor Strings,
49]
50
51Simples = [
52	booltrue: true,
53	boolfalse: false,
54	boolval: bool,
55	nilval: nil,
56	undef: undefined,
57]
58
59Simple1 = Simples
60Simple2 = Simple1
61
62Optional = [
63	#6.10(boolval: bool),
64	?optbool: bool,
65	?opttwo: 2,
66	manduint: uint,
67	*multi8: 8,
68]
69
70Group = (1,-2)
71MultiGroup = +(3,-4)
72Union = Group / MultiGroup / (3,4) / "\"hello\""
73
74Map = {
75	listkey: [5,6] => bool,
76	union: (7=>uint) / (-8=>uint),
77	twotothree: 2*3 nil => bstr,
78}
79
80EmptyMap = {}
81
82NestedListMap = [*{?1 => 4}]
83NestedMapListMap = {+[] => [*{}]}
84
85Level1 = [Level2]
86Level2 = [2**3Level3] ; Use ** here to test backwards compatibility.
87Level3 = [4*5Level4]
88Level4 = [0]
89
90Range = [
91	?optMinus5to5: -5..5,
92	?optStr3to6: tstr .size 3..6,
93	?optMinus9toMinus6excl: -9...-6,
94	+multi8: 8,
95	+multiHello: "hello",
96	+multi0to10: 0..0x0A, ; Testing hexadecimal
97]
98
99ValueRange = [
100	greater10: uint .gt 10,
101	less1000: int .lt 1000,
102	greatereqmin10: int .ge -10,
103	lesseq1: uint .le 1,
104	equal42: uint .eq 42,
105	equalstrworld: tstr .eq "world",
106]
107
108SingleBstr = bstr
109
110SingleInt = 52
111
112SingleInt2 = uint .lt 10
113
114Unabstracted = [
115	unabstractedunion1: (choice1: 1 // choice2: 2),
116	(unabstractedunion2: 3 / choice4: 4)
117]
118
119QuantityRange = (
120	upto4nils: 0*0x04nil,
121	from3true: 3*true,
122)
123
124MyKeys = (
125	?1 => int,
126	?2 => int
127)
128
129DoubleMap = {
130	* (uint => { MyKeys })
131}
132
133Floats = [
134	float_16: float16,
135	float_32: float32,
136	float_64: float64,
137	pi: 3.1415,
138	e: 2.71828 .size 8,
139	floats: *float,
140]
141
142; Test using ranges (greater/less than) on floats.
143Floats2 = [
144	float_lt_1: float .lt 1,
145	float_ge_min_10000: float .ge -10000,
146]
147
148Floats3 = [
149	float_16_32: float16-32,
150	float_32_64: float32-64,
151]
152
153Prelude = [
154	bytes,
155	text,
156	tdate,
157	time,
158	number,
159	biguint,
160	bignint,
161	bigint,
162	integer,
163	unsigned,
164	decfrac,
165	bigfloat,
166	eb64url,
167	eb64legacy,
168	eb16,
169	encoded-cbor,
170	uri,
171	b64url,
172	b64legacy,
173	regexp,
174	mime-message,
175	cbor-any,
176	float16-32,
177	float32-64,
178	null,
179]
180
181; Testing complex .cbor statements, including nested .cbor.
182CBORBstr = bstr .cbor ([
183	hello: bstr .cbor "Hello",
184	pi: bstr .cbor 3.1415,
185	big_uint_bstr: (bstr .cbor biguint),
186	nilval2: bstr .cbor nil
187])
188
189
190result_code = int
191mac_address = bstr .size 6
192uuid = bstr .size 16
193
194; Test combination of map + optional + * + size check
195MapLength = {
196	"r" : (result:result_code),
197	"m" : (mac_addr:mac_address),
198	?"e" : (end_device_array:[* uuid]),
199}
200
201Structure_One = (
202	id: 1,
203	some_array: bstr
204)
205
206UnionInt1 = [
207	(union_uint1: 5, "This is a five") //
208	(union_uint2: 1000, bstr) //
209	(union_uint3: -100000, null, number)
210]
211
212UnionInt2 = [
213	(5, "This is a five") //
214	(1000, bstr) //
215	(-100000, null, number) //
216	Structure_One
217]
218
219Intmax1 = [
220	INT_8_MIN: -128,
221	INT_8_MAX: 127,
222	UINT_8_MAX: 255,
223	INT_16_MIN: -32768,
224	INT_16_MAX: 32767,
225	UINT_16_MAX: 65535,
226	INT_32_MIN: -2147483648,
227	INT_32_MAX: 2147483647,
228	UINT_32_MAX: 4294967295,
229	INT_64_MIN: -9223372036854775808,
230	INT_64_MAX: 9223372036854775807,
231	UINT_64_MAX: 18446744073709551615,
232]
233
234Intmax2 = [
235	INT_8: -128..127,
236	UINT_8: 0..255,
237	INT_16: -32768..32767,
238	UINT_16: 0..65535,
239	INT_32: -2147483648..2147483647,
240	UINT_32: 0..4294967295,
241	INT_64: -9223372036854775808..9223372036854775807,
242	UINT_64: 0..18446744073709551615,
243]
244
245Intmax3 = [
246	(254 / 255),
247	int .le 65535,
248	{-128 => bstr .size 127},
249]
250
251InvalidIdentifiers = [
252	? "1one",
253	? Ø: 2,
254	? "{[a-z]}",
255]
256
257Uint64List = [
258	* uint64: uint .size 8,
259	? nint64: nint .size 8,
260	? uint64_lit: 0x0123456789abcdef,
261	* nint64_lit: -0x0123456789abcdef,
262]
263
264BstrSize = {
265    bstr12,
266}
267bstr12 = ("s" : bstr .size 12)
268