Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpx/lua-cjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-05-07 21:16:27 +0400
committerMark Pulford <mark@kyne.com.au>2011-05-07 21:16:27 +0400
commiteeebeda88e62fefa87c71d616d5719782bdaa45a (patch)
treea87db97b33ba5f019e36aafd65e727eeac7e0ed0
parent5d61cfbaf7d5af7d32f84edbd68989bdd49b4519 (diff)
Test octect encode/decode separately
-rw-r--r--tests/bytestring.dat1
-rwxr-xr-xtests/test.lua32
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 = {
{ 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)