From: Vsevolod Stakhov Date: Sat, 23 Apr 2016 14:27:03 +0000 (+0100) Subject: [Test] Fix unit tests X-Git-Tag: 1.3.0~651 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=88b2b5b24f1b70be17a1ede3d70fd4b96959d569;p=rspamd.git [Test] Fix unit tests --- diff --git a/test/lua/unit/regxep.lua b/test/lua/unit/regxep.lua index 0bb4db935..a27e7b363 100644 --- a/test/lua/unit/regxep.lua +++ b/test/lua/unit/regxep.lua @@ -9,13 +9,13 @@ context("Regexp unit tests", function() end) test("Regexp match", function() local cases = { + {'/Тест/iu', 'тест', true}, {'/test$/m', '123test', true}, {'/^test$/m', '123test', false}, {'m,test,', 'test', true}, {'m,test,', 'test123', false}, {'m{https?://[^/?\\s]+?:\\d+(?/r', 'some', true}, -- Cyrillic utf8 letter diff --git a/test/lua/unit/sqlite3.lua b/test/lua/unit/sqlite3.lua index 9fec2b694..15dc3d3fb 100644 --- a/test/lua/unit/sqlite3.lua +++ b/test/lua/unit/sqlite3.lua @@ -41,7 +41,7 @@ context("Sqlite3 API", function() assert_true(ret, "should be able to insert row") for row in db:rows([[SELECT * FROM x;]]) do - assert_equal(row.id, 1) + assert_equal(row.id, '1') assert_equal(row.value, 'test') end os.remove('/tmp/rspamd_unit_test_sqlite3-2.sqlite') diff --git a/test/lua/unit/trie.lua b/test/lua/unit/trie.lua index 5191d9e26..e37d40e36 100644 --- a/test/lua/unit/trie.lua +++ b/test/lua/unit/trie.lua @@ -2,7 +2,8 @@ context("Trie search functions", function() local t = require "rspamd_trie" - + local logger = require "rspamd_logger" + test("Trie search", function() local patterns = { 'test', @@ -11,47 +12,52 @@ context("Trie search functions", function() 'she', 'str\0ing' } - + local trie = t.create(patterns) assert_not_nil(trie, "cannot create trie") - + local cases = { {'test', true, {{4, 1}, {4, 2}}}, {'she test test', true, {{3, 4}, {3, 3}, {8, 1}, {8, 2}, {13, 1}, {13, 2}}}, {'non-existent', false}, {'str\0ing test', true, {{7, 5}, {12, 1}, {12, 2}}}, } - + local function comparetables(t1, t2) if #t1 ~= #t2 then return false end for i=1,#t1 do if type(t1[i]) ~= type(t2[i]) then return false elseif type(t1[i]) == 'table' then if not comparetables(t1[i], t2[i]) then return false end - elseif t1[i] ~= t2[i] then - return false + elseif t1[i] ~= t2[i] then + return false end end return true end - + for _,c in ipairs(cases) do local res = {} local function cb(idx, pos) table.insert(res, {pos, idx}) - + return 0 end - + ret = trie:match(c[1], cb) - + assert_equal(c[2], ret, tostring(c[2]) .. ' while matching ' .. c[1]) - + if ret then + table.sort(res, function(a, b) return a[2] > b[2] end) + table.sort(c[3], function(a, b) return a[2] > b[2] end) local cmp = comparetables(res, c[3]) - assert_true(cmp, 'valid results for case: ' .. c[1]) + assert_true(cmp, 'valid results for case: ' .. c[1] .. + ' got: ' .. logger.slog('%s', res) .. ' expected: ' .. + logger.slog('%s', c[3]) + ) end end - + end) -end) \ No newline at end of file +end) diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua index 0b385c063..06082afe0 100644 --- a/test/lua/unit/url.lua +++ b/test/lua/unit/url.lua @@ -18,6 +18,8 @@ context("URL check functions", function() local pool = mpool.create() local cases = { {"test.com text", {"test.com", nil}}, + {" test.com text", {"test.com", nil}}, + {" text", {"test.com", nil}}, {"test.com. text", {"test.com", nil}}, {"mailto:A.User@example.com text", {"example.com", "A.User"}}, {"http://Тест.Рф:18 text", {"тест.рф", nil}}, @@ -60,6 +62,11 @@ context("URL check functions", function() host = 'www.google.com', path = 'foo', query = 'bar=baz', tld = 'google.com' }}, {"http://[www.google.com]/", false}, + {"", false}, + {",test.com text", false}, {"ht\ttp:@www.google.com:80/;p?#", false}, {"http://user:pass@/", false}, {"http://foo:-80/", false},