]> gitweb.factorcode.org Git - factor.git/blob - basis/json/reader/reader-tests.factor
use radix literals
[factor.git] / basis / json / reader / reader-tests.factor
1 USING: assocs arrays json.reader kernel strings tools.test
2 hashtables json io.streams.string ;
3 IN: json.reader.tests
4
5 { f } [ "false" json> ] unit-test
6 { t } [ "true" json> ] unit-test
7 { json-null } [ "null" json> ] unit-test
8 { 0 } [ "0" json> ] unit-test
9 { 102 } [ "102" json> ] unit-test
10 { -102 } [ "-102" json> ] unit-test
11 { 102 } [ "+102" json> ] unit-test
12 { 1000.0 } [ "1.0e3" json> ] unit-test
13 { 1000.0 } [ "10e2" json> ] unit-test
14 { 102.0 } [ "102.0" json> ] unit-test
15 { 102.5 } [ "102.5" json> ] unit-test
16 { 102.5 } [ "102.50" json> ] unit-test
17 { -10250.0 } [ "-102.5e2" json> ] unit-test
18 { -10250.0 } [ "-102.5E+2" json> ] unit-test
19 { 10.25 } [ "1025e-2" json> ] unit-test
20 { 0.125 } [ "0.125" json> ] unit-test
21 { -0.125 } [ "-0.125" json> ] unit-test
22 { -0.00125 } [ "-0.125e-2" json> ] unit-test
23 { -012.5 } [ "-0.125e+2" json> ] unit-test
24
25 ! not widely supported by javascript, but allowed in the grammar, and a nice
26 ! feature to get
27 { -0.0 } [ "-0.0" json> ] unit-test
28
29 { " fuzzy  pickles " } [ """  " fuzzy  pickles " """  json> ] unit-test
30 { "while 1:\n\tpass" } [ """  "while 1:\n\tpass" """  json> ] unit-test
31 ! unicode is allowed in json
32 { "ß∂¬ƒ˚∆" } [ """  "ß∂¬ƒ˚∆""""  json> ] unit-test
33 { 8 9 10 12 13 34 47 92 } >string 1array [ """ "\\b\\t\\n\\f\\r\\"\\/\\\\" """ json> ] unit-test
34 { 0xabcd } >string 1array [ """ "\\uaBCd" """ json> ] unit-test
35
36 { H{ { "a" { } } { "b" 123 } } } [ "{\"a\":[],\"b\":123}" json> ] unit-test
37 { { } } [ "[]" json> ] unit-test 
38 { { 1 "two" 3.0 } } [ """ [1, "two", 3.0] """ json> ] unit-test
39 { H{ } } [ "{}" json> ] unit-test
40
41 ! the returned hashtable should be different every time
42 { H{ } } [ "key" "value" "{}" json> ?set-at "{}" json> nip ] unit-test
43
44 { H{ { "US$" 1.0 } { "EU€" 1.5 } } } [ """ { "US$":1.00, "EU\\u20AC":1.50 } """ json> ] unit-test
45 { H{
46     { "fib" { 1 1 2 3 5 8 H{ { "etc" "etc" } } } }
47     { "prime" { 2 3 5 7 11 13 } }
48 } } [ """ {
49     "fib": [1, 1,  2,   3,     5,         8,
50         { "etc":"etc" } ],
51     "prime":
52     [ 2,3,     5,7,
53 11,
54 13
55 ]      }
56 """ json> ] unit-test
57
58 { 0 } [ "      0" json> ] unit-test
59 { 0 } [ "0      " json> ] unit-test
60 { 0 } [ "   0   " json> ] unit-test
61
62 { V{ H{ { "a" "b" } } H{ { "c" "d" } } } }
63 [ """{"a": "b"} {"c": "d"}""" [ read-jsons ] with-string-reader ] unit-test
64
65 ! empty objects are allowed as values in objects
66 { H{ { "foo" H{ } } } } [ "{ \"foo\" : {}}" json> ] unit-test