Skip to content

Commit 905ba6b

Browse files
committed
test: backfill better coverage for canonicalize with a block
1 parent 829041f commit 905ba6b

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

test/xml/test_c14n.rb

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,27 @@ def test_3_1
2424
<!-- Comment 3 -->
2525
eoxml
2626

27+
expected = <<~EOF.strip
28+
<?xml-stylesheet href="doc.xsl"
29+
type="text/xsl" ?>
30+
<doc>Hello, world!</doc>
31+
<?pi-without-data?>
32+
EOF
2733
c14n = doc.canonicalize
28-
refute_match(/version=/, c14n)
29-
assert_match(/Hello, world/, c14n)
30-
refute_match(/Comment/, c14n)
31-
c14n = doc.canonicalize(nil, nil, true)
32-
assert_match(/Comment/, c14n)
34+
assert_equal(expected, c14n)
3335
c14n = doc.canonicalize(nil, nil, false)
34-
refute_match(/Comment/, c14n)
36+
assert_equal(expected, c14n)
37+
38+
expected = <<~EOF.strip
39+
<?xml-stylesheet href="doc.xsl"
40+
type="text/xsl" ?>
41+
<doc>Hello, world!<!-- Comment 1 --></doc>
42+
<?pi-without-data?>
43+
<!-- Comment 2 -->
44+
<!-- Comment 3 -->
45+
EOF
46+
c14n = doc.canonicalize(nil, nil, true)
47+
assert_equal(expected, c14n)
3548
end
3649

3750
def test_exclude_block_params
@@ -76,6 +89,23 @@ def test_exclude_block_false
7689
assert_equal("", c14n)
7790
end
7891

92+
def test_exclude_block_conditional
93+
xml = "<root><a></a><b></b><c></c><d></d></root>"
94+
doc = Nokogiri.XML(xml)
95+
96+
c14n = doc.canonicalize do |node, _parent|
97+
node.name == "root" || node.name == "a" || node.name == "c"
98+
end
99+
assert_equal("<root><a></a><c></c></root>", c14n)
100+
101+
c14n = doc.canonicalize do |node, _parent|
102+
node.name == "a" || node.name == "c"
103+
end
104+
pending_if("java c14n is not completely compatible with libxml2 c14n", Nokogiri.jruby?) do
105+
assert_equal("<a></a><c></c>", c14n)
106+
end
107+
end
108+
79109
def test_exclude_block_nil
80110
xml = "<a><b></b></a>"
81111
doc = Nokogiri.XML(xml)

0 commit comments

Comments
 (0)