diff options
| author | skewb1k <skewb1kunix@gmail.com> | 2026-01-19 08:51:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-19 08:51:57 +0800 |
| commit | ea05d06f5a56d94d423fc697561a33ca3b8bf085 (patch) | |
| tree | 48fbfc307052ed233b9ccf0b39ee569b3467d244 /tests/test.lua | |
| parent | 3c64e2247623a66347a48d66b6a791b58a71fdbe (diff) | |
| download | lua-cjson-ea05d06f5a56d94d423fc697561a33ca3b8bf085.tar.gz lua-cjson-ea05d06f5a56d94d423fc697561a33ca3b8bf085.tar.bz2 lua-cjson-ea05d06f5a56d94d423fc697561a33ca3b8bf085.zip | |
Diffstat (limited to '')
| -rwxr-xr-x | tests/test.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua index cf7a54a..0513d97 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -333,6 +333,44 @@ 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 indenting | ||
| 337 | { 'Set encode_indent(" ")', | ||
| 338 | json.encode_indent, { " " }, true, { " " } }, | ||
| 339 | { "Encode object with indenting", | ||
| 340 | json.encode, { { a = "a", b = "b" } }, | ||
| 341 | true, { | ||
| 342 | util.one_of { | ||
| 343 | '{\n "a": "a",\n "b": "b"\n}', | ||
| 344 | '{\n "b": "b",\n "a": "a"\n}', | ||
| 345 | } | ||
| 346 | } }, | ||
| 347 | { "Encode empty object with indenting", | ||
| 348 | json.encode, { { } }, true, { '{}' } }, | ||
| 349 | { "Encode nested object with indenting", | ||
| 350 | json.encode, { { a = { b = 1 } } }, | ||
| 351 | true, { '{\n "a": {\n "b": 1\n }\n}' } }, | ||
| 352 | { "Encode array with indenting", | ||
| 353 | json.encode, { { 1, 2, 3 } }, | ||
| 354 | true, { '[\n 1,\n 2,\n 3\n]' } }, | ||
| 355 | { "Encode empty array with indenting", | ||
| 356 | json.encode, { json.empty_array }, true, { '[]' } }, | ||
| 357 | { "Encode nested arrays with indenting", | ||
| 358 | json.encode, { { { 1, 2 }, { 3, 4 } } }, | ||
| 359 | true, { '[\n [\n 1,\n 2\n ],\n [\n 3,\n 4\n ]\n]' } }, | ||
| 360 | { "Encode array of objects with indenting", | ||
| 361 | json.encode, { { { a = "a" }, { b = "b" } } }, | ||
| 362 | true, { '[\n {\n "a": "a"\n },\n {\n "b": "b"\n }\n]' } }, | ||
| 363 | { 'Set encode_indent("abc")', | ||
| 364 | json.encode_indent, { "abc" }, true, { "abc" } }, | ||
| 365 | { "Encode object with non-whitespace indenting", | ||
| 366 | json.encode, { { a = { b = 1 } } }, | ||
| 367 | true, { '{\nabc"a": {\nabcabc"b": 1\nabc}\n}' } }, | ||
| 368 | { 'Set encode_indent("")', | ||
| 369 | json.encode_indent, { "" }, true, { "" } }, | ||
| 370 | { "Encode array of objects with empty indenting", | ||
| 371 | json.encode, { { { a = "a" }, { b = "b" } } }, | ||
| 372 | true, { '[{"a":"a"},{"b":"b"}]' } }, | ||
| 373 | |||
| 336 | -- Test locale support | 374 | -- Test locale support |
| 337 | -- | 375 | -- |
| 338 | -- The standard Lua interpreter is ANSI C online doesn't support locales | 376 | -- The standard Lua interpreter is ANSI C online doesn't support locales |
