From aa8fc9d9a9f35237d2870aa081f43621d3bc78ae Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 19 Mar 2015 13:47:31 +0000 Subject: [PATCH] Add unit tests for expressions processing. --- test/lua/unit/expressions.lua | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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 -- 2.39.5