From f017ace89a8f499d7ce206e9d93636420915f6ae Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 24 Jun 2019 13:23:42 +0100 Subject: [PATCH] [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@nowhere.com"}}, + expect = {"whoknows@nowhere.com"} + }, ["rcpts"] = { selector = "rcpts", - expect = {{"nobody@example.com", "no-one@example.com"}}}, + expect = {{"nobody@example.com", "no-one@example.com"}} + }, ["1st rcpts"] = { selector = "rcpts.nth(1)", - expect = {"nobody@example.com"}}, + expect = {"nobody@example.com"} + }, ["lower rcpts"] = { selector = "rcpts.lower.first", - expect = {"nobody@example.com"}}, + expect = {"nobody@example.com"} + }, ["first rcpts"] = { selector = "rcpts.first", - expect = {"nobody@example.com"}}, + expect = {"nobody@example.com"} + }, ["first addr rcpts"] = { selector = "rcpts:addr.first", - expect = {"nobody@example.com"}}, + expect = {"nobody@example.com"} + }, + + ["rcpts_uniq_domains"] = { + selector = "rcpts:domain.uniq", + expect = {{"example.com"}} + }, + + ["rcpts_sorted"] = { + selector = "rcpts:addr.sort", + expect = {{"nobody@example.com", "no-one@example.com"}} + }, ["to"] = { selector = "to", -- 2.39.5