diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-19 13:47:31 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-19 13:47:55 +0000 |
commit | aa8fc9d9a9f35237d2870aa081f43621d3bc78ae (patch) | |
tree | ba1ed2c6021bc8511e5e0379403114ba282ca69c /test/lua | |
parent | d0be293f26243092063612fe28f064415f8fc7ff (diff) | |
download | rspamd-aa8fc9d9a9f35237d2870aa081f43621d3bc78ae.tar.gz rspamd-aa8fc9d9a9f35237d2870aa081f43621d3bc78ae.zip |
Add unit tests for expressions processing.
Diffstat (limited to 'test/lua')
-rw-r--r-- | test/lua/unit/expressions.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/lua/unit/expressions.lua b/test/lua/unit/expressions.lua index 7e6310e04..257768618 100644 --- a/test/lua/unit/expressions.lua +++ b/test/lua/unit/expressions.lua @@ -57,4 +57,42 @@ context("Rspamd expressions", function() -- Expression is destroyed when the corresponding pool is destroyed pool:destroy() 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, + B = false, + C = true, + D = false, + E = true, + F = false, + } + local cases = { + {'A & B | !C', 0}, + {'A & (!B | C)', 1}, + {'A + B + C + D + E + F >= 2', 1}, + {'((A + B + C + D) > 1) & F', 0}, + {'!!C', 1}, + } + for _,c in ipairs(cases) do + local expr,err = rspamd_expression.create(c[1], + {parse_func, process_func}, pool) + + assert_not_nil(expr, "Cannot parse " .. c[1]) + res = expr:process(atoms) + 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 |