mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Remove unused test files for lua-cjson
This commit is contained in:
parent
b698363c34
commit
0e4f948eb5
17 changed files with 0 additions and 1360 deletions
4
src/deps/src/lua-cjson/tests/README
vendored
4
src/deps/src/lua-cjson/tests/README
vendored
|
|
@ -1,4 +0,0 @@
|
|||
These JSON examples were taken from the JSON website
|
||||
(http://json.org/example.html) and RFC 4627.
|
||||
|
||||
Used with permission.
|
||||
72
src/deps/src/lua-cjson/tests/TestLua.pm
vendored
72
src/deps/src/lua-cjson/tests/TestLua.pm
vendored
|
|
@ -1,72 +0,0 @@
|
|||
package TestLua;
|
||||
|
||||
use Test::Base -Base;
|
||||
use IPC::Run3;
|
||||
use Cwd;
|
||||
|
||||
use Test::LongString;
|
||||
|
||||
our @EXPORT = qw( run_tests );
|
||||
|
||||
$ENV{LUA_CPATH} = "../?.so;;";
|
||||
$ENV{LUA_PATH} = "../lua/?.lua;;";
|
||||
#$ENV{LUA_PATH} = ($ENV{LUA_PATH} || "" ) . ';' . getcwd . "/runtime/?.lua" . ';;';
|
||||
|
||||
sub run_test ($) {
|
||||
my $block = shift;
|
||||
#print $json_xs->pretty->encode(\@new_rows);
|
||||
#my $res = #print $json_xs->pretty->encode($res);
|
||||
my $name = $block->name;
|
||||
|
||||
my $lua = $block->lua or
|
||||
die "No --- lua specified for test $name\n";
|
||||
|
||||
my $luafile = "test_case.lua";
|
||||
|
||||
open my $fh, ">$luafile" or
|
||||
die "Cannot open $luafile for writing: $!\n";
|
||||
|
||||
print $fh $lua;
|
||||
close $fh;
|
||||
|
||||
my ($res, $err);
|
||||
|
||||
my @cmd;
|
||||
my $lua_bin = $ENV{LUA_BIN} || "luajit";
|
||||
|
||||
if ($ENV{TEST_LUA_USE_VALGRIND}) {
|
||||
warn "$name\n";
|
||||
@cmd = ('valgrind', '-q', '--leak-check=full', $lua_bin, 'test_case.lua');
|
||||
} else {
|
||||
@cmd = ($lua_bin, 'test_case.lua');
|
||||
}
|
||||
|
||||
run3 \@cmd, undef, \$res, \$err;
|
||||
my $rc = $?;
|
||||
|
||||
#warn "res:$res\nerr:$err\n";
|
||||
|
||||
if (defined $block->err) {
|
||||
$err =~ /.*:.*:.*: (.*\s)?/;
|
||||
$err = $1;
|
||||
is $err, $block->err, "$name - err expected";
|
||||
|
||||
} elsif ($rc) {
|
||||
die "Failed to execute --- lua for test $name: $err\n";
|
||||
|
||||
} else {
|
||||
#is $res, $block->out, "$name - output ok";
|
||||
is $res, $block->out, "$name - output ok";
|
||||
}
|
||||
|
||||
is $rc, ($block->exit || 0), "$name - exit code ok";
|
||||
#unlink 'test_case.lua' or warn "could not delete \'test_case.lua\':$!";
|
||||
}
|
||||
|
||||
sub run_tests () {
|
||||
for my $block (blocks()) {
|
||||
run_test($block);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
376
src/deps/src/lua-cjson/tests/agentzh.t
vendored
376
src/deps/src/lua-cjson/tests/agentzh.t
vendored
|
|
@ -1,376 +0,0 @@
|
|||
# vim:ft=
|
||||
|
||||
use lib '.';
|
||||
use TestLua;
|
||||
|
||||
plan tests => 2 * blocks();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: empty tables as objects
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
print(cjson.encode({}))
|
||||
print(cjson.encode({dogs = {}}))
|
||||
--- out
|
||||
{}
|
||||
{"dogs":{}}
|
||||
|
||||
|
||||
|
||||
=== TEST 2: empty tables as arrays
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
cjson.encode_empty_table_as_object(false)
|
||||
print(cjson.encode({}))
|
||||
print(cjson.encode({dogs = {}}))
|
||||
--- out
|
||||
[]
|
||||
{"dogs":[]}
|
||||
|
||||
|
||||
|
||||
=== TEST 3: empty tables as objects (explicit)
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
cjson.encode_empty_table_as_object(true)
|
||||
print(cjson.encode({}))
|
||||
print(cjson.encode({dogs = {}}))
|
||||
--- out
|
||||
{}
|
||||
{"dogs":{}}
|
||||
|
||||
|
||||
|
||||
=== TEST 4: empty_array userdata
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
print(cjson.encode({arr = cjson.empty_array}))
|
||||
--- out
|
||||
{"arr":[]}
|
||||
|
||||
|
||||
|
||||
=== TEST 5: empty_array_mt
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local empty_arr = setmetatable({}, cjson.empty_array_mt)
|
||||
print(cjson.encode({arr = empty_arr}))
|
||||
--- out
|
||||
{"arr":[]}
|
||||
|
||||
|
||||
|
||||
=== TEST 6: empty_array_mt and empty tables as objects (explicit)
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local sort_json = require "tests.sort_json"
|
||||
local empty_arr = setmetatable({}, cjson.empty_array_mt)
|
||||
print(sort_json(cjson.encode({obj = {}, arr = empty_arr})))
|
||||
--- out
|
||||
{"arr":[],"obj":{}}
|
||||
|
||||
|
||||
|
||||
=== TEST 7: empty_array_mt and empty tables as objects (explicit)
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local sort_json = require "tests.sort_json"
|
||||
cjson.encode_empty_table_as_object(true)
|
||||
local empty_arr = setmetatable({}, cjson.empty_array_mt)
|
||||
local data = {
|
||||
arr = empty_arr,
|
||||
foo = {
|
||||
obj = {},
|
||||
foobar = {
|
||||
arr = cjson.empty_array,
|
||||
obj = {}
|
||||
}
|
||||
}
|
||||
}
|
||||
print(sort_json(cjson.encode(data)))
|
||||
--- out
|
||||
{"arr":[],"foo":{"foobar":{"arr":[],"obj":{}},"obj":{}}}
|
||||
|
||||
|
||||
|
||||
=== TEST 8: empty_array_mt on non-empty tables
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local sort_json = require "tests.sort_json"
|
||||
cjson.encode_empty_table_as_object(true)
|
||||
local array = {"hello", "world", "lua"}
|
||||
setmetatable(array, cjson.empty_array_mt)
|
||||
local data = {
|
||||
arr = array,
|
||||
foo = {
|
||||
obj = {},
|
||||
foobar = {
|
||||
arr = cjson.empty_array,
|
||||
obj = {}
|
||||
}
|
||||
}
|
||||
}
|
||||
print(sort_json(cjson.encode(data)))
|
||||
--- out
|
||||
{"arr":["hello","world","lua"],"foo":{"foobar":{"arr":[],"obj":{}},"obj":{}}}
|
||||
|
||||
|
||||
|
||||
=== TEST 9: array_mt on empty tables
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local data = {}
|
||||
setmetatable(data, cjson.array_mt)
|
||||
print(cjson.encode(data))
|
||||
--- out
|
||||
[]
|
||||
|
||||
|
||||
|
||||
=== TEST 10: array_mt on non-empty tables
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local data = { "foo", "bar" }
|
||||
setmetatable(data, cjson.array_mt)
|
||||
print(cjson.encode(data))
|
||||
--- out
|
||||
["foo","bar"]
|
||||
|
||||
|
||||
|
||||
=== TEST 11: array_mt on non-empty tables with holes
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local data = {}
|
||||
data[1] = "foo"
|
||||
data[2] = "bar"
|
||||
data[4] = "last"
|
||||
data[9] = "none"
|
||||
setmetatable(data, cjson.array_mt)
|
||||
print(cjson.encode(data))
|
||||
--- out
|
||||
["foo","bar",null,"last"]
|
||||
|
||||
|
||||
|
||||
=== TEST 12: decode() by default does not set array_mt on empty arrays
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local json = [[{"my_array":[]}]]
|
||||
local t = cjson.decode(json)
|
||||
local has_metatable = getmetatable(t.my_array) == cjson.array_mt
|
||||
print("decoded JSON array has metatable: " .. tostring(has_metatable))
|
||||
print(cjson.encode(t))
|
||||
--- out
|
||||
decoded JSON array has metatable: false
|
||||
{"my_array":{}}
|
||||
|
||||
|
||||
|
||||
=== TEST 13: decode() sets array_mt on non-empty arrays if enabled
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
cjson.decode_array_with_array_mt(true)
|
||||
local json = [[{"my_array":["hello","world"]}]]
|
||||
local t = cjson.decode(json)
|
||||
t.my_array.hash_value = "adding a hash value"
|
||||
-- emptying the array part
|
||||
t.my_array[1] = nil
|
||||
t.my_array[2] = nil
|
||||
local has_metatable = getmetatable(t.my_array) == cjson.array_mt
|
||||
print("decoded JSON array has metatable: " .. tostring(has_metatable))
|
||||
print(cjson.encode(t))
|
||||
--- out
|
||||
decoded JSON array has metatable: true
|
||||
{"my_array":[]}
|
||||
|
||||
|
||||
|
||||
=== TEST 14: cfg can enable/disable setting array_mt
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
cjson.decode_array_with_array_mt(true)
|
||||
cjson.decode_array_with_array_mt(false)
|
||||
local json = [[{"my_array":[]}]]
|
||||
local t = cjson.decode(json)
|
||||
local has_metatable = getmetatable(t.my_array) == cjson.array_mt
|
||||
print("decoded JSON array has metatable: " .. tostring(has_metatable))
|
||||
print(cjson.encode(t))
|
||||
--- out
|
||||
decoded JSON array has metatable: false
|
||||
{"my_array":{}}
|
||||
|
||||
|
||||
|
||||
=== TEST 15: array_mt on tables with hash part
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local data
|
||||
|
||||
if jit and string.find(jit.version, "LuaJIT 2.1.0", nil, true) then
|
||||
local new_tab = require "table.new"
|
||||
data = new_tab(0, 2) -- allocating hash part only
|
||||
|
||||
else
|
||||
data = {}
|
||||
end
|
||||
|
||||
data.foo = "bar"
|
||||
data[1] = "hello"
|
||||
setmetatable(data, cjson.array_mt)
|
||||
print(cjson.encode(data))
|
||||
--- out
|
||||
["hello"]
|
||||
|
||||
|
||||
|
||||
=== TEST 16: multiple calls to lua_cjson_new (1/3)
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
package.loaded["cjson"] = nil
|
||||
require "cjson"
|
||||
local arr = setmetatable({}, cjson.array_mt)
|
||||
print(cjson.encode(arr))
|
||||
--- out
|
||||
[]
|
||||
|
||||
|
||||
|
||||
=== TEST 17: multiple calls to lua_cjson_new (2/3)
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
package.loaded["cjson"] = nil
|
||||
require "cjson"
|
||||
local arr = setmetatable({}, cjson.empty_array_mt)
|
||||
print(cjson.encode(arr))
|
||||
--- out
|
||||
[]
|
||||
|
||||
|
||||
|
||||
=== TEST 18: multiple calls to lua_cjson_new (3/3)
|
||||
--- lua
|
||||
local cjson = require "cjson.safe"
|
||||
-- load another cjson instance (not in package.loaded)
|
||||
require "cjson"
|
||||
local arr = setmetatable({}, cjson.empty_array_mt)
|
||||
print(cjson.encode(arr))
|
||||
--- out
|
||||
[]
|
||||
|
||||
|
||||
|
||||
=== TEST 19: & in JSON
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local a="[\"a=1&b=2\"]"
|
||||
local b=cjson.decode(a)
|
||||
print(cjson.encode(b))
|
||||
--- out
|
||||
["a=1&b=2"]
|
||||
|
||||
|
||||
|
||||
=== TEST 20: default and max precision
|
||||
--- lua
|
||||
local math = require "math"
|
||||
local cjson = require "cjson"
|
||||
local double = math.pow(2, 53)
|
||||
print(cjson.encode(double))
|
||||
cjson.encode_number_precision(16)
|
||||
print(cjson.encode(double))
|
||||
print(string.format("%16.0f", cjson.decode("9007199254740992")))
|
||||
--- out
|
||||
9.007199254741e+15
|
||||
9007199254740992
|
||||
9007199254740992
|
||||
|
||||
|
||||
|
||||
=== TEST 21: / in string
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local a={test = "http://google.com/google"}
|
||||
local b=cjson.encode(a)
|
||||
print(b)
|
||||
cjson.encode_escape_forward_slash(false)
|
||||
local b=cjson.encode(a)
|
||||
print(b)
|
||||
cjson.encode_escape_forward_slash(true)
|
||||
local b=cjson.encode(a)
|
||||
print(b)
|
||||
--- out
|
||||
{"test":"http:\/\/google.com\/google"}
|
||||
{"test":"http://google.com/google"}
|
||||
{"test":"http:\/\/google.com\/google"}
|
||||
|
||||
|
||||
|
||||
=== TEST 22: disable error on invalid type
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local f = function (x) return 2*x end
|
||||
local res, err = pcall(cjson.encode, f)
|
||||
print(err)
|
||||
local t = {f = f, valid = "valid"}
|
||||
local res, err = pcall(cjson.encode, t)
|
||||
print(err)
|
||||
local arr = {"one", "two", f, "three"}
|
||||
local res, err = pcall(cjson.encode, arr)
|
||||
print(err)
|
||||
cjson.encode_skip_unsupported_value_types(true)
|
||||
print(cjson.encode(f))
|
||||
print(cjson.encode(t))
|
||||
print(cjson.encode(arr))
|
||||
--- out
|
||||
Cannot serialise function: type not supported
|
||||
Cannot serialise function: type not supported
|
||||
Cannot serialise function: type not supported
|
||||
|
||||
{"valid":"valid"}
|
||||
["one","two","three"]
|
||||
|
||||
|
||||
|
||||
=== TEST 23: array-like proxy object with __len and __index
|
||||
--- lua
|
||||
local cjson = require "cjson"
|
||||
local real_array = {"foo", "bar", "baz"}
|
||||
local proxy_array = {}
|
||||
setmetatable(proxy_array, {
|
||||
__len = function() return 3 end,
|
||||
__index = function(t, k)
|
||||
return real_array[k]
|
||||
end,
|
||||
})
|
||||
|
||||
print(cjson.encode(proxy_array))
|
||||
--- out
|
||||
["foo","bar","baz"]
|
||||
|
||||
|
||||
|
||||
=== TEST 24: check that integers are handled correctly on Lua 5.3+
|
||||
--- lua
|
||||
local lv = tonumber((_VERSION):match("Lua 5%.([0-9]+)"))
|
||||
|
||||
if lv >= 3 then
|
||||
local cjson = require "cjson"
|
||||
local array = cjson.decode [[ [10, 10.0, 3.5] ]]
|
||||
for i = 1, 4 do
|
||||
print(tostring(i) .. ": " .. tostring(math.type(array[i])))
|
||||
end
|
||||
else
|
||||
print("1: integer")
|
||||
print("2: float")
|
||||
print("3: float")
|
||||
print("4: nil")
|
||||
end
|
||||
--- out
|
||||
1: integer
|
||||
2: float
|
||||
3: float
|
||||
4: nil
|
||||
131
src/deps/src/lua-cjson/tests/bench.lua
vendored
131
src/deps/src/lua-cjson/tests/bench.lua
vendored
|
|
@ -1,131 +0,0 @@
|
|||
#!/usr/bin/env lua
|
||||
|
||||
-- This benchmark script measures wall clock time and should be
|
||||
-- run on an unloaded system.
|
||||
--
|
||||
-- Your Mileage May Vary.
|
||||
--
|
||||
-- Mark Pulford <mark@kyne.com.au>
|
||||
|
||||
local json_module = os.getenv("JSON_MODULE") or "cjson"
|
||||
|
||||
require "socket"
|
||||
local json = require(json_module)
|
||||
local util = require "cjson.util"
|
||||
|
||||
local function find_func(mod, funcnames)
|
||||
for _, v in ipairs(funcnames) do
|
||||
if mod[v] then
|
||||
return mod[v]
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
local json_encode = find_func(json, { "encode", "Encode", "to_string", "stringify", "json" })
|
||||
local json_decode = find_func(json, { "decode", "Decode", "to_value", "parse" })
|
||||
|
||||
local function average(t)
|
||||
local total = 0
|
||||
for _, v in ipairs(t) do
|
||||
total = total + v
|
||||
end
|
||||
return total / #t
|
||||
end
|
||||
|
||||
function benchmark(tests, seconds, rep)
|
||||
local function bench(func, iter)
|
||||
-- Use socket.gettime() to measure microsecond resolution
|
||||
-- wall clock time.
|
||||
local t = socket.gettime()
|
||||
for i = 1, iter do
|
||||
func(i)
|
||||
end
|
||||
t = socket.gettime() - t
|
||||
|
||||
-- Don't trust any results when the run lasted for less than a
|
||||
-- millisecond - return nil.
|
||||
if t < 0.001 then
|
||||
return nil
|
||||
end
|
||||
|
||||
return (iter / t)
|
||||
end
|
||||
|
||||
-- Roughly calculate the number of interations required
|
||||
-- to obtain a particular time period.
|
||||
local function calc_iter(func, seconds)
|
||||
local iter = 1
|
||||
local rate
|
||||
-- Warm up the bench function first.
|
||||
func()
|
||||
while not rate do
|
||||
rate = bench(func, iter)
|
||||
iter = iter * 10
|
||||
end
|
||||
return math.ceil(seconds * rate)
|
||||
end
|
||||
|
||||
local test_results = {}
|
||||
for name, func in pairs(tests) do
|
||||
-- k(number), v(string)
|
||||
-- k(string), v(function)
|
||||
-- k(number), v(function)
|
||||
if type(func) == "string" then
|
||||
name = func
|
||||
func = _G[name]
|
||||
end
|
||||
|
||||
local iter = calc_iter(func, seconds)
|
||||
|
||||
local result = {}
|
||||
for i = 1, rep do
|
||||
result[i] = bench(func, iter)
|
||||
end
|
||||
|
||||
-- Remove the slowest half (round down) of the result set
|
||||
table.sort(result)
|
||||
for i = 1, math.floor(#result / 2) do
|
||||
table.remove(result, 1)
|
||||
end
|
||||
|
||||
test_results[name] = average(result)
|
||||
end
|
||||
|
||||
return test_results
|
||||
end
|
||||
|
||||
function bench_file(filename)
|
||||
local data_json = util.file_load(filename)
|
||||
local data_obj = json_decode(data_json)
|
||||
|
||||
local function test_encode()
|
||||
json_encode(data_obj)
|
||||
end
|
||||
local function test_decode()
|
||||
json_decode(data_json)
|
||||
end
|
||||
|
||||
local tests = {}
|
||||
if json_encode then tests.encode = test_encode end
|
||||
if json_decode then tests.decode = test_decode end
|
||||
|
||||
return benchmark(tests, 0.1, 5)
|
||||
end
|
||||
|
||||
-- Optionally load any custom configuration required for this module
|
||||
local success, data = pcall(util.file_load, ("bench-%s.lua"):format(json_module))
|
||||
if success then
|
||||
util.run_script(data, _G)
|
||||
configure(json)
|
||||
end
|
||||
|
||||
for i = 1, #arg do
|
||||
local results = bench_file(arg[i])
|
||||
for k, v in pairs(results) do
|
||||
print(("%s\t%s\t%d"):format(arg[i], k, v))
|
||||
end
|
||||
end
|
||||
|
||||
-- vi:ai et sw=4 ts=4:
|
||||
22
src/deps/src/lua-cjson/tests/example1.json
vendored
22
src/deps/src/lua-cjson/tests/example1.json
vendored
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"glossary": {
|
||||
"title": "example glossary",
|
||||
"GlossDiv": {
|
||||
"title": "S",
|
||||
"GlossList": {
|
||||
"GlossEntry": {
|
||||
"ID": "SGML",
|
||||
"SortAs": "SGML",
|
||||
"GlossTerm": "Standard Generalized Mark up Language",
|
||||
"Acronym": "SGML",
|
||||
"Abbrev": "ISO 8879:1986",
|
||||
"GlossDef": {
|
||||
"para": "A meta-markup language, used to create markup languages such as DocBook.",
|
||||
"GlossSeeAlso": ["GML", "XML"]
|
||||
},
|
||||
"GlossSee": "markup"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/deps/src/lua-cjson/tests/example2.json
vendored
11
src/deps/src/lua-cjson/tests/example2.json
vendored
|
|
@ -1,11 +0,0 @@
|
|||
{"menu": {
|
||||
"id": "file",
|
||||
"value": "File",
|
||||
"popup": {
|
||||
"menuitem": [
|
||||
{"value": "New", "onclick": "CreateNewDoc()"},
|
||||
{"value": "Open", "onclick": "OpenDoc()"},
|
||||
{"value": "Close", "onclick": "CloseDoc()"}
|
||||
]
|
||||
}
|
||||
}}
|
||||
26
src/deps/src/lua-cjson/tests/example3.json
vendored
26
src/deps/src/lua-cjson/tests/example3.json
vendored
|
|
@ -1,26 +0,0 @@
|
|||
{"widget": {
|
||||
"debug": "on",
|
||||
"window": {
|
||||
"title": "Sample Konfabulator Widget",
|
||||
"name": "main_window",
|
||||
"width": 500,
|
||||
"height": 500
|
||||
},
|
||||
"image": {
|
||||
"src": "Images/Sun.png",
|
||||
"name": "sun1",
|
||||
"hOffset": 250,
|
||||
"vOffset": 250,
|
||||
"alignment": "center"
|
||||
},
|
||||
"text": {
|
||||
"data": "Click Here",
|
||||
"size": 36,
|
||||
"style": "bold",
|
||||
"name": "text1",
|
||||
"hOffset": 250,
|
||||
"vOffset": 100,
|
||||
"alignment": "center",
|
||||
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
|
||||
}
|
||||
}}
|
||||
88
src/deps/src/lua-cjson/tests/example4.json
vendored
88
src/deps/src/lua-cjson/tests/example4.json
vendored
|
|
@ -1,88 +0,0 @@
|
|||
{"web-app": {
|
||||
"servlet": [
|
||||
{
|
||||
"servlet-name": "cofaxCDS",
|
||||
"servlet-class": "org.cofax.cds.CDSServlet",
|
||||
"init-param": {
|
||||
"configGlossary:installationAt": "Philadelphia, PA",
|
||||
"configGlossary:adminEmail": "ksm@pobox.com",
|
||||
"configGlossary:poweredBy": "Cofax",
|
||||
"configGlossary:poweredByIcon": "/images/cofax.gif",
|
||||
"configGlossary:staticPath": "/content/static",
|
||||
"templateProcessorClass": "org.cofax.WysiwygTemplate",
|
||||
"templateLoaderClass": "org.cofax.FilesTemplateLoader",
|
||||
"templatePath": "templates",
|
||||
"templateOverridePath": "",
|
||||
"defaultListTemplate": "listTemplate.htm",
|
||||
"defaultFileTemplate": "articleTemplate.htm",
|
||||
"useJSP": false,
|
||||
"jspListTemplate": "listTemplate.jsp",
|
||||
"jspFileTemplate": "articleTemplate.jsp",
|
||||
"cachePackageTagsTrack": 200,
|
||||
"cachePackageTagsStore": 200,
|
||||
"cachePackageTagsRefresh": 60,
|
||||
"cacheTemplatesTrack": 100,
|
||||
"cacheTemplatesStore": 50,
|
||||
"cacheTemplatesRefresh": 15,
|
||||
"cachePagesTrack": 200,
|
||||
"cachePagesStore": 100,
|
||||
"cachePagesRefresh": 10,
|
||||
"cachePagesDirtyRead": 10,
|
||||
"searchEngineListTemplate": "forSearchEnginesList.htm",
|
||||
"searchEngineFileTemplate": "forSearchEngines.htm",
|
||||
"searchEngineRobotsDb": "WEB-INF/robots.db",
|
||||
"useDataStore": true,
|
||||
"dataStoreClass": "org.cofax.SqlDataStore",
|
||||
"redirectionClass": "org.cofax.SqlRedirection",
|
||||
"dataStoreName": "cofax",
|
||||
"dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
|
||||
"dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
|
||||
"dataStoreUser": "sa",
|
||||
"dataStorePassword": "dataStoreTestQuery",
|
||||
"dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
|
||||
"dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
|
||||
"dataStoreInitConns": 10,
|
||||
"dataStoreMaxConns": 100,
|
||||
"dataStoreConnUsageLimit": 100,
|
||||
"dataStoreLogLevel": "debug",
|
||||
"maxUrlLength": 500}},
|
||||
{
|
||||
"servlet-name": "cofaxEmail",
|
||||
"servlet-class": "org.cofax.cds.EmailServlet",
|
||||
"init-param": {
|
||||
"mailHost": "mail1",
|
||||
"mailHostOverride": "mail2"}},
|
||||
{
|
||||
"servlet-name": "cofaxAdmin",
|
||||
"servlet-class": "org.cofax.cds.AdminServlet"},
|
||||
|
||||
{
|
||||
"servlet-name": "fileServlet",
|
||||
"servlet-class": "org.cofax.cds.FileServlet"},
|
||||
{
|
||||
"servlet-name": "cofaxTools",
|
||||
"servlet-class": "org.cofax.cms.CofaxToolsServlet",
|
||||
"init-param": {
|
||||
"templatePath": "toolstemplates/",
|
||||
"log": 1,
|
||||
"logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
|
||||
"logMaxSize": "",
|
||||
"dataLog": 1,
|
||||
"dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
|
||||
"dataLogMaxSize": "",
|
||||
"removePageCache": "/content/admin/remove?cache=pages&id=",
|
||||
"removeTemplateCache": "/content/admin/remove?cache=templates&id=",
|
||||
"fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
|
||||
"lookInContext": 1,
|
||||
"adminGroupID": 4,
|
||||
"betaServer": true}}],
|
||||
"servlet-mapping": {
|
||||
"cofaxCDS": "/",
|
||||
"cofaxEmail": "/cofaxutil/aemail/*",
|
||||
"cofaxAdmin": "/admin/*",
|
||||
"fileServlet": "/static/*",
|
||||
"cofaxTools": "/tools/*"},
|
||||
|
||||
"taglib": {
|
||||
"taglib-uri": "cofax.tld",
|
||||
"taglib-location": "/WEB-INF/tlds/cofax.tld"}}}
|
||||
27
src/deps/src/lua-cjson/tests/example5.json
vendored
27
src/deps/src/lua-cjson/tests/example5.json
vendored
|
|
@ -1,27 +0,0 @@
|
|||
{"menu": {
|
||||
"header": "SVG Viewer",
|
||||
"items": [
|
||||
{"id": "Open"},
|
||||
{"id": "OpenNew", "label": "Open New"},
|
||||
null,
|
||||
{"id": "ZoomIn", "label": "Zoom In"},
|
||||
{"id": "ZoomOut", "label": "Zoom Out"},
|
||||
{"id": "OriginalView", "label": "Original View"},
|
||||
null,
|
||||
{"id": "Quality"},
|
||||
{"id": "Pause"},
|
||||
{"id": "Mute"},
|
||||
null,
|
||||
{"id": "Find", "label": "Find..."},
|
||||
{"id": "FindAgain", "label": "Find Again"},
|
||||
{"id": "Copy"},
|
||||
{"id": "CopyAgain", "label": "Copy Again"},
|
||||
{"id": "CopySVG", "label": "Copy SVG"},
|
||||
{"id": "ViewSVG", "label": "View SVG"},
|
||||
{"id": "ViewSource", "label": "View Source"},
|
||||
{"id": "SaveAs", "label": "Save As"},
|
||||
null,
|
||||
{"id": "Help"},
|
||||
{"id": "About", "label": "About Adobe CVG Viewer..."}
|
||||
]
|
||||
}}
|
||||
24
src/deps/src/lua-cjson/tests/genutf8.pl
vendored
24
src/deps/src/lua-cjson/tests/genutf8.pl
vendored
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
# Create test comparison data using a different UTF-8 implementation.
|
||||
|
||||
# The generated utf8.dat file must have the following MD5 sum:
|
||||
# cff03b039d850f370a7362f3313e5268
|
||||
|
||||
use strict;
|
||||
no warnings 'nonchar';
|
||||
|
||||
# 0xD800 - 0xDFFF are used to encode supplementary codepoints
|
||||
# 0x10000 - 0x10FFFF are supplementary codepoints
|
||||
my (@codepoints) = (0 .. 0xD7FF, 0xE000 .. 0x10FFFF);
|
||||
|
||||
my $utf8 = pack("U*", @codepoints);
|
||||
defined($utf8) or die "Unable create UTF-8 string\n";
|
||||
|
||||
open(FH, ">:utf8", "utf8.dat")
|
||||
or die "Unable to open utf8.dat: $!\n";
|
||||
print FH $utf8
|
||||
or die "Unable to write utf8.dat\n";
|
||||
close(FH);
|
||||
|
||||
# vi:ai et sw=4 ts=4:
|
||||
7
src/deps/src/lua-cjson/tests/numbers.json
vendored
7
src/deps/src/lua-cjson/tests/numbers.json
vendored
|
|
@ -1,7 +0,0 @@
|
|||
[ 0.110001,
|
||||
0.12345678910111,
|
||||
0.412454033640,
|
||||
2.6651441426902,
|
||||
2.718281828459,
|
||||
3.1415926535898,
|
||||
2.1406926327793 ]
|
||||
|
|
@ -1 +0,0 @@
|
|||
"\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€亗儎厗噲墛媽崕彁憭摂晼棙櫄洔潪煚、¥ウЖ┆<D096><E29486><EFBFBD>辈炒刀犯购患骄坷谅媚牌侨墒颂臀闲岩釉罩棕仝圮蒉哙徕沅彐玷殛腱眍镳耱篝貊鼬<E8B28A><E9BCAC><EFBFBD><EFBFBD>"
|
||||
13
src/deps/src/lua-cjson/tests/rfc-example1.json
vendored
13
src/deps/src/lua-cjson/tests/rfc-example1.json
vendored
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"Image": {
|
||||
"Width": 800,
|
||||
"Height": 600,
|
||||
"Title": "View from 15th Floor",
|
||||
"Thumbnail": {
|
||||
"Url": "http://www.example.com/image/481989943",
|
||||
"Height": 125,
|
||||
"Width": "100"
|
||||
},
|
||||
"IDs": [116, 943, 234, 38793]
|
||||
}
|
||||
}
|
||||
22
src/deps/src/lua-cjson/tests/rfc-example2.json
vendored
22
src/deps/src/lua-cjson/tests/rfc-example2.json
vendored
|
|
@ -1,22 +0,0 @@
|
|||
[
|
||||
{
|
||||
"precision": "zip",
|
||||
"Latitude": 37.7668,
|
||||
"Longitude": -122.3959,
|
||||
"Address": "",
|
||||
"City": "SAN FRANCISCO",
|
||||
"State": "CA",
|
||||
"Zip": "94107",
|
||||
"Country": "US"
|
||||
},
|
||||
{
|
||||
"precision": "zip",
|
||||
"Latitude": 37.371991,
|
||||
"Longitude": -122.026020,
|
||||
"Address": "",
|
||||
"City": "SUNNYVALE",
|
||||
"State": "CA",
|
||||
"Zip": "94085",
|
||||
"Country": "US"
|
||||
}
|
||||
]
|
||||
61
src/deps/src/lua-cjson/tests/sort_json.lua
vendored
61
src/deps/src/lua-cjson/tests/sort_json.lua
vendored
|
|
@ -1,61 +0,0 @@
|
|||
-- NOTE: This will only work for simple tests. It doesn't parse strings so if
|
||||
-- you put any symbols like {?[], inside of a string literal then it will break
|
||||
-- The point of this function is to test basic structures, and not test JSON
|
||||
-- strings
|
||||
|
||||
local function sort_callback(str)
|
||||
local inside = str:sub(2, -2)
|
||||
|
||||
local parts = {}
|
||||
local buffer = ""
|
||||
local pos = 1
|
||||
|
||||
while true do
|
||||
if pos > #inside then
|
||||
break
|
||||
end
|
||||
|
||||
local append
|
||||
|
||||
local parens = inside:match("^%b{}", pos)
|
||||
if parens then
|
||||
pos = pos + #parens
|
||||
append = sort_callback(parens)
|
||||
else
|
||||
local array = inside:match("^%b[]", pos)
|
||||
if array then
|
||||
pos = pos + #array
|
||||
append = array
|
||||
else
|
||||
local front = inside:sub(pos, pos)
|
||||
pos = pos + 1
|
||||
|
||||
if front == "," then
|
||||
table.insert(parts, buffer)
|
||||
buffer = ""
|
||||
else
|
||||
append = front
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if append then
|
||||
buffer = buffer .. append
|
||||
end
|
||||
end
|
||||
|
||||
if buffer ~= "" then
|
||||
table.insert(parts, buffer)
|
||||
end
|
||||
|
||||
table.sort(parts)
|
||||
|
||||
return "{" .. table.concat(parts, ",") .. "}"
|
||||
end
|
||||
|
||||
local function sort_json(str)
|
||||
return (str:gsub("%b{}", sort_callback))
|
||||
end
|
||||
|
||||
|
||||
return sort_json
|
||||
474
src/deps/src/lua-cjson/tests/test.lua
vendored
474
src/deps/src/lua-cjson/tests/test.lua
vendored
|
|
@ -1,474 +0,0 @@
|
|||
#!/usr/bin/env lua
|
||||
|
||||
-- Lua CJSON tests
|
||||
--
|
||||
-- Mark Pulford <mark@kyne.com.au>
|
||||
--
|
||||
-- Note: The output of this script is easier to read with "less -S"
|
||||
|
||||
local json = require "cjson"
|
||||
local json_safe = require "cjson.safe"
|
||||
local util = require "cjson.util"
|
||||
|
||||
local function gen_raw_octets()
|
||||
local chars = {}
|
||||
for i = 0, 255 do chars[i + 1] = string.char(i) end
|
||||
return table.concat(chars)
|
||||
end
|
||||
|
||||
-- Generate every UTF-16 codepoint, including supplementary codes
|
||||
local function gen_utf16_escaped()
|
||||
-- Create raw table escapes
|
||||
local utf16_escaped = {}
|
||||
local count = 0
|
||||
|
||||
local function append_escape(code)
|
||||
local esc = ('\\u%04X'):format(code)
|
||||
table.insert(utf16_escaped, esc)
|
||||
end
|
||||
|
||||
table.insert(utf16_escaped, '"')
|
||||
for i = 0, 0xD7FF do
|
||||
append_escape(i)
|
||||
end
|
||||
-- Skip 0xD800 - 0xDFFF since they are used to encode supplementary
|
||||
-- codepoints
|
||||
for i = 0xE000, 0xFFFF do
|
||||
append_escape(i)
|
||||
end
|
||||
-- Append surrogate pair for each supplementary codepoint
|
||||
for high = 0xD800, 0xDBFF do
|
||||
for low = 0xDC00, 0xDFFF do
|
||||
append_escape(high)
|
||||
append_escape(low)
|
||||
end
|
||||
end
|
||||
table.insert(utf16_escaped, '"')
|
||||
|
||||
return table.concat(utf16_escaped)
|
||||
end
|
||||
|
||||
function load_testdata()
|
||||
local data = {}
|
||||
|
||||
-- Data for 8bit raw <-> escaped octets tests
|
||||
data.octets_raw = gen_raw_octets()
|
||||
data.octets_escaped = util.file_load("octets-escaped.dat")
|
||||
|
||||
-- Data for \uXXXX -> UTF-8 test
|
||||
data.utf16_escaped = gen_utf16_escaped()
|
||||
|
||||
-- Load matching data for utf16_escaped
|
||||
local utf8_loaded
|
||||
utf8_loaded, data.utf8_raw = pcall(util.file_load, "utf8.dat")
|
||||
if not utf8_loaded then
|
||||
data.utf8_raw = "Failed to load utf8.dat - please run genutf8.pl"
|
||||
end
|
||||
|
||||
data.table_cycle = {}
|
||||
data.table_cycle[1] = data.table_cycle
|
||||
|
||||
local big = {}
|
||||
for i = 1, 1100 do
|
||||
big = { { 10, false, true, json.null }, "string", a = big }
|
||||
end
|
||||
data.deeply_nested_data = big
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
function test_decode_cycle(filename)
|
||||
local obj1 = json.decode(util.file_load(filename))
|
||||
local obj2 = json.decode(json.encode(obj1))
|
||||
return util.compare_values(obj1, obj2)
|
||||
end
|
||||
|
||||
-- Set up data used in tests
|
||||
local Inf = math.huge;
|
||||
local NaN = math.huge * 0;
|
||||
|
||||
local testdata = load_testdata()
|
||||
|
||||
local cjson_tests = {
|
||||
-- Test API variables
|
||||
{ "Check module name, version",
|
||||
function () return json._NAME, json._VERSION end, { },
|
||||
true, { "cjson", "2.1.0.11" } },
|
||||
|
||||
-- Test decoding simple types
|
||||
{ "Decode string",
|
||||
json.decode, { '"test string"' }, true, { "test string" } },
|
||||
{ "Decode numbers",
|
||||
json.decode, { '[ 0.0, -5e3, -1, 0.3e-3, 1023.2, 0e10 ]' },
|
||||
true, { { 0.0, -5000, -1, 0.0003, 1023.2, 0 } } },
|
||||
{ "Decode null",
|
||||
json.decode, { 'null' }, true, { json.null } },
|
||||
{ "Decode true",
|
||||
json.decode, { 'true' }, true, { true } },
|
||||
{ "Decode false",
|
||||
json.decode, { 'false' }, true, { false } },
|
||||
{ "Decode object with numeric keys",
|
||||
json.decode, { '{ "1": "one", "3": "three" }' },
|
||||
true, { { ["1"] = "one", ["3"] = "three" } } },
|
||||
{ "Decode object with string keys",
|
||||
json.decode, { '{ "a": "a", "b": "b" }' },
|
||||
true, { { a = "a", b = "b" } } },
|
||||
{ "Decode array",
|
||||
json.decode, { '[ "one", null, "three" ]' },
|
||||
true, { { "one", json.null, "three" } } },
|
||||
|
||||
-- Test decoding errors
|
||||
{ "Decode UTF-16BE [throw error]",
|
||||
json.decode, { '\0"\0"' },
|
||||
false, { "JSON parser does not support UTF-16 or UTF-32" } },
|
||||
{ "Decode UTF-16LE [throw error]",
|
||||
json.decode, { '"\0"\0' },
|
||||
false, { "JSON parser does not support UTF-16 or UTF-32" } },
|
||||
{ "Decode UTF-32BE [throw error]",
|
||||
json.decode, { '\0\0\0"' },
|
||||
false, { "JSON parser does not support UTF-16 or UTF-32" } },
|
||||
{ "Decode UTF-32LE [throw error]",
|
||||
json.decode, { '"\0\0\0' },
|
||||
false, { "JSON parser does not support UTF-16 or UTF-32" } },
|
||||
{ "Decode partial JSON [throw error]",
|
||||
json.decode, { '{ "unexpected eof": ' },
|
||||
false, { "Expected value but found T_END at character 21" } },
|
||||
{ "Decode with extra comma [throw error]",
|
||||
json.decode, { '{ "extra data": true }, false' },
|
||||
false, { "Expected the end but found T_COMMA at character 23" } },
|
||||
{ "Decode invalid escape code [throw error]",
|
||||
json.decode, { [[ { "bad escape \q code" } ]] },
|
||||
false, { "Expected object key string but found invalid escape code at character 16" } },
|
||||
{ "Decode invalid unicode escape [throw error]",
|
||||
json.decode, { [[ { "bad unicode \u0f6 escape" } ]] },
|
||||
false, { "Expected object key string but found invalid unicode escape code at character 17" } },
|
||||
{ "Decode invalid keyword [throw error]",
|
||||
json.decode, { ' [ "bad barewood", test ] ' },
|
||||
false, { "Expected value but found invalid token at character 20" } },
|
||||
{ "Decode invalid number #1 [throw error]",
|
||||
json.decode, { '[ -+12 ]' },
|
||||
false, { "Expected value but found invalid number at character 3" } },
|
||||
{ "Decode invalid number #2 [throw error]",
|
||||
json.decode, { '-v' },
|
||||
false, { "Expected value but found invalid number at character 1" } },
|
||||
{ "Decode invalid number exponent [throw error]",
|
||||
json.decode, { '[ 0.4eg10 ]' },
|
||||
false, { "Expected comma or array end but found invalid token at character 6" } },
|
||||
|
||||
-- Test decoding nested arrays / objects
|
||||
{ "Set decode_max_depth(5)",
|
||||
json.decode_max_depth, { 5 }, true, { 5 } },
|
||||
{ "Decode array at nested limit",
|
||||
json.decode, { '[[[[[ "nested" ]]]]]' },
|
||||
true, { {{{{{ "nested" }}}}} } },
|
||||
{ "Decode array over nested limit [throw error]",
|
||||
json.decode, { '[[[[[[ "nested" ]]]]]]' },
|
||||
false, { "Found too many nested data structures (6) at character 6" } },
|
||||
{ "Decode object at nested limit",
|
||||
json.decode, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' },
|
||||
true, { {a={b={c={d={e="nested"}}}}} } },
|
||||
{ "Decode object over nested limit [throw error]",
|
||||
json.decode, { '{"a":{"b":{"c":{"d":{"e":{"f":"nested"}}}}}}' },
|
||||
false, { "Found too many nested data structures (6) at character 26" } },
|
||||
{ "Set decode_max_depth(1000)",
|
||||
json.decode_max_depth, { 1000 }, true, { 1000 } },
|
||||
{ "Decode deeply nested array [throw error]",
|
||||
json.decode, { string.rep("[", 1100) .. '1100' .. string.rep("]", 1100)},
|
||||
false, { "Found too many nested data structures (1001) at character 1001" } },
|
||||
|
||||
-- Test encoding nested tables
|
||||
{ "Set encode_max_depth(5)",
|
||||
json.encode_max_depth, { 5 }, true, { 5 } },
|
||||
{ "Encode nested table as array at nested limit",
|
||||
json.encode, { {{{{{"nested"}}}}} }, true, { '[[[[["nested"]]]]]' } },
|
||||
{ "Encode nested table as array after nested limit [throw error]",
|
||||
json.encode, { { {{{{{"nested"}}}}} } },
|
||||
false, { "Cannot serialise, excessive nesting (6)" } },
|
||||
{ "Encode nested table as object at nested limit",
|
||||
json.encode, { {a={b={c={d={e="nested"}}}}} },
|
||||
true, { '{"a":{"b":{"c":{"d":{"e":"nested"}}}}}' } },
|
||||
{ "Encode nested table as object over nested limit [throw error]",
|
||||
json.encode, { {a={b={c={d={e={f="nested"}}}}}} },
|
||||
false, { "Cannot serialise, excessive nesting (6)" } },
|
||||
{ "Encode table with cycle [throw error]",
|
||||
json.encode, { testdata.table_cycle },
|
||||
false, { "Cannot serialise, excessive nesting (6)" } },
|
||||
{ "Set encode_max_depth(1000)",
|
||||
json.encode_max_depth, { 1000 }, true, { 1000 } },
|
||||
{ "Encode deeply nested data [throw error]",
|
||||
json.encode, { testdata.deeply_nested_data },
|
||||
false, { "Cannot serialise, excessive nesting (1001)" } },
|
||||
|
||||
-- Test encoding simple types
|
||||
{ "Encode null",
|
||||
json.encode, { json.null }, true, { 'null' } },
|
||||
{ "Encode true",
|
||||
json.encode, { true }, true, { 'true' } },
|
||||
{ "Encode false",
|
||||
json.encode, { false }, true, { 'false' } },
|
||||
{ "Encode empty object",
|
||||
json.encode, { { } }, true, { '{}' } },
|
||||
{ "Encode integer",
|
||||
json.encode, { 10 }, true, { '10' } },
|
||||
{ "Encode string",
|
||||
json.encode, { "hello" }, true, { '"hello"' } },
|
||||
{ "Encode Lua function [throw error]",
|
||||
json.encode, { function () end },
|
||||
false, { "Cannot serialise function: type not supported" } },
|
||||
|
||||
-- Test decoding invalid numbers
|
||||
{ "Set decode_invalid_numbers(true)",
|
||||
json.decode_invalid_numbers, { true }, true, { true } },
|
||||
{ "Decode hexadecimal",
|
||||
json.decode, { '0x6.ffp1' }, true, { 13.9921875 } },
|
||||
{ "Decode numbers with leading zero",
|
||||
json.decode, { '[ 0123, 00.33 ]' }, true, { { 123, 0.33 } } },
|
||||
{ "Decode +-Inf",
|
||||
json.decode, { '[ +Inf, Inf, -Inf ]' }, true, { { Inf, Inf, -Inf } } },
|
||||
{ "Decode +-Infinity",
|
||||
json.decode, { '[ +Infinity, Infinity, -Infinity ]' },
|
||||
true, { { Inf, Inf, -Inf } } },
|
||||
{ "Decode +-NaN",
|
||||
json.decode, { '[ +NaN, NaN, -NaN ]' }, true, { { NaN, NaN, NaN } } },
|
||||
{ "Decode Infrared (not infinity) [throw error]",
|
||||
json.decode, { 'Infrared' },
|
||||
false, { "Expected the end but found invalid token at character 4" } },
|
||||
{ "Decode Noodle (not NaN) [throw error]",
|
||||
json.decode, { 'Noodle' },
|
||||
false, { "Expected value but found invalid token at character 1" } },
|
||||
{ "Set decode_invalid_numbers(false)",
|
||||
json.decode_invalid_numbers, { false }, true, { false } },
|
||||
{ "Decode hexadecimal [throw error]",
|
||||
json.decode, { '0x6' },
|
||||
false, { "Expected value but found invalid number at character 1" } },
|
||||
{ "Decode numbers with leading zero [throw error]",
|
||||
json.decode, { '[ 0123, 00.33 ]' },
|
||||
false, { "Expected value but found invalid number at character 3" } },
|
||||
{ "Decode +-Inf [throw error]",
|
||||
json.decode, { '[ +Inf, Inf, -Inf ]' },
|
||||
false, { "Expected value but found invalid token at character 3" } },
|
||||
{ "Decode +-Infinity [throw error]",
|
||||
json.decode, { '[ +Infinity, Infinity, -Infinity ]' },
|
||||
false, { "Expected value but found invalid token at character 3" } },
|
||||
{ "Decode +-NaN [throw error]",
|
||||
json.decode, { '[ +NaN, NaN, -NaN ]' },
|
||||
false, { "Expected value but found invalid token at character 3" } },
|
||||
{ 'Set decode_invalid_numbers("on")',
|
||||
json.decode_invalid_numbers, { "on" }, true, { true } },
|
||||
|
||||
-- Test encoding invalid numbers
|
||||
{ "Set encode_invalid_numbers(false)",
|
||||
json.encode_invalid_numbers, { false }, true, { false } },
|
||||
{ "Encode NaN [throw error]",
|
||||
json.encode, { NaN },
|
||||
false, { "Cannot serialise number: must not be NaN or Infinity" } },
|
||||
{ "Encode Infinity [throw error]",
|
||||
json.encode, { Inf },
|
||||
false, { "Cannot serialise number: must not be NaN or Infinity" } },
|
||||
{ "Set encode_invalid_numbers(\"null\")",
|
||||
json.encode_invalid_numbers, { "null" }, true, { "null" } },
|
||||
{ "Encode NaN as null",
|
||||
json.encode, { NaN }, true, { "null" } },
|
||||
{ "Encode Infinity as null",
|
||||
json.encode, { Inf }, true, { "null" } },
|
||||
{ "Set encode_invalid_numbers(true)",
|
||||
json.encode_invalid_numbers, { true }, true, { true } },
|
||||
{ "Encode NaN",
|
||||
json.encode, { NaN }, true, { "NaN" } },
|
||||
{ "Encode +Infinity",
|
||||
json.encode, { Inf }, true, { "Infinity" } },
|
||||
{ "Encode -Infinity",
|
||||
json.encode, { -Inf }, true, { "-Infinity" } },
|
||||
{ 'Set encode_invalid_numbers("off")',
|
||||
json.encode_invalid_numbers, { "off" }, true, { false } },
|
||||
|
||||
-- Test encoding tables
|
||||
{ "Set encode_sparse_array(true, 2, 3)",
|
||||
json.encode_sparse_array, { true, 2, 3 }, true, { true, 2, 3 } },
|
||||
{ "Encode sparse table as array #1",
|
||||
json.encode, { { [3] = "sparse test" } },
|
||||
true, { '[null,null,"sparse test"]' } },
|
||||
{ "Encode sparse table as array #2",
|
||||
json.encode, { { [1] = "one", [4] = "sparse test" } },
|
||||
true, { '["one",null,null,"sparse test"]' } },
|
||||
{ "Encode sparse array as object",
|
||||
json.encode, { { [1] = "one", [5] = "sparse test" } },
|
||||
true, {
|
||||
util.one_of {
|
||||
'{"5":"sparse test","1":"one"}',
|
||||
'{"1":"one","5":"sparse test"}'
|
||||
}
|
||||
} },
|
||||
{ "Encode table with numeric string key as object",
|
||||
json.encode, { { ["2"] = "numeric string key test" } },
|
||||
true, { '{"2":"numeric string key test"}' } },
|
||||
{ "Set encode_sparse_array(false)",
|
||||
json.encode_sparse_array, { false }, true, { false, 2, 3 } },
|
||||
{ "Encode table with incompatible key [throw error]",
|
||||
json.encode, { { [false] = "wrong" } },
|
||||
false, { "Cannot serialise boolean: table key must be a number or string" } },
|
||||
|
||||
-- Test escaping
|
||||
{ "Encode all octets (8-bit clean)",
|
||||
json.encode, { testdata.octets_raw }, true, { testdata.octets_escaped } },
|
||||
{ "Decode all escaped octets",
|
||||
json.decode, { testdata.octets_escaped }, true, { testdata.octets_raw } },
|
||||
{ "Decode single UTF-16 escape",
|
||||
json.decode, { [["\uF800"]] }, true, { "\239\160\128" } },
|
||||
{ "Decode all UTF-16 escapes (including surrogate combinations)",
|
||||
json.decode, { testdata.utf16_escaped }, true, { testdata.utf8_raw } },
|
||||
{ "Decode swapped surrogate pair [throw error]",
|
||||
json.decode, { [["\uDC00\uD800"]] },
|
||||
false, { "Expected value but found invalid unicode escape code at character 2" } },
|
||||
{ "Decode duplicate high surrogate [throw error]",
|
||||
json.decode, { [["\uDB00\uDB00"]] },
|
||||
false, { "Expected value but found invalid unicode escape code at character 2" } },
|
||||
{ "Decode duplicate low surrogate [throw error]",
|
||||
json.decode, { [["\uDB00\uDB00"]] },
|
||||
false, { "Expected value but found invalid unicode escape code at character 2" } },
|
||||
{ "Decode missing low surrogate [throw error]",
|
||||
json.decode, { [["\uDB00"]] },
|
||||
false, { "Expected value but found invalid unicode escape code at character 2" } },
|
||||
{ "Decode invalid low surrogate [throw error]",
|
||||
json.decode, { [["\uDB00\uD"]] },
|
||||
false, { "Expected value but found invalid unicode escape code at character 2" } },
|
||||
|
||||
-- Test locale support
|
||||
--
|
||||
-- The standard Lua interpreter is ANSI C online doesn't support locales
|
||||
-- by default. Force a known problematic locale to test strtod()/sprintf().
|
||||
{ "Set locale to cs_CZ (comma separator)", function ()
|
||||
os.setlocale("cs_CZ")
|
||||
json.new()
|
||||
end },
|
||||
{ "Encode number under comma locale",
|
||||
json.encode, { 1.5 }, true, { '1.5' } },
|
||||
{ "Decode number in array under comma locale",
|
||||
json.decode, { '[ 10, "test" ]' }, true, { { 10, "test" } } },
|
||||
{ "Revert locale to POSIX", function ()
|
||||
os.setlocale("C")
|
||||
json.new()
|
||||
end },
|
||||
|
||||
-- Test encode_keep_buffer() and enable_number_precision()
|
||||
{ "Set encode_keep_buffer(false)",
|
||||
json.encode_keep_buffer, { false }, true, { false } },
|
||||
{ "Set encode_number_precision(3)",
|
||||
json.encode_number_precision, { 3 }, true, { 3 } },
|
||||
{ "Encode number with precision 3",
|
||||
json.encode, { 1/3 }, true, { "0.333" } },
|
||||
{ "Set encode_number_precision(14)",
|
||||
json.encode_number_precision, { 14 }, true, { 14 } },
|
||||
{ "Set encode_keep_buffer(true)",
|
||||
json.encode_keep_buffer, { true }, true, { true } },
|
||||
|
||||
-- Test config API errors
|
||||
-- Function is listed as '?' due to pcall for older versions of Lua
|
||||
{ "Set encode_number_precision(0) [throw error]",
|
||||
json.encode_number_precision, { 0 },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #1 to '?' (expected integer between 1 and 16)",
|
||||
"bad argument #1 to 'cjson.encode_number_precision' (expected integer between 1 and 16)"
|
||||
}
|
||||
} },
|
||||
{ "Set encode_number_precision(\"five\") [throw error]",
|
||||
json.encode_number_precision, { "five" },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #1 to '?' (number expected, got string)",
|
||||
"bad argument #1 to 'cjson.encode_number_precision' (number expected, got string)"
|
||||
}
|
||||
} },
|
||||
{ "Set encode_keep_buffer(nil, true) [throw error]",
|
||||
json.encode_keep_buffer, { nil, true },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #2 to '?' (found too many arguments)",
|
||||
"bad argument #2 to 'cjson.encode_keep_buffer' (found too many arguments)"
|
||||
}
|
||||
} },
|
||||
{ "Set encode_max_depth(\"wrong\") [throw error]",
|
||||
json.encode_max_depth, { "wrong" },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #1 to '?' (number expected, got string)",
|
||||
"bad argument #1 to 'cjson.encode_max_depth' (number expected, got string)"
|
||||
}
|
||||
} },
|
||||
{ "Set decode_max_depth(0) [throw error]",
|
||||
json.decode_max_depth, { "0" },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #1 to '?' (expected integer between 1 and 2147483647)",
|
||||
"bad argument #1 to 'cjson.decode_max_depth' (expected integer between 1 and 2147483647)"
|
||||
}
|
||||
} },
|
||||
{ "Set encode_invalid_numbers(-2) [throw error]",
|
||||
json.encode_invalid_numbers, { -2 },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #1 to '?' (invalid option '-2')",
|
||||
"bad argument #1 to 'cjson.encode_invalid_numbers' (invalid option '-2')"
|
||||
}
|
||||
} },
|
||||
{ "Set decode_invalid_numbers(true, false) [throw error]",
|
||||
json.decode_invalid_numbers, { true, false },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #2 to '?' (found too many arguments)",
|
||||
"bad argument #2 to 'cjson.decode_invalid_numbers' (found too many arguments)"
|
||||
}
|
||||
} },
|
||||
{ "Set encode_sparse_array(\"not quite on\") [throw error]",
|
||||
json.encode_sparse_array, { "not quite on" },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #1 to '?' (invalid option 'not quite on')",
|
||||
"bad argument #1 to 'cjson.encode_sparse_array' (invalid option 'not quite on')"
|
||||
}
|
||||
} },
|
||||
{ "Reset Lua CJSON configuration", function () json = json.new() end },
|
||||
-- Wrap in a function to ensure the table returned by json.new() is used
|
||||
{ "Check encode_sparse_array()",
|
||||
function (...) return json.encode_sparse_array(...) end, { },
|
||||
true, { false, 2, 10 } },
|
||||
|
||||
{ "Encode (safe) simple value",
|
||||
json_safe.encode, { true },
|
||||
true, { "true" } },
|
||||
{ "Encode (safe) argument validation [throw error]",
|
||||
json_safe.encode, { "arg1", "arg2" },
|
||||
false, {
|
||||
util.one_of {
|
||||
"bad argument #1 to '?' (expected 1 argument)",
|
||||
"bad argument #1 to 'cjson.safe.encode' (expected 1 argument)"
|
||||
}
|
||||
} },
|
||||
{ "Decode (safe) error generation",
|
||||
json_safe.decode, { "Oops" },
|
||||
true, { nil, "Expected value but found invalid token at character 1" } },
|
||||
{ "Decode (safe) error generation after new()",
|
||||
function(...) return json_safe.new().decode(...) end, { "Oops" },
|
||||
true, { nil, "Expected value but found invalid token at character 1" } },
|
||||
}
|
||||
|
||||
print(("==> Testing Lua CJSON version %s\n"):format(json._VERSION))
|
||||
|
||||
util.run_test_group(cjson_tests)
|
||||
|
||||
for _, filename in ipairs(arg) do
|
||||
util.run_test("Decode cycle " .. filename, test_decode_cycle, { filename },
|
||||
true, { true })
|
||||
end
|
||||
|
||||
local pass, total = util.run_test_summary()
|
||||
|
||||
if pass == total then
|
||||
print("==> Summary: all tests succeeded")
|
||||
else
|
||||
print(("==> Summary: %d/%d tests failed"):format(total - pass, total))
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
-- vi:ai et sw=4 ts=4:
|
||||
1
src/deps/src/lua-cjson/tests/types.json
vendored
1
src/deps/src/lua-cjson/tests/types.json
vendored
|
|
@ -1 +0,0 @@
|
|||
{ "array": [ 10, true, null ] }
|
||||
Loading…
Reference in a new issue