Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
jobs:
tests:
name: Tests
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
Comment thread
jarvis9443 marked this conversation as resolved.
matrix:
Expand Down
3 changes: 2 additions & 1 deletion lib/resty/simdjson/decoder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local _MT = { __index = _M, }
local ffi = require("ffi")
local table_new = require("table.new")
local C = require("resty.simdjson.cdefs")
local cjson_array_mt = require("cjson").array_mt


local type = type
Expand Down Expand Up @@ -110,7 +111,7 @@ function _M:_build_array(count)

local err
local n = 1
local tbl = table_new(count, 0)
local tbl = setmetatable(table_new(count, 0), cjson_array_mt)
local ops = self.ops
local yieldable = self.yieldable

Expand Down
15 changes: 12 additions & 3 deletions t/02-decode.t
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,36 @@ ok
--- config
location = /t {
content_by_lua_block {
local cjson = require("cjson")
local simdjson = require("resty.simdjson")

local parser = simdjson.new()
assert(parser)

local v = parser:decode("[1, 2, 3]")
assert(type(v) == "table")
assert(getmetatable(v) == cjson.array_mt)
assert(#v == 3)
assert(v[1] == 1 and v[2] == 2 and v[3] == 3)

local v = parser:decode("[true, 2, \"abc\"]")
assert(type(v) == "table")
assert(getmetatable(v) == cjson.array_mt)
assert(#v == 3)
assert(v[1] == true and v[2] == 2 and v[3] == "abc")

local v = parser:decode("[1, null, 3]")
assert(type(v) == "table")
assert(getmetatable(v) == cjson.array_mt)
assert(#v == 3)
assert(v[1] == 1 and v[2] == ngx.null and v[3] == 3)

local v = parser:decode("[[1], []]")
assert(type(v) == "table")
assert(getmetatable(v) == cjson.array_mt)
assert(getmetatable(v[1]) == cjson.array_mt)
assert(getmetatable(v[2]) == cjson.array_mt)

ngx.say("ok")
}
}
Expand All @@ -198,13 +208,15 @@ ok
--- config
location = /t {
content_by_lua_block {
local cjson = require("cjson")
local simdjson = require("resty.simdjson")

local parser = simdjson.new()
assert(parser)

local v = parser:decode([[{"a":1, "b":true, "c":"string"}]])
assert(type(v) == "table")
assert(getmetatable(v) ~= cjson.array_mt)
assert(v.a == 1 and v.b == true and v.c == "string")

local v = parser:decode([[{"a":1.0, "b":null, "c":false}]])
Expand Down Expand Up @@ -459,6 +471,3 @@ simdjson: error: STRING_ERROR: Problem while parsing a string
[error]
[warn]
[crit]



47 changes: 42 additions & 5 deletions t/09-empty_array.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,47 @@ ok



=== TEST 2: cjson empty_array userdata
=== TEST 2: cjson encode decoded empty array
--- http_config eval: $::HttpConfig
--- config
location = /t {
content_by_lua_block {
local cjson = require("cjson")
local simdjson = require("resty.simdjson")

local parser = simdjson.new()
assert(parser)

local v = parser:decode("[]")
assert(type(v) == "table")
assert(getmetatable(v) == cjson.array_mt)
assert(cjson.encode(v) == "[]")

local v = parser:decode([[{"arr":[]}]])
assert(type(v) == "table")
assert(getmetatable(v.arr) == cjson.array_mt)
assert(cjson.encode(v) == [[{"arr":[]}]])

local v = parser:decode("{}")
assert(type(v) == "table")
assert(getmetatable(v) ~= cjson.array_mt)
assert(cjson.encode(v) == "{}")

ngx.say("ok")
}
}
--- request
GET /t
--- response_body
ok
--- no_error_log
[error]
[warn]
[crit]



=== TEST 3: cjson empty_array userdata
--- http_config eval: $::HttpConfig
--- config
location = /t {
Expand Down Expand Up @@ -83,7 +123,7 @@ ok



=== TEST 3: cjson empty_array_mt
=== TEST 4: cjson empty_array_mt
--- http_config eval: $::HttpConfig
--- config
location = /t {
Expand All @@ -110,6 +150,3 @@ ok
[error]
[warn]
[crit]



Loading