1+ local qjson = require " qjson"
2+
3+ it (" should parse an array of numbers" , function ()
4+ expect (qjson .decode (" [1, 2, 3, 4]" )).toEqual ({ 1 , 2 , 3 , 4 })
5+ end )
6+
7+ it (" should parse an array of strings" , function ()
8+ expect (qjson .decode (" [\" Hello, \" , \" world!\" ]" )).toEqual ({ " Hello, " , " world!" })
9+ end )
10+
11+ it (" should parse an array of booleans" , function ()
12+ expect (qjson .decode (" [true, false]" )).toEqual ({ " true" , " false" })
13+ end )
14+
15+ it (" should parse an array of booleans into strings" , function ()
16+ expect (qjson .decode (" [true, false]" )).toEqual ({ " true" , " false" })
17+ end )
18+
19+ it (" should parse an array of null into strings" , function ()
20+ expect (qjson .decode (" [null, null]" )).toEqual ({ " null" , " null" })
21+ end )
22+
23+ it (" should parse an empty array" , function ()
24+ expect (qjson .decode (" []" )).toEqual ({})
25+ end )
26+
27+ it (" should not care about whitespace" , function ()
28+ expect (qjson .decode (" [ 1 , null ] " )).toEqual ({ 1 , " null" })
29+ end )
30+
31+ it (" should parse an object holding a string" , function ()
32+ expect (qjson .decode ([[ {"qux": "baz"}]] )).toEqual ({ qux = " baz" })
33+ end )
34+
35+ it (" should parse an object holding an integer" , function ()
36+ expect (qjson .decode ([[ { "hmm": 5 }]] )).toEqual ({ hmm = 5 })
37+ end )
38+
39+ it (" should parse an object holding a decimal number" , function ()
40+ expect (qjson .decode ([[ { "hmm": 5.2 }]] )).toEqual ({ hmm = 5.2 })
41+ end )
42+
43+ it (" should parse an object holding a negative integer" , function ()
44+ expect (qjson .decode ([[ { "hmm": -5 }]] )).toEqual ({ hmm = - 5 })
45+ end )
46+
47+ it (" should parse an object holding a negative decimal number" , function ()
48+ expect (qjson .decode ([[ { "hmm": -5.2 }]] )).toEqual ({ hmm = - 5.2 })
49+ end )
50+
51+ it (" should parse an object holding a negative decimal number with exponents" , function ()
52+ expect (qjson .decode ([[ { "hmm": -5.2e2 }]] )).toEqual ({ hmm = - 5.2e2 })
53+ end )
54+
55+ it (" should parse an object holding a positine decimal number with exponents 2" , function ()
56+ expect (qjson .decode ([[ { "hmm": 5.2E+2 }]] )).toEqual ({ hmm = 5.2E + 2 })
57+ end )
58+
59+ it (" should parse an object holding an array of numbers" , function ()
60+ expect (qjson .decode ([[ { "hmm": [ 1, 2, 3 ] }]] )).toEqual ({ hmm = { 1 , 2 , 3 } })
61+ end )
62+
63+ it (" should parse an object holding an empty object" , function ()
64+ expect (qjson .decode ([[ { "hmm": {} }]] )).toEqual ({ hmm = {} })
65+ end )
66+
67+ it (" should parse an object holding a list of empty objects" , function ()
68+ expect (qjson .decode ([[ { "hmm": [ {}, {}, {} ] }]] )).toEqual ({ hmm = { {}, {}, {} } })
69+ end )
70+
71+ it (" should parse an object holding a list of random values" , function ()
72+ expect (qjson .decode ([[ { "hmm": [ 1, {}, "test", true ] }]] )).toEqual ({ hmm = { 1 , {}, " test" , " true" } })
73+ end )
74+
75+ it (" should parse an object holding objects to five levels of depth" , function ()
76+ local json = [[
77+ {
78+ "foo": {
79+ "bar": {
80+ "baz": {
81+ "qux": {}
82+ }
83+ }
84+ }
85+ }
86+ ]]
87+
88+ expect (qjson .decode (json )).toEqual ({
89+ foo = {
90+ bar = {
91+ baz = {
92+ qux = {}
93+ }
94+ }
95+ }
96+ })
97+ end )
0 commit comments