1 USING: bare multiline prettyprint prettyprint.config sequences tools.test ;
7 { 0 } [ B{ 0x00 } uint bare> ] unit-test
8 { B{ 0x00 } } [ 0 uint >bare ] unit-test
10 { 1 } [ B{ 0x01 } uint bare> ] unit-test
11 { B{ 0x01 } } [ 1 uint >bare ] unit-test
13 { 126 } [ B{ 0x7e } uint bare> ] unit-test
14 { B{ 0x7e } } [ 126 uint >bare ] unit-test
16 { 127 } [ B{ 0x7f } uint bare> ] unit-test
17 { B{ 0x7f } } [ 127 uint >bare ] unit-test
19 { 128 } [ B{ 0x80 0x01 } uint bare> ] unit-test
20 { B{ 0x80 0x01 } } [ 128 uint >bare ] unit-test
22 { 129 } [ B{ 0x81 0x01 } uint bare> ] unit-test
23 { B{ 0x81 0x01 } } [ 129 uint >bare ] unit-test
25 { 255 } [ B{ 0xFF 0x01 } uint bare> ] unit-test
26 { B{ 0xFF 0x01 } } [ 255 uint >bare ] unit-test
30 { 0 } [ B{ 0x00 } int bare> ] unit-test
31 { B{ 0x00 } } [ 0 int >bare ] unit-test
33 { 1 } [ B{ 0x02 } int bare> ] unit-test
34 { B{ 0x02 } } [ 1 int >bare ] unit-test
36 { -1 } [ B{ 0x01 } int bare> ] unit-test
37 { B{ 0x01 } } [ -1 int >bare ] unit-test
39 { 63 } [ B{ 0x7e } int bare> ] unit-test
40 { B{ 0x7e } } [ 63 int >bare ] unit-test
42 { -63 } [ B{ 0x7d } int bare> ] unit-test
43 { B{ 0x7d } } [ -63 int >bare ] unit-test
45 { 64 } [ B{ 0x80 0x01 } int bare> ] unit-test
46 { B{ 0x80 0x01 } } [ 64 int >bare ] unit-test
48 { -64 } [ B{ 0x7f } int bare> ] unit-test
49 { B{ 0x7f } } [ -64 int >bare ] unit-test
51 { 65 } [ B{ 0x82 0x01 } int bare> ] unit-test
52 { B{ 0x82 0x01 } } [ 65 int >bare ] unit-test
54 { -65 } [ B{ 0x81 0x01 } int bare> ] unit-test
55 { B{ 0x81 0x01 } } [ -65 int >bare ] unit-test
57 { 255 } [ B{ 0xFE 0x03 } int bare> ] unit-test
58 { B{ 0xFE 0x03 } } [ 255 int >bare ] unit-test
60 { -255 } [ B{ 0xFD 0x03 } int bare> ] unit-test
61 { B{ 0xFD 0x03 } } [ -255 int >bare ] unit-test
65 { 0 } [ B{ 0x00 0x00 0x00 0x00 } u32 bare> ] unit-test
66 { B{ 0x00 0x00 0x00 0x00 } } [ 0 u32 >bare ] unit-test
68 { 1 } [ B{ 0x01 0x00 0x00 0x00 } u32 bare> ] unit-test
69 { B{ 0x01 0x00 0x00 0x00 } } [ 1 u32 >bare ] unit-test
71 { 255 } [ B{ 0xFF 0x00 0x00 0x00 } u32 bare> ] unit-test
72 { B{ 0xFF 0x00 0x00 0x00 } } [ 255 u32 >bare ] unit-test
76 { 0 } [ B{ 0x00 0x00 } i16 bare> ] unit-test
77 { B{ 0x00 0x00 } } [ 0 i16 >bare ] unit-test
79 { 1 } [ B{ 0x01 0x00 } i16 bare> ] unit-test
80 { B{ 0x01 0x00 } } [ 1 i16 >bare ] unit-test
82 { -1 } [ B{ 0xFF 0xFF } i16 bare> ] unit-test
83 { B{ 0xFF 0xFF } } [ -1 i16 >bare ] unit-test
85 { 255 } [ B{ 0xFF 0x00 } i16 bare> ] unit-test
86 { B{ 0xFF 0x00 } } [ 255 i16 >bare ] unit-test
88 { -255 } [ B{ 0x01 0xFF } i16 bare> ] unit-test
89 { B{ 0x01 0xFF } } [ -255 i16 >bare ] unit-test
93 { 0.0 } [ B{ 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 } f64 bare> ] unit-test
94 { B{ 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 } } [ 0.0 f64 >bare ] unit-test
96 { 1.0 } [ B{ 0x00 0x00 0x00 0x00 0x00 0x00 0xF0 0x3F } f64 bare> ] unit-test
97 { B{ 0x00 0x00 0x00 0x00 0x00 0x00 0xF0 0x3F } } [ 1.0 f64 >bare ] unit-test
99 { 2.55 } [ B{ 0x66 0x66 0x66 0x66 0x66 0x66 0x04 0x40 } f64 bare> ] unit-test
100 { B{ 0x66 0x66 0x66 0x66 0x66 0x66 0x04 0x40 } } [ 2.55 f64 >bare ] unit-test
102 { -25.5 } [ B{ 0x00 0x00 0x00 0x00 0x00 0x80 0x39 0xC0 } f64 bare> ] unit-test
103 { B{ 0x00 0x00 0x00 0x00 0x00 0x80 0x39 0xC0 } } [ -25.5 f64 >bare ] unit-test
107 { t } [ B{ 0x01 } bool bare> ] unit-test
108 { B{ 0x01 } } [ t bool >bare ] unit-test
110 { f } [ B{ 0x00 } bool bare> ] unit-test
111 { B{ 0x00 } } [ f bool >bare ] unit-test
115 { "BARE" } [ B{ 0x04 0x42 0x41 0x52 0x45 } str bare> ] unit-test
116 { B{ 0x04 0x42 0x41 0x52 0x45 } } [ "BARE" str >bare ] unit-test
120 { B{ 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb } } [
121 B{ 0x10 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb }
125 { B{ 0x10 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb } } [
126 B{ 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb }
132 { B{ 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb } } [
133 B{ 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb }
137 { B{ 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb } } [
138 B{ 0xaa 0xee 0xff 0xee 0xdd 0xcc 0xbb 0xaa 0xee 0xdd 0xcc 0xbb 0xee 0xdd 0xcc 0xbb }
144 { "FOO" } [ B{ 0x00 } T{ enum f { { "FOO" 0 } { "BAR" 255 } { "BUZZ" 256 } } } bare> ] unit-test
145 { B{ 0x00 } } [ "FOO" T{ enum f { { "FOO" 0 } { "BAR" 255 } { "BUZZ" 256 } } } >bare ] unit-test
146 { "BAR" } [ B{ 0xFF 0x01 } T{ enum f { { "FOO" 0 } { "BAR" 255 } { "BUZZ" 256 } } } bare> ] unit-test
147 { B{ 0xFF 0x01 } } [ "BAR" T{ enum f { { "FOO" 0 } { "BAR" 255 } { "BUZZ" 256 } } } >bare ] unit-test
148 { "BUZZ" } [ B{ 0x80 0x02 } T{ enum f { { "FOO" 0 } { "BAR" 255 } { "BUZZ" 256 } } } bare> ] unit-test
149 { B{ 0x80 0x02 } } [ "BUZZ" T{ enum f { { "FOO" 0 } { "BAR" 255 } { "BUZZ" 256 } } } >bare ] unit-test
151 [ B{ 0x03 } T{ enum f { { "A" 0 } { "B" 1 } { "C" 2 } } } bare> ] [ invalid-enum? ] must-fail-with
152 [ "D" T{ enum f { { "A" 0 } { "B" 1 } { "C" 2 } } } >bare ] [ invalid-enum? ] must-fail-with
156 { f } [ B{ 0x00 } T{ optional f u32 } bare> ] unit-test
157 { 0 } [ B{ 0x01 0x00 0x00 0x00 0x00 } T{ optional f u32 } bare> ] unit-test
158 { 1 } [ B{ 0x01 0x01 0x00 0x00 0x00 } T{ optional f u32 } bare> ] unit-test
159 { 255 } [ B{ 0x01 0xFF 0x00 0x00 0x00 } T{ optional f u32 } bare> ] unit-test
163 { { "foo" "bar" "buzz" } } [
164 B{ 0x03 0x03 0x66 0x6f 0x6f 0x03 0x62 0x61 0x72 0x04 0x62 0x75 0x7A 0x7A }
165 T{ list f str f } bare>
168 { B{ 0x03 0x03 0x66 0x6f 0x6f 0x03 0x62 0x61 0x72 0x04 0x62 0x75 0x7A 0x7A } } [
169 { "foo" "bar" "buzz" } T{ list f str f } >bare
174 { { 0 1 254 255 256 257 126 127 128 129 } } [
175 B{ 0x00 0x01 0xFE 0x01 0xFF 0x01 0x80 0x02 0x81 0x02 0x7E 0x7F 0x80 0x01 0x81 0x01 }
176 T{ list f uint 10 } bare>
179 { B{ 0x00 0x01 0xFE 0x01 0xFF 0x01 0x80 0x02 0x81 0x02 0x7E 0x7F 0x80 0x01 0x81 0x01 } } [
180 { 0 1 254 255 256 257 126 127 128 129 } T{ list f uint 10 } >bare
187 0x03 0x00 0x00 0x00 0x00 0x04 0x7A 0x65 0x72 0x6F 0x01
188 0x00 0x00 0x00 0x03 0x6F 0x6E 0x65 0xFF 0x00 0x00 0x00
189 0x1B 0x74 0x77 0x6F 0x20 0x68 0x75 0x6E 0x64 0x72 0x65
190 0x64 0x73 0x20 0x61 0x6E 0x64 0x20 0x66 0x69 0x66 0x74
191 0x79 0x20 0x66 0x69 0x76 0x65
197 { 255 "two hundreds and fifty five" }
198 } T{ bare:map f u32 str } >bare
205 { 255 "two hundreds and fifty five" }
209 0x03 0x00 0x00 0x00 0x00 0x04 0x7A 0x65 0x72 0x6F 0x01
210 0x00 0x00 0x00 0x03 0x6F 0x6E 0x65 0xFF 0x00 0x00 0x00
211 0x1B 0x74 0x77 0x6F 0x20 0x68 0x75 0x6E 0x64 0x72 0x65
212 0x64 0x73 0x20 0x61 0x6E 0x64 0x20 0x66 0x69 0x66 0x74
213 0x79 0x20 0x66 0x69 0x76 0x65
214 } T{ bare:map f u32 str } bare>
237 B{ 0xFF 0x01 0xFF 0x01 }
239 B{ 0x80 0x02 0x04 0x42 0x41 0x52 0x45 }
241 T{ bare:union f { { int 0 } { uint 255 } { str 256 } } } bare>
246 B{ 0x03 0x03 } T{ bare:union f { { int 0 } { uint 1 } { str 2 } } } bare>
247 ] [ invalid-union? ] must-fail-with
258 B{ 0xFF 0x01 0xFD 0x03 0x04 0x42 0x41 0x52 0x45 }
259 T{ struct f { { "foo" uint } { "bar" int } { "buzz" str } } } bare>
263 B{ 0xFF 0x01 0xFD 0x03 0x04 0x42 0x41 0x52 0x45 }
269 } T{ struct f { { "foo" uint } { "bar" int } { "buzz" str } } } >bare
272 ! user types / schema
275 type PublicKey data[128]
276 type Time str # ISO 8601
278 type Department enum {
284 # Reserved for the CEO
288 type Address list<str>[4] # street, city, state, country
290 type Customer struct {
294 orders: list<struct {
298 metadata: map<str><data>
301 type Employee struct {
305 department: Department
307 publicKey: optional<PublicKey>
308 metadata: map<str><data>
311 type TerminatedEmployee void
313 type Person union {Customer | Employee | TerminatedEmployee}
320 { "name" "James Smith" }
321 { "email" "jsmith@example.org" }
324 { "123 Main St" "Philadelphia" "PA" "United States" }
328 { V{ { "orderId" 4242424242 } { "quantity" 5 } } }
334 0x00 0x0b 0x4a 0x61 0x6d 0x65 0x73 0x20 0x53 0x6d 0x69
335 0x74 0x68 0x12 0x6a 0x73 0x6d 0x69 0x74 0x68 0x40 0x65
336 0x78 0x61 0x6d 0x70 0x6c 0x65 0x2e 0x6f 0x72 0x67 0x0b
337 0x31 0x32 0x33 0x20 0x4d 0x61 0x69 0x6e 0x20 0x53 0x74
338 0x0c 0x50 0x68 0x69 0x6c 0x61 0x64 0x65 0x6c 0x70 0x68
339 0x69 0x61 0x02 0x50 0x41 0x0d 0x55 0x6e 0x69 0x74 0x65
340 0x64 0x20 0x53 0x74 0x61 0x74 0x65 0x73 0x01 0xb2 0x41
341 0xde 0xfc 0x00 0x00 0x00 0x00 0x05 0x00 0x00 0x00 0x00
348 { "name" "Tiffany Doe" }
349 { "email" "tiffanyd@acme.corp" }
352 { "123 Main St" "Philadelphia" "PA" "United States" }
354 { "department" "ADMINISTRATION" }
355 { "hireDate" "2020-06-21T21:18:05Z" }
361 0x01 0x0b 0x54 0x69 0x66 0x66 0x61 0x6e 0x79 0x20 0x44
362 0x6f 0x65 0x12 0x74 0x69 0x66 0x66 0x61 0x6e 0x79 0x64
363 0x40 0x61 0x63 0x6d 0x65 0x2e 0x63 0x6f 0x72 0x70 0x0b
364 0x31 0x32 0x33 0x20 0x4d 0x61 0x69 0x6e 0x20 0x53 0x74
365 0x0c 0x50 0x68 0x69 0x6c 0x61 0x64 0x65 0x6c 0x70 0x68
366 0x69 0x61 0x02 0x50 0x41 0x0d 0x55 0x6e 0x69 0x74 0x65
367 0x64 0x20 0x53 0x74 0x61 0x74 0x65 0x73 0x01 0x14 0x32
368 0x30 0x32 0x30 0x2d 0x30 0x36 0x2d 0x32 0x31 0x54 0x32
369 0x31 0x3a 0x31 0x38 0x3a 0x30 0x35 0x5a 0x00 0x00
377 B{ 0x02 } Person bare>
382 [ "type Thing enum {}" parse-schema ] [ not-enough-entries? ] must-fail-with
383 [ "type Thing enum { }" parse-schema ] [ not-enough-entries? ] must-fail-with
385 "type Alphabet enum {
392 ] [ duplicate-keys? ] must-fail-with
395 "type Alphabet enum {
402 ] [ duplicate-values? ] must-fail-with
406 [ "type Foo data[0]" parse-schema ] [ invalid-length? ] must-fail-with
407 [ "type Foo data[18446744073709551616]" parse-schema ] [ invalid-length? ] must-fail-with
411 [ "type Foo optional<void>" parse-schema ] [ cannot-be-void? ] must-fail-with
415 [ "type Foo list<void>" parse-schema ] [ cannot-be-void? ] must-fail-with
416 [ "type Foo list<int>[0]" parse-schema ] [ invalid-length? ] must-fail-with
417 [ "type Foo list<int>[18446744073709551616]" parse-schema ] [ invalid-length? ] must-fail-with
421 [ "type Foo map<void><int>" parse-schema ] [ cannot-be-void? ] must-fail-with
422 [ "type Foo map<void><void>" parse-schema ] [ cannot-be-void? ] must-fail-with
423 [ "type Foo map<int><void>" parse-schema ] [ cannot-be-void? ] must-fail-with
427 [ "type Thing union {}" parse-schema ] [ not-enough-entries? ] must-fail-with
428 [ "type Thing union { }" parse-schema ] [ not-enough-entries? ] must-fail-with
429 [ "type Thing union {int=0|int|str=0}" parse-schema ] [ duplicate-keys? ] must-fail-with
430 [ "type Thing union {int=0|uint|str=0}" parse-schema ] [ duplicate-values? ] must-fail-with
434 [ "type Thing struct {}" parse-schema ] [ not-enough-entries? ] must-fail-with
435 [ "type Thing struct { }" parse-schema ] [ not-enough-entries? ] must-fail-with
436 [ "type Thing struct { a: int b: int a: int }" parse-schema ] [ duplicate-keys? ] must-fail-with
437 [ "type Thing struct { a: void }" parse-schema ] [ cannot-be-void? ] must-fail-with
441 [ "type Thing Other" parse-schema ] [ unknown-type? ] must-fail-with