v2 / vlib / x / json2 / tests / decode_float_to_64bit_integer_test.v
21 lines · 18 sloc · 697 bytes · c6fc4daa96392f862a3a5b0a40b22caca924e68e
Raw
1import json as old_json
2import x.json2 as json
3
4struct Legacy64BitNumbers {
5 signed i64
6 unsigned u64
7}
8
9fn test_decode_float_numbers_into_64bit_integer_fields_matches_json_module() {
10 payload := '{"signed": -1756811041916.0, "unsigned": 1756811041916.0}'
11 expected := old_json.decode(Legacy64BitNumbers, payload)!
12 actual := json.decode[Legacy64BitNumbers](payload)!
13 assert actual == expected
14}
15
16fn test_decode_float_strings_into_64bit_integer_fields_in_default_mode() {
17 payload := '{"signed": "-1756811041916.0", "unsigned": "1756811041916.0"}'
18 actual := json.decode[Legacy64BitNumbers](payload)!
19 assert actual.signed == i64(-1756811041916)
20 assert actual.unsigned == u64(1756811041916)
21}
22