diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/agentzh.t | 42 | ||||
-rwxr-xr-x | tests/genutf8.pl | 1 |
2 files changed, 43 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 | ||
340 | local cjson = require "cjson" | ||
341 | local real_array = {"foo", "bar", "baz"} | ||
342 | local proxy_array = {} | ||
343 | setmetatable(proxy_array, { | ||
344 | __len = function() return 3 end, | ||
345 | __index = function(t, k) | ||
346 | return real_array[k] | ||
347 | end, | ||
348 | }) | ||
349 | |||
350 | print(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 | ||
358 | local lv = tonumber((_VERSION):match("Lua 5%.([0-9]+)")) | ||
359 | |||
360 | if 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 | ||
366 | else | ||
367 | print("1: integer") | ||
368 | print("2: float") | ||
369 | print("3: float") | ||
370 | print("4: nil") | ||
371 | end | ||
372 | --- out | ||
373 | 1: integer | ||
374 | 2: float | ||
375 | 3: float | ||
376 | 4: nil | ||
diff --git a/tests/genutf8.pl b/tests/genutf8.pl index db661a1..c79f238 100755 --- a/tests/genutf8.pl +++ b/tests/genutf8.pl | |||
@@ -6,6 +6,7 @@ | |||
6 | # cff03b039d850f370a7362f3313e5268 | 6 | # cff03b039d850f370a7362f3313e5268 |
7 | 7 | ||
8 | use strict; | 8 | use strict; |
9 | no warnings 'nonchar'; | ||
9 | 10 | ||
10 | # 0xD800 - 0xDFFF are used to encode supplementary codepoints | 11 | # 0xD800 - 0xDFFF are used to encode supplementary codepoints |
11 | # 0x10000 - 0x10FFFF are supplementary codepoints | 12 | # 0x10000 - 0x10FFFF are supplementary codepoints |