Skip to content

Commit

Permalink
Merge pull request #889 from tdesveaux/fix-mergeFilters
Browse files Browse the repository at this point in the history
Fix context.mergeFilters
  • Loading branch information
tvandijck authored Apr 14, 2018
2 parents 776a4c9 + a8ad766 commit 6c7c6c7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/base/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@
--

function context.mergeFilters(ctx, src)
for k,v in pairs(src.terms) do
ctx.terms[k] = v
for k, v in pairs(src.terms) do
if k == "tags" then
ctx.terms[k] = table.join(ctx.terms[k], v)
else
ctx.terms[k] = v
end
end
end

Expand Down
38 changes: 38 additions & 0 deletions tests/base/test_context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,41 @@
-- detoken in extended context should result in value set in that environ.
test.isequal("text", ext.targetname)
end

--
-- mergeFilters should behave as expected for tags
--

function suite.mergeFilters()

ctx = { terms = { tags = { "ctxtags" } } }
src = { terms = { tags = { "srctags" } } }

context.mergeFilters(ctx, src)

result = { terms = { tags = { "ctxtags", "srctags" } } }

test.isequal(result, ctx)
end

function suite.mergeFilters_keeptype()

ctx = { terms = { kind = "ConsoleApp" } }
src = { terms = { kind = "ConsoleApp" } }

context.mergeFilters(ctx, src)

test.isequal("string", type(ctx.terms.kind))
end

function suite.mergeFilters_createtable()

ctx = { terms = { tags = "ctxtags" } }
src = { terms = { tags = "srctags" } }

context.mergeFilters(ctx, src)

result = { terms = { tags = { "ctxtags", "srctags" } } }

test.isequal(result, ctx)
end

0 comments on commit 6c7c6c7

Please sign in to comment.