Skip to content

Commit

Permalink
test: add coverage for HTML5 attribute namespace behavior
Browse files Browse the repository at this point in the history
This corresponds to the code added in 7b3c972

Note also that this commit adds the same test for HTML4, commented out
because it currently fails, that we will make pass in the next few
commits.
  • Loading branch information
flavorjones committed Aug 30, 2022
1 parent 704a5f8 commit 90b3dd0
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/namespaces/test_namespaces_in_created_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,49 @@ def test_created_namespaced_attribute_on_unparented_node
doc.root.add_child(node)
assert_equal("http://foo.io", doc.root.children.first.attribute_nodes.first.namespace.href)
end

def test_created_namespaced_attribute_on_unparented_node_is_renamespaced_in_xml_doc
doc1 = Nokogiri::XML("<root>")
doc2 = Nokogiri::XML("<root>")

child = doc1.create_element("child")
child["tempname"] = "en"
attr = child.attribute("tempname")
attr.name = "xml:lang"
assert_nil(child.attribute_nodes.first.namespace)

doc2.root.add_child(child)
assert(child.attribute_nodes.first.namespace)
end

# def test_created_namespaced_attribute_on_unparented_node_is_not_renamespaced_in_html4_doc
# doc1 = Nokogiri::HTML4("<html><body></body></html>")
# doc2 = Nokogiri::HTML4("<html><body></body></html>")

# child = doc1.create_element("div")
# child["tempname"] = "en"
# attr = child.attribute("tempname")
# attr.name = "xml:lang"
# assert_nil(child.attribute_nodes.first.namespace)

# doc2.at_css("body").add_child(child)
# assert_nil(child.attribute_nodes.first.namespace)
# end

def test_created_namespaced_attribute_on_unparented_node_is_not_renamespaced_in_html5_doc
skip("HTML5 not supported on this platform yet") unless defined?(Nokogiri::HTML5)
doc1 = Nokogiri::HTML5("<html><body></body></html>")
doc2 = Nokogiri::HTML5("<html><body></body></html>")

child = doc1.create_element("div")
child["tempname"] = "en"
attr = child.attribute("tempname")
attr.name = "xml:lang"
assert_nil(child.attribute_nodes.first.namespace)

doc2.at_css("body").add_child(child)
assert_nil(child.attribute_nodes.first.namespace)
end
end
end
end

0 comments on commit 90b3dd0

Please sign in to comment.