Skip to content

Commit

Permalink
Merge pull request #2709 from sparklemotion/2697-run-html5-fragment-t…
Browse files Browse the repository at this point in the history
…ests-with-a-context-node

test: exercise fragment construction with a context Element
  • Loading branch information
flavorjones committed Dec 1, 2022
2 parents 3cdb98b + eff81ee commit 6d2c1fa
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions test/html5/test_tree_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,27 @@ def compare_nodes(node, ng_node)

def run_test
if @test[:context]
ctx = @test[:context].join(":")
doc = Nokogiri::HTML5::Document.new
doc = Nokogiri::HTML5::DocumentFragment.new(doc, @test[:data], ctx, max_errors: @test[:errors].length + 10)
# this is a fragment test
if @test_context_node
# run the test using a context Element
if @test[:context].length > 1
# the test is in a foreign context
doc = Nokogiri::HTML5::Document.parse("<!DOCTYPE html><math></math><svg></svg>")
foreign_el = doc.at_css(@test[:context].first)
context_node_name = @test[:context].last
context_node = foreign_el.add_child("<#{context_node_name}></#{context_node_name}>").first
else
# the test is not in a foreign context
doc = Nokogiri::HTML5::Document.new
context_node = doc.create_element(@test[:context].first)
end
doc = Nokogiri::HTML5::DocumentFragment.new(doc, @test[:data], context_node, max_errors: @test[:errors].length + 10)
else
# run the test using a tag name
ctx = @test[:context].join(":")
doc = Nokogiri::HTML5::Document.new
doc = Nokogiri::HTML5::DocumentFragment.new(doc, @test[:data], ctx, max_errors: @test[:errors].length + 10)
end
else
doc = Nokogiri::HTML5.parse(@test[:data], max_errors: @test[:errors].length + 10)
end
Expand Down Expand Up @@ -288,11 +306,18 @@ def self.generate_tests
tests.each_with_index do |test, index|
next if test[:script] == :on

define_method "test_#{index}".to_sym do
define_method "test_#{index}" do
@test = test
@index = index
run_test
end

define_method "test_#{index}__with_node" do
@test = test
@index = index
@test_context_node = true
run_test
end if test[:context]
end
end
Object.const_set(test_name, klass)
Expand Down

0 comments on commit 6d2c1fa

Please sign in to comment.