| 1 | import json |
| 2 | |
| 3 | pub struct MyStruct[T] { |
| 4 | pub mut: |
| 5 | result ?T |
| 6 | id string |
| 7 | } |
| 8 | |
| 9 | fn test_gn_struct_string() ! { |
| 10 | a := MyStruct[string]{ |
| 11 | result: 'test' |
| 12 | id: 'some id' |
| 13 | } |
| 14 | |
| 15 | encoded_string := json.encode(a) |
| 16 | dump(encoded_string) |
| 17 | test := json.decode(MyStruct[string], encoded_string)! |
| 18 | dump(test) |
| 19 | assert a == test |
| 20 | } |
| 21 | |
| 22 | fn test_gn_struct_int() ! { |
| 23 | a := MyStruct[int]{ |
| 24 | result: 1 |
| 25 | id: 'some id' |
| 26 | } |
| 27 | |
| 28 | encoded_string := json.encode(a) |
| 29 | dump(encoded_string) |
| 30 | test := json.decode(MyStruct[int], encoded_string)! |
| 31 | dump(test) |
| 32 | assert a == test |
| 33 | } |
| 34 | |
| 35 | fn test_gn_struct_f64() ! { |
| 36 | a := MyStruct[f64]{ |
| 37 | result: 1.2 |
| 38 | id: 'some id' |
| 39 | } |
| 40 | |
| 41 | encoded_string := json.encode(a) |
| 42 | dump(encoded_string) |
| 43 | test := json.decode(MyStruct[f64], encoded_string)! |
| 44 | dump(test) |
| 45 | assert a == test |
| 46 | } |
| 47 | |