commit f017ace: [Minor] Fix unique to work with iterators, add tests

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Jun 24 12:28:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-06-24 13:23:42 +0100
URL: https://github.com/rspamd/rspamd/commit/f017ace89a8f499d7ce206e9d93636420915f6ae (HEAD -> master)

[Minor] Fix unique to work with iterators, add tests

---
 lualib/lua_selectors.lua    |  6 +++---
 test/lua/unit/selectors.lua | 49 +++++++++++++++++++++++++++++++++------------
 2 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua
index 15777fc11..3bc7b9d75 100644
--- a/lualib/lua_selectors.lua
+++ b/lualib/lua_selectors.lua
@@ -441,9 +441,9 @@ local transform_function = {
     },
     ['process'] = function(inp, t, _)
       local tmp = {}
-      for _,val in ipairs(inp) do
-        tmp[val] = true
-      end
+      fun.each(function(val)
+         tmp[val] = true
+      end, inp)
 
       return fun.map(function(k, _) return k end, tmp), t
     end,
diff --git a/test/lua/unit/selectors.lua b/test/lua/unit/selectors.lua
index 2c2ebfb5b..be77454e5 100644
--- a/test/lua/unit/selectors.lua
+++ b/test/lua/unit/selectors.lua
@@ -33,11 +33,13 @@ context("Selectors test", function()
   local cases = {
     ["ip"] = {
                 selector = "ip",
-                expect = {"198.172.22.91"}},
+                expect = {"198.172.22.91"}
+    },
 
     ["header Subject"] = {
                 selector = "header(Subject)",
-                expect = {"Second, lower-cased header subject"}},
+                expect = {"Second, lower-cased header subject"}
+    },
 
     ["header Subject lower"] = {
                 selector = "header(Subject).lower",
@@ -45,47 +47,68 @@ context("Selectors test", function()
 
     ["header full Subject lower"] = {
                 selector = "header(Subject, 'full').lower",
-                expect = {{"second, lower-cased header subject", "test subject"}}},
+                expect = {{"second, lower-cased header subject", "test subject"}}
+    },
 
     ["header full strong Subject"] = {
                 selector = "header(Subject, 'full,strong')",
-                expect = {{"Test subject"}}},
+                expect = {{"Test subject"}}
+    },
 
     ["header full strong lower-cased Subject"] = {
                 selector = "header(subject, 'full,strong')",
-                expect = {{"Second, lower-cased header subject"}}},
+                expect = {{"Second, lower-cased header subject"}}
+    },
 
     ["digest"] = {
                 selector = "digest",
-                expect = {"c459a21bd1f33fb4ba035481f46ef0c7"}},
+                expect = {"c459a21bd1f33fb4ba035481f46ef0c7"}
+    },
 
     ["user"] = {
                 selector = "user",
-                expect = {"cool user name"}},
+                expect = {"cool user name"}
+    },
 
     ["from"] = {
                 selector = "from",
-                expect = {"whoknows at nowhere.com"}},
+                expect = {"whoknows at nowhere.com"}
+    },
 
     ["rcpts"] = {
                 selector = "rcpts",
-                expect = {{"nobody at example.com", "no-one at example.com"}}},
+                expect = {{"nobody at example.com", "no-one at example.com"}}
+    },
 
     ["1st rcpts"] = {
                 selector = "rcpts.nth(1)",
-                expect = {"nobody at example.com"}},
+                expect = {"nobody at example.com"}
+    },
 
     ["lower rcpts"] = {
                 selector = "rcpts.lower.first",
-                expect = {"nobody at example.com"}},
+                expect = {"nobody at example.com"}
+    },
 
     ["first rcpts"] = {
                 selector = "rcpts.first",
-                expect = {"nobody at example.com"}},
+                expect = {"nobody at example.com"}
+    },
 
     ["first addr rcpts"] = {
                 selector = "rcpts:addr.first",
-                expect = {"nobody at example.com"}},
+                expect = {"nobody at example.com"}
+    },
+
+    ["rcpts_uniq_domains"] = {
+      selector = "rcpts:domain.uniq",
+      expect = {{"example.com"}}
+    },
+
+    ["rcpts_sorted"] = {
+      selector = "rcpts:addr.sort",
+      expect = {{"nobody at example.com", "no-one at example.com"}}
+    },
 
     ["to"] = {
                 selector = "to",


More information about the Commits mailing list