v2 / vlib / v / tests / serialisation / json_serialisation_of_fixed_arrays_test.v
46 lines · 43 sloc · 849 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1import json
2
3struct Abc {
4 my_ints [6]int
5 my_strs [2]string
6 my_arr []int
7}
8
9struct Fixed_Array {
10 abc [5]Abc
11}
12
13fn test_json_serialisation_of_fixed_arrays() {
14 a := Fixed_Array{[
15 Abc{
16 my_ints: [1, 2, 3, 4, 5, 6]!
17 my_strs: ['zzzddddddddddd', 'www']!
18 my_arr: [1, 2, 3]
19 },
20 Abc{
21 my_ints: [7, 8, 9, 10, 11, 12]!
22 my_strs: ['zzz', 'www']!
23 my_arr: [1, 2, 3]
24 },
25 Abc{
26 my_ints: [13, 14, 15, 16, 17, 18]!
27 my_strs: ['zzzaaaaaaaa', 'www111111112333']!
28 my_arr: [1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 5, 7, 1, 2, 3, 4, 5]
29 },
30 Abc{
31 my_ints: [19, 21, 23, 10, 50444, 3331]!
32 my_strs: ['zzz', 'www']!
33 my_arr: [1, 2, 3]
34 },
35 Abc{
36 my_ints: [20, 22, 24, 44, 560, 640]!
37 my_strs: ['zzz', 'www']!
38 my_arr: [1, 2, 3]
39 },
40 ]!}
41 s := json.encode(a)
42 dump(s)
43 b := json.decode(Fixed_Array, s)!
44 dump(b)
45 assert a == b
46}
47