|
3 | 3 | require "helper" |
4 | 4 |
|
5 | 5 | 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) |
8 | 9 |
|
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) |
11 | 12 |
|
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) |
14 | 15 |
|
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) |
17 | 18 |
|
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 |
20 | 42 | end |
21 | 43 | end |
0 commit comments