From 10632eafd42479d162b31c225859f2e4927cf0ca Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 3 Nov 2014 23:00:15 +0100 Subject: [PATCH] Parsing support for the :first-of-type pseudo. --- lib/oga/css/parser.y | 7 +++++++ .../css/parser/pseudo_classes/first_of_type_spec.rb | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index 8f6dbd9..4aaef24 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -514,6 +514,13 @@ end ) end + ## + # @return [AST::Node] + # + def on_pseudo_class_first_of_type + return s(:eq, s(:call, 'position'), s(:int, 1)) + end + private ## diff --git a/spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb b/spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb new file mode 100644 index 0000000..4356bb7 --- /dev/null +++ b/spec/oga/css/parser/pseudo_classes/first_of_type_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Oga::CSS::Parser do + context ':first-of-type pseudo class' do + example 'parse the :first-of-type pseudo class' do + parse_css(':first-of-type').should == parse_xpath( + 'descendant-or-self::*[position() = 1]' + ) + end + end +end