aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-04 16:01:14 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-04 16:01:14 +0000
commit7b00e0c737ca83763135b4e212c0b59b0610ac3f (patch)
treee96c7894da3b87b2a97c786f80d323778d4fbf88 /test
parent49731817d10c29646a6eaec17a63fc63a1ce93c7 (diff)
downloadrspamd-7b00e0c737ca83763135b4e212c0b59b0610ac3f.tar.gz
rspamd-7b00e0c737ca83763135b4e212c0b59b0610ac3f.zip
Add unit test for lua regexp.
Diffstat (limited to 'test')
-rw-r--r--test/lua/unit/regxep.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/lua/unit/regxep.lua b/test/lua/unit/regxep.lua
new file mode 100644
index 000000000..f063efeda
--- /dev/null
+++ b/test/lua/unit/regxep.lua
@@ -0,0 +1,31 @@
+context("Regexp unit tests", function()
+ local re = require("rspamd_regexp")
+
+ test("Regexp creation", function()
+ assert_not_nil(re.create_cached('/test$/m'))
+ assert_not_nil(re.create_cached('^test$', 'm'))
+ assert_not_nil(re.create_cached('m,test,m'))
+ assert_not_nil(re.create_cached('m|test|m'))
+ end)
+ test("Regexp match", function()
+ local cases = {
+ {'/test$/m', '123test', true},
+ {'/^test$/m', '123test', false},
+ {'m,test,', 'test', true},
+ {'m,test,', 'test123', false},
+ {'/test/i', 'TeSt123', true},
+ {'/тест/i', 'ТесТ', true},
+ }
+
+ for _,c in ipairs(cases) do
+ local r = re.create_cached(c[1])
+ assert_not_nil(r)
+ local res = r:match(c[2])
+ local m = false
+ if res then m = true end
+
+ assert_equal(m, c[3])
+ end
+ end)
+ end
+) \ No newline at end of file