aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-08-13 15:07:31 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-08-13 15:07:31 +0100
commit042490e8dc102635c02d2caeb195bddf83f58054 (patch)
treee9ab2a3d9cd63abd5e48686f5bf99ae517c84f1b /test
parent9ec9f02eb9fa2faf60873547a14b758240289398 (diff)
downloadrspamd-042490e8dc102635c02d2caeb195bddf83f58054.tar.gz
rspamd-042490e8dc102635c02d2caeb195bddf83f58054.zip
[Test] Add unit tests for ucl functions
Diffstat (limited to 'test')
-rw-r--r--test/lua/unit/ucl.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/lua/unit/ucl.lua b/test/lua/unit/ucl.lua
new file mode 100644
index 000000000..991afc979
--- /dev/null
+++ b/test/lua/unit/ucl.lua
@@ -0,0 +1,60 @@
+-- Test some UCL stuff
+
+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 reply = parser:get_object_wrapped()
+
+ assert_equal(tostring(reply), '{"key":"val"}')
+ assert_equal(reply:type(), 'object')
+ assert_equal(reply:at('key'):unwrap(), 'val')
+ reply.ololo = 'ohlol'
+ 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
+
+ parser = ucl.parser()
+ res, err = parser:parse_string('["e1","e2"]')
+ assert(res)
+ local ireply = parser:get_object_wrapped()
+
+ assert_equal(tostring(ireply), '["e1","e2"]')
+ assert_equal(ireply:type(), 'array')
+ ireply[1] = 1
+ ireply[1] = 1
+ ireply[1] = 1
+ ireply[1] = 1
+ ireply[1] = 1
+ ireply[#ireply + 1] = 100500
+ local iexpected = { 1, 1, 1, 1, 1, "e1", "e2", 100500 }
+ for k, v in ireply:ipairs() do
+ assert_equal(iexpected[k], v:unwrap())
+ end
+
+ reply.tbl = ireply
+ expected.tbl = iexpected
+ for k, v in reply:pairs() do
+ if type(expected[k]) == 'table' then
+ for kk, vv in v:ipairs() do
+ assert_equal(expected[k][kk], vv:unwrap())
+ end
+ else
+ assert_equal(expected[k], v:unwrap())
+ end
+ end
+
+ collectgarbage() -- To ensure we don't crash with asan
+ end)
+end) \ No newline at end of file