aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMiecio Za <miecio@miecio.net>2019-03-18 14:06:56 +0100
committerMiecio Za <miecio@miecio.net>2019-03-18 14:06:56 +0100
commitcd08c8845f6ea0bac789ea8a49f7d8537f598b7d (patch)
treedee0d9dbc67008cd190c502393098c5f2772a764 /test
parent7160b4ace6665d808b636b0617f081f51a849617 (diff)
downloadrspamd-cd08c8845f6ea0bac789ea8a49f7d8537f598b7d.tar.gz
rspamd-cd08c8845f6ea0bac789ea8a49f7d8537f598b7d.zip
[Minor] Fix performance issue with is_utf_outside_range
Fix performace issue, add some checking and add few tests
Diffstat (limited to 'test')
-rw-r--r--test/lua/unit/rspamd_util.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/lua/unit/rspamd_util.lua b/test/lua/unit/rspamd_util.lua
new file mode 100644
index 000000000..802b400d2
--- /dev/null
+++ b/test/lua/unit/rspamd_util.lua
@@ -0,0 +1,67 @@
+context("Rspamd util for lua - check generic functions", function()
+ local util = require 'rspamd_util'
+
+ local cases = {
+ {
+ input = "test1",
+ result = false,
+ range_start = 0x0000,
+ range_end = 0x017f
+ },
+ {
+ input = "test test xxx",
+ result = false,
+ range_start = 0x0000,
+ range_end = 0x017f
+ },
+ {
+ input = "АбЫрвАлг",
+ result = true,
+ range_start = 0x0000,
+ range_end = 0x017f
+ },
+ {
+ input = "АбЫрвАлг example",
+ result = true,
+ range_start = 0x0000,
+ range_end = 0x017f
+ },
+ {
+ input = "example ąłśćżłóę",
+ result = false,
+ range_start = 0x0000,
+ range_end = 0x017f
+ },
+ {
+ input = "ąłśćżłóę АбЫрвАлг",
+ result = true,
+ range_start = 0x0000,
+ range_end = 0x017f
+ },
+ }
+
+ for i,c in ipairs(cases) do
+ test("is_utf_outside_range, test case #" .. i, function()
+ local actual = util.is_utf_outside_range(c.input, c.range_start, c.range_end)
+
+ assert_equal(c.result, actual)
+ end)
+ end
+
+ test("is_utf_outside_range, check cache", function ()
+ cache_size = 20
+ for i = 1,cache_size do
+ local res = util.is_utf_outside_range("a", 0x0000, 0x0000+i)
+ end
+ end)
+
+ test("is_utf_outside_range, check empty string", function ()
+ assert_error(util.is_utf_outside_range)
+ end)
+
+ test("get_string_stats, test case", function()
+ local res = util.get_string_stats("this is test 99")
+ assert_equal(res["letters"], 10)
+ assert_equal(res["digits"], 2)
+ end)
+end)