diff options
-rwxr-xr-x | tests/decode.lua | 11 | ||||
-rwxr-xr-x | tests/encode.lua | 26 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/decode.lua b/tests/decode.lua new file mode 100755 index 0000000..c042168 --- /dev/null +++ b/tests/decode.lua | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/usr/bin/env lua | ||
2 | |||
3 | require "common" | ||
4 | require "cjson" | ||
5 | |||
6 | if not arg[1] then | ||
7 | print("usage: decode.lua FILE") | ||
8 | os.exit(-1) | ||
9 | end | ||
10 | |||
11 | print(serialise_value(cjson.decode(file_load(arg[1])))) | ||
diff --git a/tests/encode.lua b/tests/encode.lua new file mode 100755 index 0000000..e8026cc --- /dev/null +++ b/tests/encode.lua | |||
@@ -0,0 +1,26 @@ | |||
1 | #!/usr/bin/env lua | ||
2 | |||
3 | require "common" | ||
4 | require "cjson" | ||
5 | |||
6 | function get_lua_table(file) | ||
7 | local func = loadstring("data = " .. file_load(file)) | ||
8 | if func == nil then | ||
9 | error("Invalid syntax? Lua table required.") | ||
10 | end | ||
11 | |||
12 | local env = {} | ||
13 | func = setfenv(func, env) | ||
14 | func() | ||
15 | |||
16 | return env.data | ||
17 | end | ||
18 | |||
19 | if not arg[1] then | ||
20 | print("usage: encode.lua FILE") | ||
21 | os.exit(-1) | ||
22 | end | ||
23 | |||
24 | print(cjson.encode(get_lua_table(arg[1]))) | ||
25 | |||
26 | -- vi:ai et sw=4 ts=4: | ||