From ce23cce9bdc1e2b240af48c7f588782d032b8646 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 13 Jun 2014 16:20:53 +0200 Subject: [PATCH] Added XPath parser specs for all axes. --- spec/oga/xpath/lexer/axes_spec.rb | 2 +- spec/oga/xpath/parser/axes_spec.rb | 141 +++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 spec/oga/xpath/parser/axes_spec.rb diff --git a/spec/oga/xpath/lexer/axes_spec.rb b/spec/oga/xpath/lexer/axes_spec.rb index 6e2c471..749f662 100644 --- a/spec/oga/xpath/lexer/axes_spec.rb +++ b/spec/oga/xpath/lexer/axes_spec.rb @@ -58,7 +58,7 @@ describe Oga::XPath::Lexer do ] end - example 'lex the follow-sibling axis' do + example 'lex the following-sibling axis' do lex_xpath('/following-sibling::A').should == [ [:T_SLASH, nil], [:T_AXIS, 'following-sibling'], diff --git a/spec/oga/xpath/parser/axes_spec.rb b/spec/oga/xpath/parser/axes_spec.rb new file mode 100644 index 0000000..faa5fca --- /dev/null +++ b/spec/oga/xpath/parser/axes_spec.rb @@ -0,0 +1,141 @@ +require 'spec_helper' + +describe Oga::XPath::Parser do + context 'full axes' do + example 'parse the ancestor axis' do + parse_xpath('/ancestor::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'ancestor', s(:name, nil, 'A')))) + ) + end + + example 'parse the ancestor-or-self axis' do + parse_xpath('/ancestor-or-self::A').should == s( + :xpath, + s( + :path, + s(:node_test, s(:axis, 'ancestor-or-self', s(:name, nil, 'A'))) + ) + ) + end + + example 'parse the attribute axis' do + parse_xpath('/attribute::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'attribute', s(:name, nil, 'A')))) + ) + end + + example 'parse the child axis' do + parse_xpath('/child::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'child', s(:name, nil, 'A')))) + ) + end + + example 'parse the descendant axis' do + parse_xpath('/descendant::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'descendant', s(:name, nil, 'A')))) + ) + end + + example 'parse the descendant-or-self axis' do + parse_xpath('/descendant-or-self::A').should == s( + :xpath, + s( + :path, + s(:node_test, s(:axis, 'descendant-or-self', s(:name, nil, 'A'))) + ) + ) + end + + example 'parse the following axis' do + parse_xpath('/following::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'following', s(:name, nil, 'A')))) + ) + end + + example 'parse the following-sibling axis' do + parse_xpath('/following-sibling::A').should == s( + :xpath, + s( + :path, + s(:node_test, s(:axis, 'following-sibling', s(:name, nil, 'A'))) + ) + ) + end + + example 'parse the namespace axis' do + parse_xpath('/namespace::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'namespace', s(:name, nil, 'A')))) + ) + end + + example 'parse the parent axis' do + parse_xpath('/parent::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'parent', s(:name, nil, 'A')))) + ) + end + + example 'parse the preceding axis' do + parse_xpath('/preceding::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'preceding', s(:name, nil, 'A')))) + ) + end + + example 'parse the preceding-sibling axis' do + parse_xpath('/preceding-sibling::A').should == s( + :xpath, + s( + :path, + s(:node_test, s(:axis, 'preceding-sibling', s(:name, nil, 'A'))) + ) + ) + end + + example 'parse the self axis' do + parse_xpath('/self::A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'self', s(:name, nil, 'A')))) + ) + end + end + + context 'short axes' do + example 'parse the @attribute axis' do + parse_xpath('/@A').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'attribute', s(:name, nil, 'A')))) + ) + end + + example 'parse the // axis' do + parse_xpath('//A').should == s( + :xpath, + s( + :path, + s(:node_test, s(:axis, 'descendant-or-self', s(:name, nil, 'A'))) + ) + ) + end + + example 'parse the .. axis' do + parse_xpath('/..').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'parent'))) + ) + end + + example 'parse the . axis' do + parse_xpath('/.').should == s( + :xpath, + s(:path, s(:node_test, s(:axis, 'self'))) + ) + end + end +end