Skip to content

Commit

Permalink
Merge pull request #182 from aplavin/patch-1
Browse files Browse the repository at this point in the history
add propertynames
  • Loading branch information
sjkelly committed Nov 7, 2023
2 parents a0025a7 + 6ea5c72 commit 6954d4a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/document.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ end
# Document properties
# -------------------

Base.propertynames(x::Document) = (
:version, :encoding, :root, :dtd,
fieldnames(typeof(x))...
)

@inline function Base.getproperty(doc::Document, name::Symbol)
name == :version ? (hasversion(doc) ? version(doc) : nothing) :
name == :encoding ? (hasencoding(doc) ? encoding(doc) : nothing) :
Expand Down
5 changes: 5 additions & 0 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ end
# Node properties
# ---------------

Base.propertynames(x::Node) = (
:type, :name, :path, :content, :namespace, :document, :parentnode, :parentelement, :firstnode, :lastnode, :firstelement, :lastelement, :nextnode, :prevnode, :nextelement, :prevelement,
fieldnames(typeof(x))...
)

@inline function Base.getproperty(node::Node, name::Symbol)
# node properties
name == :type ? nodetype(node) :
Expand Down
5 changes: 5 additions & 0 deletions src/streamreader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ mutable struct StreamReader
end
end

Base.propertynames(x::StreamReader) = (
:type, :depth, :name, :content, :namespace,
fieldnames(typeof(x))...
)

@inline function Base.getproperty(reader::StreamReader, name::Symbol)
name == :type ? nodetype(reader) :
name == :depth ? nodedepth(reader) :
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ end
@test nodetype(n) === EzXML.ELEMENT_NODE
@test iselement(n)
@test_throws ArgumentError document(n)
@test getproperty.(Ref(n), propertynames(n)) isa Tuple

n = TextNode("some text")
@test isa(n, EzXML.Node)
Expand Down Expand Up @@ -550,6 +551,7 @@ end
@test nodetype(doc.node) === EzXML.DOCUMENT_NODE
@test !hasroot(doc)
@test_throws ArgumentError root(doc)
@test getproperty.(Ref(doc), propertynames(doc)) isa Tuple

doc = HTMLDocument()
@test isa(doc, EzXML.Document)
Expand Down

0 comments on commit 6954d4a

Please sign in to comment.