From b08a8586c7c34831be0f13f9147b84016d17d94b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sun, 16 Oct 2022 10:07:05 -0400 Subject: [PATCH] test: repro namespace_scopes compaction issue Co-Authored-By: Matt Valentine-House Co-Authored-By: Peter Zhu --- test/test_compaction.rb | 42 +++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/test/test_compaction.rb b/test/test_compaction.rb index 5b0720f670..e06d36d40d 100644 --- a/test/test_compaction.rb +++ b/test/test_compaction.rb @@ -3,19 +3,41 @@ require "helper" describe "compaction" do - it "https://github.com/sparklemotion/nokogiri/pull/2579" do - skip unless GC.respond_to?(:verify_compaction_references) + describe Nokogiri::XML::Node do + it "compacts safely" do # https://github.com/sparklemotion/nokogiri/pull/2579 + skip unless GC.respond_to?(:verify_compaction_references) - big_doc = "" + ("a".."zz").map { |x| "<#{x}>#{x}" }.join + "" - doc = Nokogiri.XML(big_doc) + big_doc = "" + ("a".."zz").map { |x| "<#{x}>#{x}" }.join + "" + doc = Nokogiri.XML(big_doc) - # ensure a bunch of node objects have been wrapped - doc.root.children.each(&:inspect) + # ensure a bunch of node objects have been wrapped + doc.root.children.each(&:inspect) - # compact the heap and try to get the node wrappers to move - GC.verify_compaction_references(double_heap: true, toward: :empty) + # compact the heap and try to get the node wrappers to move + GC.verify_compaction_references(double_heap: true, toward: :empty) - # access the node wrappers and make sure they didn't move - doc.root.children.each(&:inspect) + # access the node wrappers and make sure they didn't move + doc.root.children.each(&:inspect) + end + end + + describe Nokogiri::XML::Namespace do + it "namespace_scopes" do + skip unless GC.respond_to?(:verify_compaction_references) + + doc = Nokogiri::XML(<<~EOF) + + + + + + EOF + + doc.at_xpath("//root:first", "root" => "http://example.com/root").namespace_scopes.inspect + + GC.verify_compaction_references(double_heap: true, toward: :empty) + + doc.at_xpath("//root:first", "root" => "http://example.com/root").namespace_scopes.inspect + end end end