Browse files

Test octect encode/decode separately

  • Loading branch information...
1 parent 5d61cfb commit eeebeda88e62fefa87c71d616d5719782bdaa45a @mpx committed May 7, 2011
Showing with 9 additions and 24 deletions.
  1. +1 −0 tests/bytestring.dat
  2. +8 −24 tests/test.lua
View
1 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��������������������������������������������������������������������������������������������������������������������������������"
View
32 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)

0 comments on commit eeebeda

Please sign in to comment.