commit bd5a342: [Test] Add unit tests for trie table version

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Sep 5 14:35:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-05 14:04:00 +0100
URL: https://github.com/rspamd/rspamd/commit/bd5a342c6a3dd0857d0392865624e49ce179c5e9

[Test] Add unit tests for trie table version

---
 test/lua/unit/trie.lua | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

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)


More information about the Commits mailing list