]> gitweb.factorcode.org Git - factor.git/blob - basis/json/writer/writer-tests.factor
factor: rename [ ] [ ] unit-test -> { } [ ] unit-test using a refactoring tool!
[factor.git] / basis / json / writer / writer-tests.factor
1 USING: hashtables json.writer tools.test json.reader json kernel namespaces ;
2 IN: json.writer.tests
3
4 { "false" } [ f >json ] unit-test
5 { "true" } [ t >json ] unit-test
6 { "null" } [ json-null >json ] unit-test
7 { "0" } [ 0 >json ] unit-test
8 { "102" } [ 102 >json ] unit-test
9 { "-102" } [ -102 >json ] unit-test
10 { "102.0" } [ 102.0 >json ] unit-test
11 { "102.5" } [ 102.5 >json ] unit-test
12 { "0.5" } [ 1/2 >json ] unit-test
13 { """\"hello world\"""" } [ "hello world" >json ] unit-test
14
15 { "[1,\"two\",3.0]" } [ { 1 "two" 3.0 } >json ] unit-test
16 { """{"US$":1.0,"EU€":1.5}""" } [ H{ { "US$" 1.0 } { "EU€" 1.5 } } >json ] unit-test
17
18 { """">json"""" } [ \ >json >json ] unit-test
19
20 { { 0.5 } } [ { 1/2 } >json json> ] unit-test
21
22 TUPLE: person first-name age ;
23
24 { "{\"first-name\":\"David\",\"age\":32}" }
25 [
26     f json-friendly-keys?
27     [ "David" 32 person boa >json ]
28     with-variable
29 ] unit-test
30
31 { "{\"first_name\":\"David\",\"age\":32}" }
32 [
33     t json-friendly-keys?
34     [ "David" 32 person boa >json ]
35     with-variable
36 ] unit-test
37
38 { """{"1":2,"3":4}""" }
39 [ H{ { "1" 2 } { "3" 4 } } >json ] unit-test
40
41 { """{"1":2,"3":4}""" }
42 [ H{ { 1 2 } { 3 4 } } >json ] unit-test
43
44 { """{"":4}""" }
45 [ H{ { "" 2 } { "" 4 } } >json ] unit-test
46
47 { """{"true":4,"false":2,"":5}""" }
48 [ H{ { f 2 } { t 4 } { "" 5 } } >json ] unit-test
49
50 { """{"3.1":3}""" }
51 [ H{ { 3.1 3 } } >json ] unit-test
52
53 { """{"null":1}""" }
54 [ H{ { json-null 1 } } >json ] unit-test
55
56 { """{"Infinity":1}""" }
57 [ t json-allow-fp-special? [ H{ { 1/0. 1 } } >json ] with-variable ] unit-test
58
59 { """{"-Infinity":1}""" }
60 [ t json-allow-fp-special? [ H{ { -1/0. 1 } } >json ] with-variable ] unit-test
61
62 { """{"NaN":1}""" }
63 [ t json-allow-fp-special? [ H{ { NAN: 333 1 } } >json ] with-variable ] unit-test
64
65 {
66     "\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f\""
67 } [
68     "\0\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\e\x1c\x1d\x1e\x1f"
69     >json
70 ] unit-test
71
72 { "\"\\ud834\\udd1e\"" }
73 [ t json-escape-unicode? [ "𝄞" >json ] with-variable ] unit-test
74
75 { "\"\\ud800\\udc01\"" }
76 [ t json-escape-unicode? [ "𐀁" >json ] with-variable ] unit-test