Skip to content

Commit ff0357e

Browse files
authored
Merge branch 'sparklemotion:main' into issue_2494
2 parents 8b2c3ea + c92eb58 commit ff0357e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

test/css/test_css_integration.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TestNokogiriCssIntegration < Nokogiri::TestCase
66
describe "CSS integration tests" do
77
let(:subject) do
88
subject_class.parse(<<~HTML)
9-
<html>
9+
<html><body>
1010
<table>
1111
<tr><td>row1 </td></tr>
1212
<tr><td>row2 </td></tr>
@@ -64,7 +64,7 @@ class TestNokogiriCssIntegration < Nokogiri::TestCase
6464
6565
<p class='empty'></p>
6666
<p class='not-empty'><b></b></p>
67-
</html>
67+
</body></html>
6868
HTML
6969
end
7070

@@ -343,6 +343,14 @@ def assert_result_rows(intarray, result, word = "row")
343343
assert_equal(expected, result.to_a)
344344
end
345345

346+
it "selects using contains" do
347+
assert_equal(14, subject.css("td:contains('row')").length)
348+
assert_equal(6, subject.css("td:contains('row1')").length)
349+
assert_equal(4, subject.css("h1:contains('header')").length)
350+
assert_equal(4, subject.css("div :contains('header')").length)
351+
assert_equal(9, subject.css(":contains('header')").length) # 9 = 4xh1 + 3xdiv + body + html
352+
end
353+
346354
it "selects class_attr_selector" do
347355
doc = subject_class.parse(<<~HTML)
348356
<html><body>

test/css/test_xpath_visitor.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,21 @@ def assert_xpath(expecteds, asts)
383383
assert_xpath("//script//comment()", parser.parse("script comment()"))
384384
end
385385

386+
it "handles contains() (non-standard)" do
387+
# https://api.jquery.com/contains-selector/
388+
assert_xpath(%{//div[contains(.,"youtube")]}, parser.parse(%{div:contains("youtube")}))
389+
end
390+
391+
it "handles gt() (non-standard)" do
392+
# https://api.jquery.com/gt-selector/
393+
assert_xpath("//td[position()>3]", parser.parse("td:gt(3)"))
394+
end
395+
396+
it "handles self()" do
397+
# TODO: it's unclear how this is useful and we should consider deprecating it
398+
assert_xpath("//self::div", parser.parse("self(div)"))
399+
end
400+
386401
it "supports custom functions" do
387402
visitor = Class.new(Nokogiri::CSS::XPathVisitor) do
388403
attr_accessor :awesome

0 commit comments

Comments
 (0)