Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Lua Json
Commits
73487ac0
Commit
73487ac0
authored
Jun 22, 2019
by
seny
Browse files
Add compliance and error tests
parent
cde7ad26
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/test-json.lua
View file @
73487ac0
...
@@ -142,4 +142,27 @@ end
...
@@ -142,4 +142,27 @@ end
-- Compliance test --
-- Compliance test --
---------------------
---------------------
-- TODO
local
strs
=
{
'{\t"a"\n:\r1, \t"a"\n:\r2}'
,
-- Whitespace + double key
'"\\ud800\\uDC00"'
,
-- UTF-16 surrogate pair
}
local
objs
=
{
{
a
=
2
},
'𐀀'
,
}
for
i
=
1
,
#
strs
do
local
str
,
obj
=
strs
[
i
],
objs
[
i
]
local
obj_
,
pos
=
json
.
decode
(
str
)
assert
(
compare
(
obj
,
obj_
))
assert
(
pos
==
#
str
+
1
)
end
-- Errors
assert
(
not
pcall
(
json
.
encode
,
setmetatable
({},
{})))
-- Table with metatable
assert
(
not
pcall
(
json
.
encode
,
setmetatable
({},
{
__toJSON
=
function
(
t
)
return
{
t
=
t
}
end
})))
-- Recursion
assert
(
not
pcall
(
json
.
encode
,
setmetatable
({},
{
__toJSON
=
function
(
t
)
t
()
end
})))
-- Run-time error
assert
(
not
pcall
(
json
.
encode
,
{
a
=
print
}))
-- Invalid value
assert
(
not
pcall
(
json
.
encode
,
{[
print
]
=
1
}))
-- Invalid key
assert
(
not
pcall
(
json
.
decode
,
'"\\ud800\\uDBFF"'
))
-- Invalid UTF-16 surrogate
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment