aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/unit/rspamd_text.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-11-16 19:23:17 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-11-16 19:23:17 +0000
commitbae168a884609d7b4dd964fab725416074d92836 (patch)
treef05463cc0e9dd41de889e15dc2f5de0c659260f1 /test/lua/unit/rspamd_text.lua
parentae73d813970522f5f3de5399ddde0f1f367c9479 (diff)
downloadrspamd-bae168a884609d7b4dd964fab725416074d92836.tar.gz
rspamd-bae168a884609d7b4dd964fab725416074d92836.zip
[Test] Add some tests for rspamd_text:find
Diffstat (limited to 'test/lua/unit/rspamd_text.lua')
-rw-r--r--test/lua/unit/rspamd_text.lua46
1 files changed, 45 insertions, 1 deletions
diff --git a/test/lua/unit/rspamd_text.lua b/test/lua/unit/rspamd_text.lua
index 269b49150..4e3a5e8e7 100644
--- a/test/lua/unit/rspamd_text.lua
+++ b/test/lua/unit/rspamd_text.lua
@@ -1,5 +1,4 @@
context("Rspamd_text:byte() test", function()
- local lua_util = require "lua_util"
local rspamd_text = require "rspamd_text"
local str = 'OMG'
@@ -28,3 +27,48 @@ context("Rspamd_text:byte() test", function()
end)
end
end)
+
+context("Rspamd_text:find() test", function()
+ local rspamd_text = require "rspamd_text"
+
+ local cases = {
+ {{'foobarfoo', 'f'}, {1, 1}},
+ {{'foobarfoo', 'foo'}, {1, 3}},
+ {{'foobarfoo', 'bar'}, {4, 6}},
+ {{'foobarfoo', 'baz'}, nil},
+ {{'foobarfoo', 'rfoo'}, {6, 9}},
+ }
+
+ for _, case in ipairs(cases) do
+ local name = string.format('case rspamd_text:find(%s,%s)', case[1][1], case[1][2])
+ test(name, function()
+ local t = rspamd_text.fromstring(case[1][1])
+ local s,e = t:find(case[1][2])
+
+ if case[2] then
+ assert_rspamd_table_eq({
+ expect = case[2],
+ actual = {s, e}
+ })
+ else
+ assert_nil(s)
+ end
+ local ss,ee = string.find(case[1][1], case[1][2], 1, true)
+ assert_rspamd_table_eq({
+ expect = { ss, ee },
+ actual = { s, e }
+ })
+ end)
+ -- Compare with vanila lua
+ name = string.format('case lua string vs rspamd_text:find(%s,%s)', case[1][1], case[1][2])
+ test(name, function()
+ local t = rspamd_text.fromstring(case[1][1])
+ local s,e = t:find(case[1][2])
+ local ss,ee = string.find(case[1][1], case[1][2], 1, true)
+ assert_rspamd_table_eq({
+ expect = { ss, ee },
+ actual = { s, e }
+ })
+ end)
+ end
+end)