From 2cf058457de27cd683eee47112ccb42e51daed03 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 3 Nov 2014 23:27:56 +0100 Subject: [PATCH] Parsing support for the :only-child pseudo. --- lib/oga/css/parser.y | 9 +++++++++ .../oga/css/parser/pseudo_classes/only_child_spec.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 spec/oga/css/parser/pseudo_classes/only_child_spec.rb diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index 3ea228c..1d1ae5c 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -532,6 +532,15 @@ end return s(:eq, s(:call, 'position'), s(:call, 'last')) end + ## + # Generates the AST for the `:only-child` selector. + # + # @return [AST::Node] + # + def on_pseudo_class_only_child + return s(:and, on_pseudo_class_first_child, on_pseudo_class_last_child) + end + private ## diff --git a/spec/oga/css/parser/pseudo_classes/only_child_spec.rb b/spec/oga/css/parser/pseudo_classes/only_child_spec.rb new file mode 100644 index 0000000..c14de75 --- /dev/null +++ b/spec/oga/css/parser/pseudo_classes/only_child_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context ':only-child pseudo class' do + example 'parse the :only-child pseudo class' do + parse_css(':only-child').should == parse_xpath( + 'descendant-or-self::*[count(preceding-sibling::*) = 0 ' \ + 'and count(following-sibling::*) = 0]' + ) + end + end +end