Skip to content

Commit 6d2c1fa

Browse files
authored
Merge pull request #2709 from sparklemotion/2697-run-html5-fragment-tests-with-a-context-node
test: exercise fragment construction with a context Element
2 parents 3cdb98b + eff81ee commit 6d2c1fa

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

test/html5/test_tree_construction.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,27 @@ def compare_nodes(node, ng_node)
6060

6161
def run_test
6262
if @test[:context]
63-
ctx = @test[:context].join(":")
64-
doc = Nokogiri::HTML5::Document.new
65-
doc = Nokogiri::HTML5::DocumentFragment.new(doc, @test[:data], ctx, max_errors: @test[:errors].length + 10)
63+
# this is a fragment test
64+
if @test_context_node
65+
# run the test using a context Element
66+
if @test[:context].length > 1
67+
# the test is in a foreign context
68+
doc = Nokogiri::HTML5::Document.parse("<!DOCTYPE html><math></math><svg></svg>")
69+
foreign_el = doc.at_css(@test[:context].first)
70+
context_node_name = @test[:context].last
71+
context_node = foreign_el.add_child("<#{context_node_name}></#{context_node_name}>").first
72+
else
73+
# the test is not in a foreign context
74+
doc = Nokogiri::HTML5::Document.new
75+
context_node = doc.create_element(@test[:context].first)
76+
end
77+
doc = Nokogiri::HTML5::DocumentFragment.new(doc, @test[:data], context_node, max_errors: @test[:errors].length + 10)
78+
else
79+
# run the test using a tag name
80+
ctx = @test[:context].join(":")
81+
doc = Nokogiri::HTML5::Document.new
82+
doc = Nokogiri::HTML5::DocumentFragment.new(doc, @test[:data], ctx, max_errors: @test[:errors].length + 10)
83+
end
6684
else
6785
doc = Nokogiri::HTML5.parse(@test[:data], max_errors: @test[:errors].length + 10)
6886
end
@@ -288,11 +306,18 @@ def self.generate_tests
288306
tests.each_with_index do |test, index|
289307
next if test[:script] == :on
290308

291-
define_method "test_#{index}".to_sym do
309+
define_method "test_#{index}" do
292310
@test = test
293311
@index = index
294312
run_test
295313
end
314+
315+
define_method "test_#{index}__with_node" do
316+
@test = test
317+
@index = index
318+
@test_context_node = true
319+
run_test
320+
end if test[:context]
296321
end
297322
end
298323
Object.const_set(test_name, klass)

0 commit comments

Comments
 (0)