Skip to content

Commit b08a858

Browse files
flavorjoneseightbitraptorpeterzhu2118
committed
test: repro namespace_scopes compaction issue
Co-Authored-By: Matt Valentine-House <[email protected]> Co-Authored-By: Peter Zhu <[email protected]>
1 parent 7b369e5 commit b08a858

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

test/test_compaction.rb

+32-10
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,41 @@
33
require "helper"
44

55
describe "compaction" do
6-
it "https://github.com/sparklemotion/nokogiri/pull/2579" do
7-
skip unless GC.respond_to?(:verify_compaction_references)
6+
describe Nokogiri::XML::Node do
7+
it "compacts safely" do # https://github.com/sparklemotion/nokogiri/pull/2579
8+
skip unless GC.respond_to?(:verify_compaction_references)
89

9-
big_doc = "<root>" + ("a".."zz").map { |x| "<#{x}>#{x}</#{x}>" }.join + "</root>"
10-
doc = Nokogiri.XML(big_doc)
10+
big_doc = "<root>" + ("a".."zz").map { |x| "<#{x}>#{x}</#{x}>" }.join + "</root>"
11+
doc = Nokogiri.XML(big_doc)
1112

12-
# ensure a bunch of node objects have been wrapped
13-
doc.root.children.each(&:inspect)
13+
# ensure a bunch of node objects have been wrapped
14+
doc.root.children.each(&:inspect)
1415

15-
# compact the heap and try to get the node wrappers to move
16-
GC.verify_compaction_references(double_heap: true, toward: :empty)
16+
# compact the heap and try to get the node wrappers to move
17+
GC.verify_compaction_references(double_heap: true, toward: :empty)
1718

18-
# access the node wrappers and make sure they didn't move
19-
doc.root.children.each(&:inspect)
19+
# access the node wrappers and make sure they didn't move
20+
doc.root.children.each(&:inspect)
21+
end
22+
end
23+
24+
describe Nokogiri::XML::Namespace do
25+
it "namespace_scopes" do
26+
skip unless GC.respond_to?(:verify_compaction_references)
27+
28+
doc = Nokogiri::XML(<<~EOF)
29+
<root xmlns="http://example.com/root" xmlns:bar="http://example.com/bar">
30+
<first/>
31+
<second xmlns="http://example.com/child"/>
32+
<third xmlns:foo="http://example.com/foo"/>
33+
</root>
34+
EOF
35+
36+
doc.at_xpath("//root:first", "root" => "http://example.com/root").namespace_scopes.inspect
37+
38+
GC.verify_compaction_references(double_heap: true, toward: :empty)
39+
40+
doc.at_xpath("//root:first", "root" => "http://example.com/root").namespace_scopes.inspect
41+
end
2042
end
2143
end

0 commit comments

Comments
 (0)