aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/unit
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-08-16 13:25:41 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-08-16 13:25:41 +0100
commit089746e704a325bf429dcb1e7caa554253c47063 (patch)
tree1a51edbb7c677cd834a9a4516fb481994afa69d6 /test/lua/unit
parent05ea03c3b2cd36a35996e8dc0c59a6b1d0659df4 (diff)
downloadrspamd-089746e704a325bf429dcb1e7caa554253c47063.tar.gz
rspamd-089746e704a325bf429dcb1e7caa554253c47063.zip
[Test] Add more unit tests
Diffstat (limited to 'test/lua/unit')
-rw-r--r--test/lua/unit/ucl.lua35
1 files changed, 25 insertions, 10 deletions
diff --git a/test/lua/unit/ucl.lua b/test/lua/unit/ucl.lua
index 9bbf7225c..1b975d390 100644
--- a/test/lua/unit/ucl.lua
+++ b/test/lua/unit/ucl.lua
@@ -3,13 +3,17 @@
context("UCL manipulation", function()
local ucl = require "ucl"
- test("UCL transparent test", function()
- local parser = ucl.parser()
- local res, err = parser:parse_string('{"key":"val"}')
- assert(res)
+ local parser = ucl.parser()
+ local res, err = parser:parse_string('{"key":"val"}')
+ assert(res)
- local reply = parser:get_object_wrapped()
+ local reply = parser:get_object_wrapped()
+ local expected = {
+ key = 'ohlol',
+ ololo = 'ohlol'
+ }
+ test("UCL transparent test: object", function()
assert_equal(tostring(reply), '{"key":"val"}')
assert_equal(reply:type(), 'object')
assert_equal(reply:at('key'):unwrap(), 'val')
@@ -17,14 +21,13 @@ context("UCL manipulation", function()
reply.ololo = 'ohlol'
reply.key = 'ohlol'
assert_equal(reply:at('key'):unwrap(), 'ohlol')
- local expected = {
- key = 'ohlol',
- ololo = 'ohlol'
- }
+
for k, v in reply:pairs() do
assert_equal(expected[k], v:unwrap())
end
+ end)
+ test("UCL transparent test: array", function()
parser = ucl.parser()
res, err = parser:parse_string('["e1","e2"]')
assert(res)
@@ -42,7 +45,9 @@ context("UCL manipulation", function()
for k, v in ireply:ipairs() do
assert_equal(v:unwrap(), iexpected[k])
end
+ end)
+ test("UCL transparent test: concat", function()
reply.tbl = ireply
expected.tbl = iexpected
for k, v in reply:pairs() do
@@ -54,7 +59,17 @@ context("UCL manipulation", function()
assert_equal(expected[k], v:unwrap())
end
end
+ end)
- collectgarbage() -- To ensure we don't crash with asan
+ test("UCL transparent test: implicit conversion array->object", function()
+ -- Assign empty table, so it'll be an array
+ reply.t = {}
+ assert_equal(reply.t:type(), 'array')
+ -- We can convert empty table to object
+ reply.t.test = 'test'
+ assert_equal(reply.t:type(), 'object')
+ assert_equal(reply.t.test:unwrap(), 'test')
end)
+
+ collectgarbage() -- To ensure we don't crash with asan
end) \ No newline at end of file