From eeebeda88e62fefa87c71d616d5719782bdaa45a Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Sun, 8 May 2011 02:46:27 +0930 Subject: Test octect encode/decode separately --- tests/bytestring.dat | 1 + tests/test.lua | 32 ++++++++------------------------ 2 files changed, 9 insertions(+), 24 deletions(-) create mode 100644 tests/bytestring.dat 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 = { { json.encode, { "hello" }, true, { '"hello"' } }, } -function test_ascii_sweep(min, max) - local function gen_ascii() - local chars = {} - for i = min, max do - chars[i + 1] = string.char(i) - end - return table.concat(chars) - end - - local ascii_raw = gen_ascii() - local ascii_raw2 = json.decode(json.encode(ascii_raw)) - - if ascii_raw == ascii_raw2 then - return "clean" - else - return "failed ascii sweep test" - end +local function gen_ascii() + local chars = {} + for i = 0, 255 do chars[i + 1] = string.char(i) end + return table.concat(chars) end +local octets_raw = gen_ascii() +local octets_escaped = file_load("bytestring.dat") local escape_tests = { - { test_ascii_sweep, { 0, 255 }, true, { 'clean' } }, + { json.encode, { octets_raw }, true, { octets_escaped } }, + { json.decode, { octets_escaped }, true, { octets_raw } } } -function test_decode_cycle(filename) - local obj1 = json.decode(file_load(filename)) - local obj2 = json.decode(json.encode(obj1)) - return compare_values(obj1, obj2) -end - run_test_group("decode simple value", simple_value_tests) run_test_group("decode numeric", numeric_tests) -- cgit v1.2.3