diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lua/unit/regxep.lua | 31 |
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 |