diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-06 13:59:07 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-06 13:59:07 +0000 |
commit | 9bc218c25f142a973206869d57275f3cae9a2184 (patch) | |
tree | 10f4a2abcba2f89dba64b8e2d4d39b84f0c6b79a /test/lua | |
parent | 453645aa3766bd1e5df8d9bb076f78bf3604e1d8 (diff) | |
download | rspamd-9bc218c25f142a973206869d57275f3cae9a2184.tar.gz rspamd-9bc218c25f142a973206869d57275f3cae9a2184.zip |
Implement lua regexp split, write test case.
Diffstat (limited to 'test/lua')
-rw-r--r-- | test/lua/unit/regxep.lua | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/test/lua/unit/regxep.lua b/test/lua/unit/regxep.lua index 81234ddb6..1277cce11 100644 --- a/test/lua/unit/regxep.lua +++ b/test/lua/unit/regxep.lua @@ -19,12 +19,35 @@ context("Regexp unit tests", function() for _,c in ipairs(cases) do local r = re.create_cached(c[1]) - assert_not_nil(r) + assert_not_nil(r, "cannot parse " .. c[1]) local res = r:match(c[2]) assert_equal(res, c[3], string.format("'%s' doesn't match with '%s'", c[2], c[1])) end end) + + test("Regexp split", function() + local cases = { + {'\\s', 'one two', {'one', 'two'}}, -- trivial + {'\\s', 'one two', {'one', 'two'}}, -- multiple delimiters + {'\\s', ' one two ', {'one', 'two'}}, -- multiple delimiters + {'\\s', ' one ', {'one', 'two'}}, -- multiple delimiters + {'[:,]', ',,,:::one,two,,', {'one', 'two'}}, -- multiple delimiters + } + + for _,c in ipairs(cases) do + local r = re.create_cached(c[1]) + assert_not_nil(r, "cannot parse " .. c[1]) + + local res = r:split(c[2]) + assert_not_nil(res, "cannot split " .. c[2]) + + for i,r in ipairs(res) do + assert_equal(r, c[3][i]) + end + end + end) + end )
\ No newline at end of file |