Support for the XPath local-name() function.
This commit is contained in:
1 parent
2deb7a6d84
commit
9e20b5ca3e
2 files changed
+79
-5
No files matched your search
@@ -0,0 +1,46 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Oga::XPath::Evaluator do
|
||||
context 'local-name() function' do
|
||||
before do
|
||||
@document = parse('<root xmlns:x="y"><x:a></x:a><b></b></root>')
|
||||
@evaluator = described_class.new(@document)
|
||||
end
|
||||
|
||||
context 'outside predicates' do
|
||||
example 'return the local name of the <x:a> node' do
|
||||
@evaluator.evaluate('local-name(root/x:a)').should == 'a'
|
||||
end
|
||||
|
||||
example 'return the local name of the <b> node' do
|
||||
@evaluator.evaluate('local-name(root/b)').should == 'b'
|
||||
end
|
||||
|
||||
example 'return only the name of the first node in the set' do
|
||||
@evaluator.evaluate('local-name(root/*)').should == 'a'
|
||||
end
|
||||
|
||||
example 'return an empty string by default' do
|
||||
@evaluator.evaluate('local-name(foo)').should == ''
|
||||
end
|
||||
|
||||
example 'raise a TypeError for invalid argument types' do
|
||||
block = lambda { @evaluator.evaluate('local-name("foo")') }
|
||||
|
||||
block.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'inside predicates' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('root/b[local-name()]')
|
||||
end
|
||||
|
||||
it_behaves_like :node_set, :length => 1
|
||||
|
||||
example 'return the <b> node' do
|
||||
@set[0].should == @document.children[0].children[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user