commit bae168a: [Test] Add some tests for rspamd_text:find
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Nov 16 19:28:07 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-11-16 19:23:17 +0000
URL: https://github.com/rspamd/rspamd/commit/bae168a884609d7b4dd964fab725416074d92836 (HEAD -> master)
[Test] Add some tests for rspamd_text:find
---
test/lua/unit/rspamd_text.lua | 46 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
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)
More information about the Commits
mailing list