diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-06-30 13:43:11 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-06-30 13:43:11 +0100 |
commit | abbfcd0c515cfa0cd85ec3c87236f899a47c5f16 (patch) | |
tree | 78c989b96f9b1026829d72de4ee6bd2dd12316e4 /test | |
parent | c17f742da32e8bc216991a70a5eded31d6cefd87 (diff) | |
download | rspamd-abbfcd0c515cfa0cd85ec3c87236f899a47c5f16.tar.gz rspamd-abbfcd0c515cfa0cd85ec3c87236f899a47c5f16.zip |
Add captures unit test.
Diffstat (limited to 'test')
-rw-r--r-- | test/lua/unit/regxep.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/lua/unit/regxep.lua b/test/lua/unit/regxep.lua index 3aca6c7ba..8ee26be07 100644 --- a/test/lua/unit/regxep.lua +++ b/test/lua/unit/regxep.lua @@ -32,6 +32,26 @@ context("Regexp unit tests", function() end end) + test("Regexp capture", function() + local cases = { + {'Body=(\\S+)(?: Fuz1=(\\S+))?(?: Fuz2=(\\S+))?', + 'mc-filter4 1120; Body=1 Fuz1=1 Fuz2=1', + {'Body=1 Fuz1=1 Fuz2=1', '1', '1', '1'}} + } + for _,c in ipairs(cases) do + local r = re.create_cached(c[1]) + assert_not_nil(r, "cannot parse " .. c[1]) + local res = r:search(c[2], false, true) + + assert_not_nil(res, "cannot find pattern") + + for n,m in ipairs(res[1]) do + assert_equal(m, c[3][n], string.format("'%s' doesn't match with '%s'", + c[3][n], c[1])) + end + end + end) + test("Regexp split", function() local cases = { {'\\s', 'one', {'one'}}, -- one arg |