diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index 4aaef24..3ea228c 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -515,12 +515,23 @@ end end ## + # Generates the AST for the `:first-of-type` selector. + # # @return [AST::Node] # def on_pseudo_class_first_of_type return s(:eq, s(:call, 'position'), s(:int, 1)) end + ## + # Generates the AST for the `:last-of-type` selector. + # + # @return [AST::Node] + # + def on_pseudo_class_last_of_type + return s(:eq, s(:call, 'position'), s(:call, 'last')) + end + private ## diff --git a/spec/oga/css/parser/pseudo_classes/last_of_type_spec.rb b/spec/oga/css/parser/pseudo_classes/last_of_type_spec.rb new file mode 100644 index 0000000..52678ba --- /dev/null +++ b/spec/oga/css/parser/pseudo_classes/last_of_type_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context ':last-of-type pseudo class' do + example 'parse the :last-of-type pseudo class' do + parse_css(':last-of-type').should == parse_xpath( + 'descendant-or-self::*[position() = last()]' + ) + end + end +end