Added XPath parser specs for all axes.

This commit is contained in:
Yorick Peterse 2014-06-13 16:20:53 +02:00
parent 3ff9057858
commit ce23cce9bd
2 changed files with 142 additions and 1 deletions

View File

@ -58,7 +58,7 @@ describe Oga::XPath::Lexer do
] ]
end end
example 'lex the follow-sibling axis' do example 'lex the following-sibling axis' do
lex_xpath('/following-sibling::A').should == [ lex_xpath('/following-sibling::A').should == [
[:T_SLASH, nil], [:T_SLASH, nil],
[:T_AXIS, 'following-sibling'], [:T_AXIS, 'following-sibling'],

View File

@ -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