From dfdc124e27a22921eebcf208a499423e21b553b3 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 27 Apr 2024 18:26:14 -0700 Subject: [PATCH] tests: Add more coverage for table.concat corner cases --- tests/conformance/tables.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/conformance/tables.lua b/tests/conformance/tables.lua index 03b46396..c9f18240 100644 --- a/tests/conformance/tables.lua +++ b/tests/conformance/tables.lua @@ -412,6 +412,25 @@ do assert(table.find({[(1)] = true}, true) == 1) end +-- test table.concat +do + -- hash elements + local t = {} + t[123] = "a" + t[124] = "b" + + assert(table.concat(t) == "") + assert(table.concat(t, ",", 123, 124) == "a,b") + assert(table.concat(t, ",", 123, 123) == "a") + + -- numeric values + assert(table.concat({1, 2, 3}, ",") == "1,2,3") + assert(table.concat({"a", 2, "c"}, ",") == "a,2,c") + + -- out of bounds indices => element is nil => error + assert(pcall(table.concat, t, ",", 1, 100) == false) +end + -- test indexing with strings that have zeroes embedded in them do local t = {}