aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/unit/regxep.lua
blob: 5329fece2f63ce356a171c6da062f093ddee448d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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], string.format("'%s' doesn't match with '%s'",
        c[2], c[1]))
    end
  end)
  end
)