@@ -102,6 +102,17 @@ function testJSON4Lua()
102
102
-- NB: This test can fail because of order: need to test further once
103
103
-- decoding is supported.
104
104
-- assert(r==[[{"age":35,"Name":"Craig","email":"[email protected] "}]])
105
+
106
+ -- Test encoding tables with numeric (string) indexes
107
+ s = {}
108
+ s [' 1' ]= ' One'
109
+ r = json .encode (s )
110
+ -- print("r = ", r)
111
+ assert (r == ' {"1":"One"}' )
112
+
113
+ s [' 2' ]= {One = ' Uno' }
114
+ r = json .encode (s )
115
+ assert (compareData (json .decode (r ), s ))
105
116
106
117
-- Test decode_scanWhitespace
107
118
if nil then
@@ -122,7 +133,6 @@ function testJSON4Lua()
122
133
s = [[ "Test\u00A7\\"]]
123
134
r ,e = json ._decode_scanString (s ,1 )
124
135
assert (r == " Test\xC2\xA7 \\ " and e == 9 )
125
- print (s ,r )
126
136
127
137
-- Test decode_scanNumber
128
138
s = [[ 354]]
@@ -165,14 +175,13 @@ function testJSON4Lua()
165
175
s = [[ "Test\u00A7\\\""]]
166
176
r ,e = json .decode (s )
167
177
assert (r == " Test\xC2\xA7 \\\" " , r )
168
- print (s ,r )
169
178
170
179
-- Test decode_scanObject
171
180
s = [[ {"one":1, "two":2, "three":"three", "four":true} ]]
172
181
r ,e = json .decode (s )
173
- for x ,y in pairs (r ) do
174
- print (x ,y )
175
- end
182
+ -- for x,y in pairs(r) do
183
+ -- print(x,y)
184
+ -- end
176
185
assert (compareData (r ,{one = 1 ,two = 2 ,three = ' three' ,four = true }))
177
186
s = [[ { "one" : { "first":1,"second":2,"third":3}, "two":2, "three":false } ]]
178
187
r ,e = json .decode (s )
@@ -198,6 +207,15 @@ function testJSON4Lua()
198
207
]]
199
208
r ,e = json .decode (s )
200
209
assert (r == ' test' ," Comment decoding failed" )
210
+
211
+ -- Per error reported by M.Hund, with incorrect decoding of string-numbered tables
212
+ s = {}
213
+ subt = {a = " a" ,b = " b" ,c = " c" }
214
+ s [' 1' ] = subt
215
+ s [' 2' ] = subt
216
+ s [' 3' ] = subt
217
+ r = json .decode (' {"1":{"a":"a","b":"b","c":"c"},"2":{"a":"a","b":"b","c":"c"},"3":{"a":"a","b":"b","c":"c"}}' )
218
+ assert (compareData (s , r ))
201
219
end
202
220
203
221
testJSON4Lua ()
0 commit comments