Skip to content

Commit

Permalink
test: backfill better coverage for canonicalize with a block
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Oct 16, 2022
1 parent 924a8c9 commit 359e03d
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions test/xml/test_c14n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ def test_3_1
<!-- Comment 3 -->
eoxml

expected = <<~EOF.strip
<?xml-stylesheet href="doc.xsl"
type="text/xsl" ?>
<doc>Hello, world!</doc>
<?pi-without-data?>
EOF
c14n = doc.canonicalize
refute_match(/version=/, c14n)
assert_match(/Hello, world/, c14n)
refute_match(/Comment/, c14n)
c14n = doc.canonicalize(nil, nil, true)
assert_match(/Comment/, c14n)
assert_equal(expected, c14n)
c14n = doc.canonicalize(nil, nil, false)
refute_match(/Comment/, c14n)
assert_equal(expected, c14n)

expected = <<~EOF.strip
<?xml-stylesheet href="doc.xsl"
type="text/xsl" ?>
<doc>Hello, world!<!-- Comment 1 --></doc>
<?pi-without-data?>
<!-- Comment 2 -->
<!-- Comment 3 -->
EOF
c14n = doc.canonicalize(nil, nil, true)
assert_equal(expected, c14n)
end

def test_exclude_block_params
Expand Down Expand Up @@ -76,6 +89,23 @@ def test_exclude_block_false
assert_equal("", c14n)
end

def test_exclude_block_conditional
xml = "<root><a></a><b></b><c></c><d></d></root>"
doc = Nokogiri.XML(xml)

c14n = doc.canonicalize do |node, _parent|
node.name == "root" || node.name == "a" || node.name == "c"
end
assert_equal("<root><a></a><c></c></root>", c14n)

c14n = doc.canonicalize do |node, _parent|
node.name == "a" || node.name == "c"
end
pending_if("java c14n is not completely compatible with libxml2 c14n", Nokogiri.jruby?) do
assert_equal("<a></a><c></c>", c14n)
end
end

def test_exclude_block_nil
xml = "<a><b></b></a>"
doc = Nokogiri.XML(xml)
Expand Down

0 comments on commit 359e03d

Please sign in to comment.