Skip to content

Commit 9f9ee10

Browse files
committed
std/encoding/json: add decode test for numbers
1 parent 19483a2 commit 9f9ee10

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

std/encoding/json/decode_test.jule

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,49 @@ use "std/conv"
66
use "std/encoding"
77
use "std/strings"
88
use "std/testing"
9+
use "std/unsafe"
10+
11+
#test
12+
fn testDecodeNumber(t: &testing::T) {
13+
numbers := [
14+
"0",
15+
"1",
16+
"-1",
17+
"100",
18+
"-100",
19+
"0.5",
20+
"-0.5",
21+
"123.456",
22+
"-123.456",
23+
"1e3",
24+
"1E3",
25+
"1e+3",
26+
"1e-3",
27+
"-1e3",
28+
"-1E3",
29+
"-1e+3",
30+
"-1e-3",
31+
"1.23e4",
32+
"1.23E4",
33+
"1.23e+4",
34+
"1.23e-4",
35+
"-1.23e4",
36+
"-1.23E4",
37+
"-1.23e+4",
38+
"-1.23e-4",
39+
"0.0",
40+
"1.0",
41+
"2.0e5",
42+
"2.0E5",
43+
]
44+
for i, n in numbers {
45+
mut f := f64(0)
46+
Decode(unsafe::StrBytes(n), f) else {
47+
t.Errorf("#{} test failed", i)
48+
continue
49+
}
50+
}
51+
}
952

1053
#test
1154
fn testDecodeStr(t: &testing::T) {

0 commit comments

Comments
 (0)