From 1b870406decbb8b6bc7559eed3f3ca5cf64d3084 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 3 Nov 2014 23:47:25 +0100 Subject: [PATCH] Parsing support for the :only-of-type pseudo. --- lib/oga/css/parser.y | 9 +++++++++ .../css/parser/pseudo_classes/only_of_type_spec.rb | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index 1d1ae5c..ac6cf6a 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -541,6 +541,15 @@ end return s(:and, on_pseudo_class_first_child, on_pseudo_class_last_child) end + ## + # Generates the AST for the `:only-of-type` selector. + # + # @return [AST::Node] + # + def on_pseudo_class_only_of_type + return s(:eq, s(:call, 'last'), s(:int, 1)) + end + private ## diff --git a/spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb b/spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb new file mode 100644 index 0000000..2c06f94 --- /dev/null +++ b/spec/oga/css/parser/pseudo_classes/only_of_type_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context ':only-of-type pseudo class' do + example 'parse the :only-of-type pseudo class' do + parse_css(':only-of-type').should == parse_xpath( + 'descendant-or-self::*[last() = 1]' + ) + end + end +end