@@ -60,9 +60,27 @@ def compare_nodes(node, ng_node)
60
60
61
61
def run_test
62
62
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
66
84
else
67
85
doc = Nokogiri ::HTML5 . parse ( @test [ :data ] , max_errors : @test [ :errors ] . length + 10 )
68
86
end
@@ -288,11 +306,18 @@ def self.generate_tests
288
306
tests . each_with_index do |test , index |
289
307
next if test [ :script ] == :on
290
308
291
- define_method "test_#{ index } " . to_sym do
309
+ define_method "test_#{ index } " do
292
310
@test = test
293
311
@index = index
294
312
run_test
295
313
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 ]
296
321
end
297
322
end
298
323
Object . const_set ( test_name , klass )
0 commit comments