Skip to content

Commit

Permalink
Fix issue with mv and certain patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
DrChainsaw committed Feb 15, 2021
1 parent 53a5aaf commit f88746f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tree-ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ function _combine(cs, combine)
for c in cs
prev = get(seen, name(c), nothing)
if prev !== nothing
out[end] = apply_combine(combine, c, out[end])
out[prev] = apply_combine(combine, out[prev], c)
else
push!(out, c)
seen[name(c)] = c
seen[name(c)] = length(out)
end
end
map(identity, out)
Expand Down
10 changes: 10 additions & 0 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ import FileTrees: attach
@test isconsistent(t6)

@test isequal(t6, merge(t1, t5))

@testset "combine" begin
tcombine = maketree(["a" => [(name="y", value="ay"), (name ="x", value="ax")], "b" => [(name ="x", value="bx"), (name="y", value="by")]])
tcombined = mv(tcombine, r"^([^/]*)/([x|y])", s"\2"; combine=(v1,v2) -> v1 * "_" * v2)

@test tcombined["x"][] == "ax_bx"
@test tcombined["y"][] == "ay_by"
# Also test that we maintained the same order as the first encountered node
@test name.(children(tcombined)) == ["y", "x"]
end
end

@testset "values" begin
Expand Down

0 comments on commit f88746f

Please sign in to comment.