diff options
| author | ruki <[email protected]> | 2025-11-14 23:28:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-14 23:28:02 +0800 |
| commit | 31cab9106eeb43897e641ae80d5557d3b24c35f3 (patch) | |
| tree | 1fd2797edf71be1086074b18c5958072751138ef /tests/modules/json/test.lua | |
| parent | 1da60acf10492426338a6802b537589361e8c6b6 (diff) | |
add pretty support for json module
Diffstat (limited to 'tests/modules/json/test.lua')
| -rwxr-xr-x | tests/modules/json/test.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/modules/json/test.lua b/tests/modules/json/test.lua index a09f0918a..b2e53481b 100755 --- a/tests/modules/json/test.lua +++ b/tests/modules/json/test.lua @@ -38,6 +38,16 @@ function test_json_encode(t) t:are_equal(json_encode({1, "2", {a = 1}}), '[1,"2",{"a":1}]') t:are_equal(json_encode({1, "2", {b = true}}), '[1,"2",{"b":true}]') t:are_equal(json_encode(json.mark_as_array({1, 0xa, 0xdeadbeef, 0xffffffff, -1})), '[1,10,3735928559,4294967295,-1]') + local pretty_expected = table.concat({ + "{", + " \"name\": \"xmake\",", + " \"targets\": [", + " \"foo\",", + " \"bar\"", + " ]", + "}" + }, "\n") + t:are_equal(json_encode({name = "xmake", targets = {"foo", "bar"}}, {pretty = true, indent = 4}), pretty_expected) end function test_pure_json_decode(t) @@ -59,4 +69,14 @@ function test_pure_json_encode(t) t:are_equal(json_pure_encode({1, "2", {a = 1}}), '[1,"2",{"a":1}]') t:are_equal(json_pure_encode({1, "2", {b = true}}), '[1,"2",{"b":true}]') t:are_equal(json_pure_encode(json.mark_as_array({1, 0xa, 0xdeadbeef, 0xffffffff, -1})), '[1,10,3735928559,4294967295,-1]') + local pretty_expected = table.concat({ + "{", + " \"name\": \"xmake\",", + " \"targets\": [", + " \"foo\",", + " \"bar\"", + " ]", + "}" + }, "\n") + t:are_equal(json.encode({name = "xmake", targets = {"foo", "bar"}}, {pure = true, pretty = true, indent = 4}), pretty_expected) end |
