diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-04 15:54:02 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-04 15:54:02 +0000 |
commit | babc0280dbbf7331d0c2a132a825905e403431bb (patch) | |
tree | 6b07ea30355520618ea076271eaad30077a44e3c /test | |
parent | acdbb7f65d72f038568e3e092558a8bcb7afdace (diff) | |
download | rspamd-babc0280dbbf7331d0c2a132a825905e403431bb.tar.gz rspamd-babc0280dbbf7331d0c2a132a825905e403431bb.zip |
Init re cache on config post load
Diffstat (limited to 'test')
-rw-r--r-- | test/lua/unit/expressions.lua | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/test/lua/unit/expressions.lua b/test/lua/unit/expressions.lua index b2e66e8cc..a9d4ac2ea 100644 --- a/test/lua/unit/expressions.lua +++ b/test/lua/unit/expressions.lua @@ -5,7 +5,7 @@ context("Rspamd expressions", function() local rspamd_mempool = require "rspamd_mempool" local rspamd_regexp = require "rspamd_regexp" local split_re = rspamd_regexp.create('/\\s+|\\)|\\(/') - + local function parse_func(str) -- extract token till the first space character local token = str @@ -16,20 +16,22 @@ context("Rspamd expressions", function() -- Return token name return token end - + test("Expression creation function", function() local function process_func(token, task) -- Do something using token and task end - + local pool = rspamd_mempool.create() - + local cases = { {'A & B | !C', 'C ! A B & |'}, {'A & (B | !C)', 'A B C ! | &'}, {'A & B &', nil}, -- Unbalanced braces {'(((A))', nil}, + -- Invalid data + {'1.0001', nil}, -- Balanced braces {'(((A)))', 'A'}, -- Plus and comparision operators @@ -44,9 +46,9 @@ context("Rspamd expressions", function() {'A & B | ! C', 'C ! A B & |'}, } for _,c in ipairs(cases) do - local expr,err = rspamd_expression.create(c[1], + local expr,err = rspamd_expression.create(c[1], {parse_func, process_func}, pool) - + if not c[2] then assert_nil(expr, "Should not be able to parse " .. c[1]) else @@ -60,14 +62,14 @@ context("Rspamd expressions", function() end) test("Expression process function", function() local function process_func(token, input) - + --print(token) local t = input[token] - + if t then return 1 end return 0 end - + local pool = rspamd_mempool.create() local atoms = { A = true, @@ -89,7 +91,7 @@ context("Rspamd expressions", function() {'!!C', 1}, } for _,c in ipairs(cases) do - local expr,err = rspamd_expression.create(c[1], + local expr,err = rspamd_expression.create(c[1], {parse_func, process_func}, pool) assert_not_nil(expr, "Cannot parse " .. c[1]) @@ -98,7 +100,7 @@ context("Rspamd expressions", function() assert_equal(res, c[2], string.format("Processed expr '%s' returned '%d', expected: '%d'", expr:to_string(), res, c[2])) end - + pool:destroy() end) -end)
\ No newline at end of file +end) |