aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-17 23:29:27 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-17 23:29:49 +0000
commit29a5425adb186ac73ec2b7b436cb9e87be762adb (patch)
tree110aefcee0fcb10b8c8bf6d4dd18b353d3b8c98d /test/lua
parenta6e30390f384a5dd6446542436d45fd983af565b (diff)
downloadrspamd-29a5425adb186ac73ec2b7b436cb9e87be762adb.tar.gz
rspamd-29a5425adb186ac73ec2b7b436cb9e87be762adb.zip
Fix more issues in expressions parser.
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/unit/expressions.lua16
1 files changed, 11 insertions, 5 deletions
diff --git a/test/lua/unit/expressions.lua b/test/lua/unit/expressions.lua
index 4c6c55f7d..f191019e6 100644
--- a/test/lua/unit/expressions.lua
+++ b/test/lua/unit/expressions.lua
@@ -4,11 +4,15 @@ context("Rspamd expressions", function()
local rspamd_expression = require "rspamd_expression"
local rspamd_mempool = require "rspamd_mempool"
local rspamd_regexp = require "rspamd_regexp"
- local split_re = rspamd_regexp.create('/\\s+/')
+ local split_re = rspamd_regexp.create('/\\s+|\\)|\\(/')
local function parse_func(str)
-- extract token till the first space character
- local token = split_re:split(str)[1]
+ local token = str
+ local t = split_re:split(str)
+ if t then
+ token = t[1]
+ end
-- Return token name
return token
end
@@ -21,15 +25,17 @@ context("Rspamd expressions", function()
local pool = rspamd_mempool.create()
local cases = {
- {'A & B | !C', 'A B & C ! |'}
+ {'A & B | !C', 'A B & C ! |'},
+ {'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_nil(expr, "Cannot parse " .. c[1] ": " .. err)
+ if not c[2] then
+ assert_nil(expr, "Should not be able to parse " .. c[1])
else
+ assert_not_nil(expr, "Cannot parse " .. c[1])
assert_equal(expr:to_string(), c[2], string.format("Evaluated expr to '%s', expected: '%s'",
expr:to_string(), c[2]))
end