Skip to content

Commit 40d3605

Browse files
authored
fix append!/prepend! for NodeChildren (#16)
1 parent 88bff68 commit 40d3605

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MarkdownAST"
22
uuid = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"
33
authors = ["Morten Piibeleht <morten.piibeleht@gmail.com> and contributors"]
4-
version = "0.1.0"
4+
version = "0.1.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/node.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ If any of `children` are part of another tree, then they are unlinked from that
418418
(see [JuliaLang/julia#15868](https://github.com/JuliaLang/julia/issues/15868)).
419419
"""
420420
function Base.append!(nodechildren::NodeChildren{T}, children) where T
421-
for child in children
421+
for child in collect(children)
422422
isa(child, T) || throw(ArgumentError("invalid element type ($(typeof(child))) in children, expected $T"))
423423
push!(nodechildren, child)
424424
end
@@ -440,7 +440,7 @@ If any of `children` are part of another tree, then they are unlinked from that
440440
(see [JuliaLang/julia#15868](https://github.com/JuliaLang/julia/issues/15868)).
441441
"""
442442
function Base.prepend!(nodechildren::NodeChildren{T}, children) where T
443-
for child in Iterators.reverse(children)
443+
for child in Iterators.reverse(collect(children))
444444
isa(child, T) || throw(ArgumentError("invalid element type ($(typeof(child))) in children, expected $T"))
445445
pushfirst!(nodechildren, child)
446446
end

test/node.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ _startswith(prefix) = s -> startswith(s, prefix)
207207
# test, but with a generic iterator
208208
@test append!(n.children, c for c in cs) isa NodeChildren
209209
@test typeof.(getproperty.(n.children, :element)) == [DisplayMath, DisplayMath, Paragraph, CodeBlock, BlockQuote]
210+
# test, but with elements from NodeChildren iterator
211+
n2 = @ast Document() do
212+
Heading(1)
213+
end
214+
@test append!(n2.children, n.children) isa NodeChildren
215+
@test typeof.(getproperty.(n2.children, :element)) == [Heading, DisplayMath, DisplayMath, Paragraph, CodeBlock, BlockQuote]
216+
@test isempty(n.children)
217+
n3 = @ast Document() do
218+
Heading(1)
219+
end
220+
@test prepend!(n3.children, n2.children) isa NodeChildren
221+
@test typeof.(getproperty.(n3.children, :element)) == [Heading, DisplayMath, DisplayMath, Paragraph, CodeBlock, BlockQuote, Heading]
222+
@test isempty(n2.children)
210223

211224
# @ast macro with variables and function calls
212225
inner_tree = @ast Paragraph() do; "foo"; end

0 commit comments

Comments
 (0)