Skip to content

Commit

Permalink
Merge branch 'sparklemotion:main' into issue_2494
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyE authored Apr 3, 2022
2 parents 8b2c3ea + c92eb58 commit ff0357e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/css/test_css_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestNokogiriCssIntegration < Nokogiri::TestCase
describe "CSS integration tests" do
let(:subject) do
subject_class.parse(<<~HTML)
<html>
<html><body>
<table>
<tr><td>row1 </td></tr>
<tr><td>row2 </td></tr>
Expand Down Expand Up @@ -64,7 +64,7 @@ class TestNokogiriCssIntegration < Nokogiri::TestCase
<p class='empty'></p>
<p class='not-empty'><b></b></p>
</html>
</body></html>
HTML
end

Expand Down Expand Up @@ -343,6 +343,14 @@ def assert_result_rows(intarray, result, word = "row")
assert_equal(expected, result.to_a)
end

it "selects using contains" do
assert_equal(14, subject.css("td:contains('row')").length)
assert_equal(6, subject.css("td:contains('row1')").length)
assert_equal(4, subject.css("h1:contains('header')").length)
assert_equal(4, subject.css("div :contains('header')").length)
assert_equal(9, subject.css(":contains('header')").length) # 9 = 4xh1 + 3xdiv + body + html
end

it "selects class_attr_selector" do
doc = subject_class.parse(<<~HTML)
<html><body>
Expand Down
15 changes: 15 additions & 0 deletions test/css/test_xpath_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,21 @@ def assert_xpath(expecteds, asts)
assert_xpath("//script//comment()", parser.parse("script comment()"))
end

it "handles contains() (non-standard)" do
# https://api.jquery.com/contains-selector/
assert_xpath(%{//div[contains(.,"youtube")]}, parser.parse(%{div:contains("youtube")}))
end

it "handles gt() (non-standard)" do
# https://api.jquery.com/gt-selector/
assert_xpath("//td[position()>3]", parser.parse("td:gt(3)"))
end

it "handles self()" do
# TODO: it's unclear how this is useful and we should consider deprecating it
assert_xpath("//self::div", parser.parse("self(div)"))
end

it "supports custom functions" do
visitor = Class.new(Nokogiri::CSS::XPathVisitor) do
attr_accessor :awesome
Expand Down

0 comments on commit ff0357e

Please sign in to comment.