Skip to content

Commit

Permalink
Merge pull request #858 from ykzts/feature/not-only-child
Browse files Browse the repository at this point in the history
Add feature that the ':only-child' pseudo class should work even though it's in ':not' pseudo class.
  • Loading branch information
leejarvis committed Jun 14, 2013
2 parents d24eb85 + 4383dc6 commit d1b0afd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/nokogiri/css/xpath_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def visit_pseudo_class node
when "last", "last-child" then "position() = last()"
when "first-of-type" then "position() = 1"
when "last-of-type" then "position() = last()"
when "only-child" then "last() = 1"
when "only-of-type" then "last() = 1"
when "empty" then "not(node())"
when "parent" then "node()"
Expand Down
5 changes: 5 additions & 0 deletions test/css/test_xpath_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def test_not_last_child
@parser.parse('ol > *:not(:last-child)'))
end

def test_not_only_child
assert_xpath('//ol/*[not(last() = 1)]',
@parser.parse('ol > *:not(:only-child)'))
end

def test_function_calls_allow_at_params
assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)'))
assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))
Expand Down

0 comments on commit d1b0afd

Please sign in to comment.