From: Vsevolod Stakhov Date: Wed, 4 Mar 2015 16:01:14 +0000 (+0000) Subject: Add unit test for lua regexp. X-Git-Tag: 0.9.0~565 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7b00e0c737ca83763135b4e212c0b59b0610ac3f;p=rspamd.git Add unit test for lua regexp. --- 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