From c92ecda53337490633c95e6ae00e322dc9ad1fb8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 10 Jun 2024 22:39:55 -0300 Subject: feature: Lua 5.3 + 5.4 integer support, with CI and conflicts fixed. Co-Authored-By: Hisham Muhammad Co-authored-by: Mark Pulford Co-authored-by: ichenq Co-authored-by: Cloud Wu Co-authored-by: caijietao Co-authored-by: actboy168 Co-authored-by: wudeng Co-authored-by: caiyiheng --- tests/agentzh.t | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/genutf8.pl | 1 + 2 files changed, 43 insertions(+) (limited to 'tests') 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 {"valid":"valid"} ["one","two","three"] + + + +=== TEST 23: array-like proxy object with __len and __index +--- lua +local cjson = require "cjson" +local real_array = {"foo", "bar", "baz"} +local proxy_array = {} +setmetatable(proxy_array, { + __len = function() return 3 end, + __index = function(t, k) + return real_array[k] + end, +}) + +print(cjson.encode(proxy_array)) +--- out +["foo","bar","baz"] + + + +=== TEST 24: check that integers are handled correctly on Lua 5.3+ +--- lua +local lv = tonumber((_VERSION):match("Lua 5%.([0-9]+)")) + +if lv >= 3 then + local cjson = require "cjson" + local array = cjson.decode [[ [10, 10.0, 3.5] ]] + for i = 1, 4 do + print(tostring(i) .. ": " .. tostring(math.type(array[i]))) + end +else + print("1: integer") + print("2: float") + print("3: float") + print("4: nil") +end +--- out +1: integer +2: float +3: float +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 @@ # cff03b039d850f370a7362f3313e5268 use strict; +no warnings 'nonchar'; # 0xD800 - 0xDFFF are used to encode supplementary codepoints # 0x10000 - 0x10FFFF are supplementary codepoints -- cgit v1.2.3-55-g6feb