docs: updates README to reflect new test LPEG platform and Lua 5.3.4 release
[luajson.git] / tests / test.lua
blobc5162f5cadb8ffb2046ad0818eedb7a0710d9d4c
1 -- Additional path that may be required
2 require("json")
4 local testStrings = {
5 [[{1:[1213.3e12, 123 , 123, "hello", [12, 2], {1:true /*test*/}]}]],
6 [[{"username":"demo1","message":null,"password":""}]],
7 [[{"challenge":"b64d-fnNQ6bRZ7CYiNIKwmdHoNgl9JR9MIYtzjBhpQzYXCFrgARt9mNmgUuO7FoODGr1NieT9yTeB2SLztGkvIA4NXmN9Bi27hqx1ybJIQq6S2L-AjQ3VTDClSmCsYFPOm9EMVZDZ0jhBX1fXw3o9VYj1j9KzSY5VCSAzGqYo-cBPY\n.b64","cert":"b64MIIGyjCCBbKgAwIBAgIKFAC1ZgAAAAAUYzANBgkqhkiG9w0BAQUFADBZMRUwEwYKCZImiZPyLGQBGRYFbG9tp8uQuFjWGS_KxTHXz9vkLNFjOoZY2bOwzsdEpshuYSdvX-9bRvHTQcoMNz8Q9nXG1aMl5x1nbV5byQNTCJlz4gzMJeNfeKGcipdCj7B6e_VpF-n2P-dFZizUHjxMksCVZ3nTr51x3Uw\n.b64","key":"D79B30BA7954DF520B44897A6FF58919"}]],
8 [[{"key":"D79B30BA7954DF520B44897A6FF58919"}]],
9 [[{"val":undefined}]],
10 [[{
11 "Image": {
12 "Width": 800,
13 "Height": 600,
14 "Title": "View from 15th Floor",
15 "Thumbnail": {
16 "Url": "http://www.example.com/image/481989943",
17 "Height": 125,
18 "Width": "100"
20 "IDs": [116, 943, 234, 38793]
22 }]],
23 [[ [
25 "precision": "zip",
26 "Latitude": 37.7668,
27 "Longitude": -122.3959,
28 "Address": "",
29 "City": "SAN FRANCISCO",
30 "State": "CA",
31 "Zip": "94107",
32 "Country": "US"
35 "precision": "zip",
36 "Latitude": 37.371991,
37 "Longitude": -122.026020,
38 "Address": "",
39 "City": "SUNNYVALE",
40 "State": "CA",
41 "Zip": "94085",
42 "Country": "US"
44 ] ]],
45 [[[null,true,[1,2,3],"hello\"],[world!"] ]],
46 [[ [{"0":"tan\\\\","model\\\\":"sedan"},{"0":"red","model":"sports"}] ]],
47 [[ {"1":"one","2":"two","5":"five"} ]],
48 [=[ [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] ]=]
51 for i, v in ipairs(testStrings) do
52 print("Testing: #" .. i)
53 local dec = json.decode(v)
54 json.util.printValue(dec, "JSONVALUE")
55 local reenc = json.encode(dec)
56 print("RE_ENC: ", reenc)
57 local redec = json.decode(reenc)
58 json.util.printValue(redec, "REDECJSONVALUE")
59 end
61 local testValues = {
62 {[300] = {nil, true, 1,2,3, nil, 3}}
65 for _, v in ipairs(testValues) do
66 local ret = json.encode(v)
67 print(ret)
68 local dec = json.decode(ret)
69 json.util.printValue(dec, "Encoded value")
70 print("Re-encoded", json.encode(dec))
71 end