From c840a33667cde54870d147a462192ec5c7b1f3ae Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 23 Jun 2014 09:37:26 +0200 Subject: [PATCH] Extra tests for parsing XPath function calls. --- spec/oga/xpath/parser/calls_spec.rb | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/spec/oga/xpath/parser/calls_spec.rb b/spec/oga/xpath/parser/calls_spec.rb index b675c8a..45a5baa 100644 --- a/spec/oga/xpath/parser/calls_spec.rb +++ b/spec/oga/xpath/parser/calls_spec.rb @@ -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