aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorskewb1k <skewb1kunix@gmail.com>2026-02-10 03:59:11 +0300
committerGitHub <noreply@github.com>2026-02-10 08:59:11 +0800
commitfed8c8356be4d94ceb55f2880bdb77fd9b55ef1e (patch)
tree07a6044110a57d509da45f99ae0a80054386abc7 /tests
parentea05d06f5a56d94d423fc697561a33ca3b8bf085 (diff)
downloadlua-cjson-fed8c8356be4d94ceb55f2880bdb77fd9b55ef1e.tar.gz
lua-cjson-fed8c8356be4d94ceb55f2880bdb77fd9b55ef1e.tar.bz2
lua-cjson-fed8c8356be4d94ceb55f2880bdb77fd9b55ef1e.zip
feature: add option to allow comments in decode.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua
index 0513d97..068a9f0 100755
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -333,6 +333,32 @@ local cjson_tests = {
333 json.decode, { [["\uDB00\uD"]] }, 333 json.decode, { [["\uDB00\uD"]] },
334 false, { "Expected value but found invalid unicode escape code at character 2" } }, 334 false, { "Expected value but found invalid unicode escape code at character 2" } },
335 335
336 -- Test comments
337 { 'Set decode_allow_comments(true)',
338 json.decode_allow_comments, { true }, true, { true } },
339 { "Decode single-line comment",
340 json.decode, { '{//comment\n}' }, true, { {} } },
341 { "Decode single-line comment with windows newline",
342 json.decode, { '{//comment\r\n}' }, true, { {} } },
343 { "Decode single-line comment after string value",
344 json.decode, { '"test // /* */ string"//comment' }, true, { "test // /* */ string" } },
345 { "Decode multi-line comment",
346 json.decode, { '{/* A multi-line\ncomment*/}' }, true, { {} } },
347 { "Decode multi-line comment before colon",
348 json.decode, { '{"a" /* Comment */: 1}' }, true, { { a = 1 } } },
349 { "Decode multi-line comment after colon",
350 json.decode, { '{"a": /* Comment */ 1}' }, true, { { a = 1 } } },
351 { "Decode multiple comments in a row",
352 json.decode, { '/*first*//*second*/{}' }, true, { {} } },
353 { "Decode unclosed multi-line comment [throw error]",
354 json.decode, { '{}/*Unclosed' },
355 false, { "Expected the end but found unclosed multi-line comment at character 13" } },
356 { "Decode comment inside number [throw error]",
357 json.decode, { '{"a":1/*x*/0}' },
358 false, { "Expected comma or object end but found T_INTEGER at character 12" } },
359 { 'Set decode_allow_comments(false)',
360 json.decode_allow_comments, { false }, true, { false } },
361
336 -- Test indenting 362 -- Test indenting
337 { 'Set encode_indent(" ")', 363 { 'Set encode_indent(" ")',
338 json.encode_indent, { " " }, true, { " " } }, 364 json.encode_indent, { " " }, true, { " " } },