v2 / vlib / x / json2 / tests / scientific_notation_integer_test.v
23 lines · 19 sloc · 603 bytes · e16dec113a688530fd2d9cc57f13386f9cf8adb8
Raw
1import x.json2
2
3struct ScientificI64Value {
4 size i64
5}
6
7fn test_decode_i64_from_scientific_notation_number() {
8 decoded := json2.decode[ScientificI64Value]('{"size":1.7596215426069998e+12}')!
9 assert decoded.size == i64(1.7596215426069998e+12)
10}
11
12fn test_decode_i64_from_scientific_notation_string() {
13 decoded := json2.decode[ScientificI64Value]('{"size":"1.7596215426069998e+12"}')!
14 assert decoded.size == i64(1.7596215426069998e+12)
15}
16
17fn test_decode_i64_from_plain_fraction_still_fails() {
18 if _ := json2.decode[ScientificI64Value]('{"size":123.45}') {
19 assert false
20 } else {
21 assert true
22 }
23}
24