diff options
author | Mark Pulford <mark@kyne.com.au> | 2011-05-08 02:46:27 +0930 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2011-05-08 02:46:27 +0930 |
commit | eeebeda88e62fefa87c71d616d5719782bdaa45a (patch) | |
tree | a87db97b33ba5f019e36aafd65e727eeac7e0ed0 | |
parent | 5d61cfbaf7d5af7d32f84edbd68989bdd49b4519 (diff) | |
download | lua-cjson-eeebeda88e62fefa87c71d616d5719782bdaa45a.tar.gz lua-cjson-eeebeda88e62fefa87c71d616d5719782bdaa45a.tar.bz2 lua-cjson-eeebeda88e62fefa87c71d616d5719782bdaa45a.zip |
Test octect encode/decode separately
-rw-r--r-- | tests/bytestring.dat | 1 | ||||
-rwxr-xr-x | tests/test.lua | 32 |
2 files changed, 9 insertions, 24 deletions
diff --git a/tests/bytestring.dat b/tests/bytestring.dat new file mode 100644 index 0000000..ee99a6b --- /dev/null +++ b/tests/bytestring.dat | |||
@@ -0,0 +1 @@ | |||
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-.\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007f" \ No newline at end of file | |||
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 | ||