diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-05 14:04:00 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-05 14:04:00 +0100 |
commit | bd5a342c6a3dd0857d0392865624e49ce179c5e9 (patch) | |
tree | b763508c4e57d3fe319d2599c1584e1d4a0bf44c | |
parent | 5eb5732198350416bbab04b80b371f9b390c5a37 (diff) | |
download | rspamd-bd5a342c6a3dd0857d0392865624e49ce179c5e9.tar.gz rspamd-bd5a342c6a3dd0857d0392865624e49ce179c5e9.zip |
[Test] Add unit tests for trie table version
-rw-r--r-- | test/lua/unit/trie.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/lua/unit/trie.lua b/test/lua/unit/trie.lua index 3731a713c..22b872df8 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) |