-
-
Notifications
You must be signed in to change notification settings - Fork 897
/
test_compaction.rb
39 lines (28 loc) · 1.25 KB
/
test_compaction.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
require "helper"
describe "compaction" do
it "https://github.com/sparklemotion/nokogiri/pull/2579" do
skip unless GC.respond_to?(:verify_compaction_references)
big_doc = "<root>" + ("a".."zz").map { |x| "<#{x}>#{x}</#{x}>" }.join + "</root>"
doc = Nokogiri.XML(big_doc)
# 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)
# access the node wrappers and make sure they didn't move
doc.root.children.each(&:inspect)
end
it "namespace_scopes compact" do
skip unless GC.respond_to?(:verify_compaction_references)
doc = Nokogiri::XML(<<~EOF)
<root xmlns="http://example.com/root" xmlns:bar="http://example.com/bar">
<first/>
<second xmlns="http://example.com/child"/>
<third xmlns:foo="http://example.com/foo"/>
</root>
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