Extra tests for parsing XPath function calls.

This commit is contained in:
Yorick Peterse 2014-06-23 09:37:26 +02:00
parent d2f15e37d0
commit c840a33667
1 changed files with 56 additions and 0 deletions

View File

@ -24,5 +24,61 @@ describe Oga::XPath::Parser do
)
)
end
example 'parse a relative path with a function call' do
parse_xpath('foo/bar()').should == s(
:path,
s(:test, nil, 'foo'),
s(:path, s(:call, 'bar'))
)
end
example 'parse an absolute path with a function call' do
parse_xpath('/foo/bar()').should == s(
:absolute,
s(:path, s(:test, nil, 'foo'), s(:path, s(:call, 'bar')))
)
end
example 'parse a predicate followed by a function call' do
parse_xpath('div[@class="foo"]/bar()').should == s(
:path,
s(
:test,
nil,
'div',
s(
:path,
s(
:eq,
s(:axis, 'attribute', s(:test, nil, 'class')),
s(:string, 'foo')
)
)
),
s(:path, s(:call, 'bar'))
)
end
example 'parse two predicates followed by a function call' do
parse_xpath('A[@class]/B[@class]/bar()').should == s(
:path,
s(
:test,
nil,
'A',
s(:path, s(:axis, 'attribute', s(:test, nil, 'class')))),
s(
:path,
s(
:test,
nil,
'B',
s(:path, s(:axis, 'attribute', s(:test, nil, 'class')))
),
s(:path, s(:call, 'bar'))
)
)
end
end
end