2022-11-19 12:52:17 +03:00
|
|
|
import x.json2
|
|
|
|
|
|
|
|
struct IntegerValues {
|
|
|
|
mut:
|
|
|
|
ux8 u8
|
|
|
|
ux16 u16
|
|
|
|
ux32 u32
|
|
|
|
ux64 u64
|
|
|
|
sx8 i8
|
|
|
|
sx16 i16
|
|
|
|
sx32 int
|
|
|
|
sx64 i64
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_all_primitive_integer_types_are_encodable_and_decodable() {
|
|
|
|
f := IntegerValues{1, 2, 3, 4, -1, -2, -3, -4}
|
2022-11-26 19:23:26 +03:00
|
|
|
s := json2.encode[IntegerValues](f)
|
2022-11-19 12:52:17 +03:00
|
|
|
assert s == '{"ux8":1,"ux16":2,"ux32":3,"ux64":4,"sx8":-1,"sx16":-2,"sx32":-3,"sx64":-4}'
|
2022-11-26 19:23:26 +03:00
|
|
|
x := json2.decode[IntegerValues](s)!
|
2022-11-19 12:52:17 +03:00
|
|
|
assert x == f
|
|
|
|
println('done')
|
|
|
|
}
|