aboutsummaryrefslogtreecommitdiff
path: root/tests/agentzh.t
diff options
context:
space:
mode:
Diffstat (limited to 'tests/agentzh.t')
-rw-r--r--tests/agentzh.t42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/agentzh.t b/tests/agentzh.t
index 552630a..88a94b8 100644
--- a/tests/agentzh.t
+++ b/tests/agentzh.t
@@ -332,3 +332,45 @@ Cannot serialise function: type not supported
332 332
333{"valid":"valid"} 333{"valid":"valid"}
334["one","two","three"] 334["one","two","three"]
335
336
337
338=== TEST 23: array-like proxy object with __len and __index
339--- lua
340local cjson = require "cjson"
341local real_array = {"foo", "bar", "baz"}
342local proxy_array = {}
343setmetatable(proxy_array, {
344 __len = function() return 3 end,
345 __index = function(t, k)
346 return real_array[k]
347 end,
348})
349
350print(cjson.encode(proxy_array))
351--- out
352["foo","bar","baz"]
353
354
355
356=== TEST 24: check that integers are handled correctly on Lua 5.3+
357--- lua
358local lv = tonumber((_VERSION):match("Lua 5%.([0-9]+)"))
359
360if lv >= 3 then
361 local cjson = require "cjson"
362 local array = cjson.decode [[ [10, 10.0, 3.5] ]]
363 for i = 1, 4 do
364 print(tostring(i) .. ": " .. tostring(math.type(array[i])))
365 end
366else
367 print("1: integer")
368 print("2: float")
369 print("3: float")
370 print("4: nil")
371end
372--- out
3731: integer
3742: float
3753: float
3764: nil