| 1 | import x.json2 |
| 2 | |
| 3 | struct TestStruct { |
| 4 | age u16 = 25 |
| 5 | } |
| 6 | |
| 7 | fn test_u16_in_struct() { |
| 8 | original := TestStruct{} |
| 9 | encoded := json2.encode(original) |
| 10 | println('Encoded: ${encoded}') |
| 11 | |
| 12 | decoded := json2.decode[TestStruct](encoded) or { panic('Failed to decode: ${err}') } |
| 13 | println('Decoded: ${decoded}') |
| 14 | println('Age value: ${decoded.age}') |
| 15 | |
| 16 | assert decoded.age == 25, 'Expected age 25, got ${decoded.age}' |
| 17 | } |
| 18 | |
| 19 | fn test_u16_direct() { |
| 20 | decoded := json2.decode[u16]('25') or { panic('Failed: ${err}') } |
| 21 | println('Direct u16 decode of "25": ${decoded}') |
| 22 | assert decoded == 25, 'Expected 25, got ${decoded}' |
| 23 | } |
| 24 | |
| 25 | fn main() { |
| 26 | test_u16_direct() |
| 27 | test_u16_in_struct() |
| 28 | println('All tests passed!') |
| 29 | } |
| 30 | |