diff options
Diffstat (limited to '')
| -rwxr-xr-x | tests/test.lua | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/tests/test.lua b/tests/test.lua index bab2e94..9075bab 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -89,35 +89,19 @@ local encode_simple_tests = { | |||
| 89 | { json.encode, { "hello" }, true, { '"hello"' } }, | 89 | { json.encode, { "hello" }, true, { '"hello"' } }, |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | function test_ascii_sweep(min, max) | 92 | local function gen_ascii() |
| 93 | local function gen_ascii() | 93 | local chars = {} |
| 94 | local chars = {} | 94 | for i = 0, 255 do chars[i + 1] = string.char(i) end |
| 95 | for i = min, max do | 95 | return table.concat(chars) |
| 96 | chars[i + 1] = string.char(i) | ||
| 97 | end | ||
| 98 | return table.concat(chars) | ||
| 99 | end | ||
| 100 | |||
| 101 | local ascii_raw = gen_ascii() | ||
| 102 | local ascii_raw2 = json.decode(json.encode(ascii_raw)) | ||
| 103 | |||
| 104 | if ascii_raw == ascii_raw2 then | ||
| 105 | return "clean" | ||
| 106 | else | ||
| 107 | return "failed ascii sweep test" | ||
| 108 | end | ||
| 109 | end | 96 | end |
| 110 | 97 | ||
| 98 | local octets_raw = gen_ascii() | ||
| 99 | local octets_escaped = file_load("bytestring.dat") | ||
| 111 | local escape_tests = { | 100 | local escape_tests = { |
| 112 | { test_ascii_sweep, { 0, 255 }, true, { 'clean' } }, | 101 | { json.encode, { octets_raw }, true, { octets_escaped } }, |
| 102 | { json.decode, { octets_escaped }, true, { octets_raw } } | ||
| 113 | } | 103 | } |
| 114 | 104 | ||
| 115 | function test_decode_cycle(filename) | ||
| 116 | local obj1 = json.decode(file_load(filename)) | ||
| 117 | local obj2 = json.decode(json.encode(obj1)) | ||
| 118 | return compare_values(obj1, obj2) | ||
| 119 | end | ||
| 120 | |||
| 121 | run_test_group("decode simple value", simple_value_tests) | 105 | run_test_group("decode simple value", simple_value_tests) |
| 122 | run_test_group("decode numeric", numeric_tests) | 106 | run_test_group("decode numeric", numeric_tests) |
| 123 | 107 | ||
