Skip to content

Commit 36b0644

Browse files
authored
Merge branch 'JuliaComputing:main' into main
2 parents 6ca1710 + 7ec50de commit 36b0644

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

.github/workflows/Downstream.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Downstream
2+
on:
3+
push:
4+
branches: [main]
5+
tags: [v*]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
name: ${{ matrix.package }}
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
package:
16+
- "XLSX"
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: julia-actions/setup-julia@v2
20+
with:
21+
version: 1
22+
arch: x64
23+
show-versioninfo: true
24+
- uses: julia-actions/julia-buildpkg@latest
25+
- name: Load this and run the downstream tests
26+
shell: julia --color=yes {0}
27+
run: |
28+
using Pkg
29+
Pkg.Registry.update()
30+
Pkg.activate(;temp=true)
31+
# force it to use this PR's version of the package
32+
ENV["JULIA_PKG_DEVDIR"]= mktempdir()
33+
Pkg.develop([
34+
PackageSpec(path="."),
35+
PackageSpec(name="${{ matrix.package }}"),
36+
])
37+
Pkg.update()
38+
Pkg.test("${{ matrix.package }}")

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "XML"
22
uuid = "72c71f33-b9b6-44de-8c94-c961784809e2"
33
authors = ["Josh Day <[email protected]> and contributors"]
4-
version = "0.3.4"
4+
version = "0.3.5"
55

66
[deps]
77
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"

src/XML.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ attributes(o) = o.attributes
264264
value(o) = o.value
265265
children(o::T) where {T} = isnothing(o.children) ? () : o.children
266266

267-
depth(o) = 1
267+
depth(o) = missing
268268
parent(o) = missing
269269
next(o) = missing
270270
prev(o) = missing
@@ -364,7 +364,7 @@ write(x; kw...) = (io = IOBuffer(); write(io, x; kw...); String(take!(io)))
364364

365365
write(filename::AbstractString, x; kw...) = open(io -> write(io, x; kw...), filename, "w")
366366

367-
function write(io::IO, x; indentsize::Int=2, depth::Int=depth(x))
367+
function write(io::IO, x; indentsize::Int=2, depth::Int=1)
368368
indent = ' ' ^ indentsize
369369
nodetype = XML.nodetype(x)
370370
tag = XML.tag(x)

src/raw.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function Base.:(==)(a::Raw, b::Raw)
8787
end
8888

8989
Base.view(o::Raw) = view(o.data, o.pos:o.pos + o.len)
90-
String(o::Raw) = String(view(o))
90+
Base.String(o::Raw) = String(view(o))
9191

9292
Base.IteratorSize(::Type{Raw}) = Base.SizeUnknown()
9393
Base.eltype(::Type{Raw}) = Raw
@@ -208,14 +208,23 @@ function children(o::Raw)
208208
end
209209
end
210210

211+
"""
212+
depth(node) --> Int
213+
214+
Return the depth of the node. Will be `0` for `Document` nodes. Not defined for `XML.Node`.
215+
"""
216+
function depth(o::Raw)
217+
o.depth
218+
end
219+
211220
"""
212221
parent(node) --> typeof(node), Nothing
213222
214223
Return the parent of the node. Will be `nothing` for `Document` nodes. Not defined for `XML.Node`.
215224
"""
216225
function parent(o::Raw)
217226
depth = o.depth
218-
depth === 1 && return nothing
227+
depth === 0 && return nothing
219228
p = prev(o)
220229
while p.depth >= depth
221230
p = prev(p)

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ end
134134
end
135135
end
136136

137+
@testset "depth and parent" begin
138+
@test XML.depth(data) == 0
139+
@test isnothing(XML.parent(data))
140+
@test XML.depth(doc[1]) == 1
141+
@test XML.parent(doc[1]) == data
142+
@test XML.depth(doc[2]) == 1
143+
@test XML.depth(doc[3]) == 2
144+
@test XML.parent(doc[3]) == doc[2]
145+
@test XML.depth(doc[end]) == 1
146+
@test XML.parent(doc[end]) == data
147+
end
148+
137149
@testset "tag/attributes/value" begin
138150
x = doc[1] # <?xml version="1.0"?>
139151
@test XML.tag(x) === nothing

0 commit comments

Comments
 (0)