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