From: Vsevolod Stakhov Date: Thu, 5 Sep 2019 13:04:00 +0000 (+0100) Subject: [Test] Add unit tests for trie table version X-Git-Tag: 2.0~276 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bd5a342c6a3dd0857d0392865624e49ce179c5e9;p=thirdparty%2Frspamd.git [Test] Add unit tests for trie table version --- diff --git a/test/lua/unit/trie.lua b/test/lua/unit/trie.lua index 3731a713c8..22b872df86 100644 --- a/test/lua/unit/trie.lua +++ b/test/lua/unit/trie.lua @@ -58,4 +58,31 @@ context("Trie search functions", function() end) end + for i,c in ipairs(cases) do + test("Trie search, table version " .. i, function() + local match = {} + + match = trie:match(c[1]) + + assert_equal(c[2], #match > 0, tostring(c[2]) .. ' while matching ' .. c[1]) + + if match and #match > 0 then + local res = {} + -- Convert to something that this test expects + for pat,hits in pairs(match) do + for _,pos in ipairs(hits) do + table.insert(res, {pos, pat}) + end + end + 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] .. + ' got: ' .. logger.slog('%s', res) .. ' expected: ' .. + logger.slog('%s', c[3]) + ) + end + end) + end + end)