diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-17 17:25:24 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-17 17:25:24 +0000 |
commit | 48b97b59c59f6d5c32f905cdeb329c7019997be3 (patch) | |
tree | 376104f0fc0f15a29fcaf8d0faa842188235e07e /test | |
parent | 6f828fb18e6b6ab2407179027f7f6c1032c90463 (diff) | |
download | rspamd-48b97b59c59f6d5c32f905cdeb329c7019997be3.tar.gz rspamd-48b97b59c59f6d5c32f905cdeb329c7019997be3.zip |
Add lua unit test for expressions.
Diffstat (limited to 'test')
-rw-r--r-- | test/lua/unit/expressions.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/lua/unit/expressions.lua b/test/lua/unit/expressions.lua new file mode 100644 index 000000000..dc9cfd0cb --- /dev/null +++ b/test/lua/unit/expressions.lua @@ -0,0 +1,39 @@ +-- Expressions unit tests + +context("Rspamd expressions", function() + local rspamd_expression = require "rspamd_expression" + local rspamd_mempool = require "rspamd_mempool" + local _ = require "fun" + + local function parse_func(str) + -- extract token till the first space character + local token = table.join('', take_while(function(s) return s ~= ' ' end, str)) + -- 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', 'A B & C ! |'} + } + for _,c in ipairs(cases) do + local expr,err = rspamd_expression.create(c[1], + {parse_func, process_func}, pool) + + if c[2] then + assert_not_null(expr, "Cannot parse " .. c[1] ": " .. err) + else + assert_equal(expr:to_string(), c[2], string.format("Evaluated expr to '%s', expected: '%s'", + expr:to_string(), c[2])) + end + end + -- Expression is destroyed when the corresponding pool is destroyed + pool:destroy() + end) +end)
\ No newline at end of file |