From de04c61df9a0b5fcdcc53b745375e2f49ea80f1f Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 4 Nov 2014 00:00:23 +0100 Subject: [PATCH] Parsing support for the :empty pseudo. --- lib/oga/css/parser.y | 9 +++++++++ spec/oga/css/parser/pseudo_classes/empty_spec.rb | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 spec/oga/css/parser/pseudo_classes/empty_spec.rb diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index ac6cf6a..cedad80 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -550,6 +550,15 @@ end return s(:eq, s(:call, 'last'), s(:int, 1)) end + ## + # Generates the AST for the `:empty` selector. + # + # @return [AST::Node] + # + def on_pseudo_class_empty + return s(:call, 'not', s(:axis, 'child', s(:type_test, 'node'))) + end + private ## diff --git a/spec/oga/css/parser/pseudo_classes/empty_spec.rb b/spec/oga/css/parser/pseudo_classes/empty_spec.rb new file mode 100644 index 0000000..b487f1d --- /dev/null +++ b/spec/oga/css/parser/pseudo_classes/empty_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context ':empty pseudo class' do + example 'parse the :empty pseudo class' do + parse_css(':empty').should == parse_xpath( + 'descendant-or-self::*[not(node())]' + ) + end + end +end