Rewrote all XPath axis specs.

This commit is contained in:
Yorick Peterse 2014-11-09 22:53:47 +01:00
parent 5f13cc9d73
commit 58209cbad0
13 changed files with 171 additions and 586 deletions

View File

@ -4,44 +4,26 @@ describe Oga::XPath::Evaluator do
context 'ancestor-or-self axis' do context 'ancestor-or-self axis' do
before do before do
@document = parse('<a><b><c></c></b></a>') @document = parse('<a><b><c></c></b></a>')
@c_node = @document.children[0].children[0].children[0]
@evaluator = described_class.new(@c_node) @a1 = @document.children[0]
@b1 = @a1.children[0]
@c1 = @b1.children[0]
end end
context 'direct ancestors' do example 'return a node set containing the direct ancestor' do
before do evaluate_xpath(@c1, 'ancestor-or-self::b').should == node_set(@b1)
@set = @evaluator.evaluate('ancestor-or-self::b')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing a higher ancestor' do
evaluate_xpath(@c1, 'ancestor-or-self::a').should == node_set(@a1)
example 'return the <b> ancestor' do
@set[0].name.should == 'b'
end
end end
context 'higher ancestors' do example 'return a node set containing the context node itself' do
before do evaluate_xpath(@c1, 'ancestor-or-self::c').should == node_set(@c1)
@set = @evaluator.evaluate('ancestor-or-self::a')
end end
it_behaves_like :node_set, :length => 1 example 'return an empty node set for non existing ancestors' do
evaluate_xpath(@c1, 'ancestor-or-self::foo').should == node_set
example 'return the <a> ancestor' do
@set[0].name.should == 'a'
end
end
context 'ancestors that only match the context nodes' do
before do
@set = @evaluator.evaluate('ancestor-or-self::c')
end
it_behaves_like :node_set, :length => 1
example 'return the <c> node' do
@set[0].name.should == 'c'
end
end end
end end
end end

View File

@ -4,40 +4,22 @@ describe Oga::XPath::Evaluator do
context 'ancestor axis' do context 'ancestor axis' do
before do before do
@document = parse('<a><b><c></c></b></a>') @document = parse('<a><b><c></c></b></a>')
@c_node = @document.children[0].children[0].children[0]
@evaluator = described_class.new(@c_node) @a1 = @document.children[0]
@b1 = @a1.children[0]
@c1 = @b1.children[0]
end end
context 'direct ancestors' do example 'return a node set containing a direct ancestor' do
before do evaluate_xpath(@c1, 'ancestor::b').should == node_set(@b1)
@set = @evaluator.evaluate('ancestor::b')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing a higher ancestor' do
evaluate_xpath(@c1, 'ancestor::a').should == node_set(@a1)
example 'return the <b> ancestor' do
@set[0].name.should == 'b'
end
end end
context 'higher ancestors' do example 'return an empty node set for non existing ancestors' do
before do evaluate_xpath(@c1, 'ancestor::c').should == node_set
@set = @evaluator.evaluate('ancestor::a')
end
it_behaves_like :node_set, :length => 1
example 'return the <a> ancestor' do
@set[0].name.should == 'a'
end
end
context 'non existing ancestors' do
before do
@set = @evaluator.evaluate('ancestor::foobar')
end
it_behaves_like :empty_node_set
end end
end end
end end

View File

@ -3,44 +3,22 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'attribute axis' do context 'attribute axis' do
before do before do
document = parse('<a foo="bar"></a>') @document = parse('<a foo="bar"></a>')
@evaluator = described_class.new(document.children[0])
@a1 = @document.children[0]
@attr = @a1.attribute('foo')
end end
context 'matching existing attributes' do example 'return a node set containing an attribute' do
before do evaluate_xpath(@a1, 'attribute::foo').should == node_set(@attr)
@set = @evaluator.evaluate('attribute::foo')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing an attribute using the short form' do
evaluate_xpath(@a1, '@foo').should == node_set(@attr)
example 'return an Attribute instance' do
@set[0].is_a?(Oga::XML::Attribute).should == true
end end
example 'return the "foo" attribute' do example 'return an empty node set for non existing attributes' do
@set[0].name.should == 'foo' evaluate_xpath(@a1, 'attribute::bar').should == node_set
end
end
context 'matching non existing attributes' do
before do
@set = @evaluator.evaluate('attribute::bar')
end
it_behaves_like :empty_node_set
end
context 'matching attributes using the short form' do
before do
@set = @evaluator.evaluate('@foo')
end
it_behaves_like :node_set, :length => 1
example 'return the "foo" attribute' do
@set[0].name.should == 'foo'
end
end end
end end
end end

View File

@ -4,39 +4,21 @@ describe Oga::XPath::Evaluator do
context 'child axis' do context 'child axis' do
before do before do
@document = parse('<a><b></b></a>') @document = parse('<a><b></b></a>')
@evaluator = described_class.new(@document)
@a1 = @document.children[0]
@b1 = @a1.children[0]
end end
context 'direct children' do example 'return a node set containing a direct child node' do
before do evaluate_xpath(@document, 'child::a').should == node_set(@a1)
@set = @evaluator.evaluate('child::a')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing a nested child node' do
evaluate_xpath(@document, 'child::a/child::b').should == node_set(@b1)
example 'return the <a> node' do
@set[0].name.should == 'a'
end
end end
context 'nested children' do example 'return an empty node set for non existing child nodes' do
before do evaluate_xpath(@document, 'child::x').should == node_set
@set = @evaluator.evaluate('child::a/child::b')
end
it_behaves_like :node_set, :length => 1
example 'return the <b> node' do
@set[0].name.should == 'b'
end
end
context 'non existing children' do
before do
@set = @evaluator.evaluate('child::b')
end
it_behaves_like :empty_node_set
end end
end end
end end

View File

@ -3,199 +3,62 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'descendant-or-self axis' do context 'descendant-or-self axis' do
before do before do
document = parse('<a><b><b><c class="x"></c></b></b></a>') @document = parse('<a><b><b><c class="x"></c></b></b></a>')
@first_a = document.children[0] @a1 = @document.children[0]
@first_b = @first_a.children[0] @b1 = @a1.children[0]
@second_b = @first_b.children[0] @b2 = @b1.children[0]
@first_c = @second_b.children[0] @c1 = @b2.children[0]
@evaluator = described_class.new(document)
end end
context 'direct descendants' do example 'return a node set containing a direct descendant' do
before do evaluate_xpath(@document, 'descendant-or-self::b')
@set = @evaluator.evaluate('descendant-or-self::b') .should == node_set(@b1, @b2)
end end
it_behaves_like :node_set, :length => 2 example 'return a node set containing a nested descendant' do
evaluate_xpath(@document, 'descendant-or-self::c').should == node_set(@c1)
example 'return the first <b> node' do
@set[0].should == @first_b
end end
example 'return the second <b> node' do example 'return a node set using multiple descendant expressions' do
@set[1].should == @second_b evaluate_xpath(@document, 'descendant-or-self::a/descendant-or-self::*')
end .should == node_set(@a1, @b1, @b2, @c1)
end end
context 'nested descendants' do example 'return a node set containing a descendant with an attribute' do
before do evaluate_xpath(@document, 'descendant-or-self::c[@class="x"]')
@set = @evaluator.evaluate('descendant-or-self::c') .should == node_set(@c1)
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing a descendant relative to a node' do
evaluate_xpath(@document, 'a/descendant-or-self::b')
example 'return the <c> node' do .should == node_set(@b1, @b2)
@set[0].should == @first_c
end
end end
context 'chained descendants' do example 'return a node set containing the context node' do
before do evaluate_xpath(@document, 'descendant-or-self::a')
@set = @evaluator.evaluate( .should == node_set(@a1)
'descendant-or-self::a/descendant-or-self::*'
)
end end
it_behaves_like :node_set, :length => 4 example 'return a node set containing the context node relative to a node' do
evaluate_xpath(@document, 'a/b/b/c/descendant-or-self::c')
example 'return the <a> node' do .should == node_set(@c1)
@set[0].should == @first_a
end end
example 'return the first <b> node' do example 'return an empty node set for a non existing descendant' do
@set[1].should == @first_b evaluate_xpath(@document, 'descendant-or-self::foobar').should == node_set
end end
example 'return the second <b> node' do example 'return a node set containing a descendant using the short form' do
@set[2].should == @second_b evaluate_xpath(@document, '//b').should == node_set(@b1, @b2)
end end
example 'return the <c> node' do example 'return a node set containing a nested descendant using the short form' do
@set[3].should == @first_c evaluate_xpath(@document, '//a//*').should == node_set(@b1, @b2, @c1)
end
end end
context 'nested descendants with a matching predicate' do example 'return a node set containing children of a descendant' do
before do evaluate_xpath(@document, '//a/b').should == node_set(@b1)
@set = @evaluator.evaluate('descendant-or-self::c[@class="x"]')
end
it_behaves_like :node_set, :length => 1
end
context 'descendants of a specific node' do
before do
@set = @evaluator.evaluate('a/descendant-or-self::b')
end
it_behaves_like :node_set, :length => 2
example 'return the first <b> node' do
@set[0].should == @first_b
end
example 'return the second <b> node' do
@set[1].should == @second_b
end
end
context 'descendants matching self' do
before do
@set = @evaluator.evaluate('descendant-or-self::a')
end
it_behaves_like :node_set, :length => 1
example 'return the first <a> node' do
@set[0].should == @first_a
end
end
context 'descendants of a specific node matching self' do
before do
@set = @evaluator.evaluate('a/b/b/c/descendant-or-self::c')
end
it_behaves_like :node_set, :length => 1
example 'return the first <c> node' do
@set[0].should == @first_c
end
end
context 'non existing descendants' do
before do
@set = @evaluator.evaluate('descendant-or-self::foobar')
end
it_behaves_like :empty_node_set
end
context 'direct descendants without a matching predicate' do
before do
@set = @evaluator.evaluate('descendant-or-self::a[@class]')
end
it_behaves_like :empty_node_set
end
context 'nested descendants without a matching predicate' do
before do
@set = @evaluator.evaluate('descendant-or-self::b[@class]')
end
it_behaves_like :empty_node_set
end
context 'direct descendants using the short form' do
before do
@set = @evaluator.evaluate('//b')
end
it_behaves_like :node_set, :length => 2
example 'return the first <b> node' do
@set[0].should == @first_b
end
example 'return the second <b> node' do
@set[1].should == @second_b
end
end
context 'nested descendants using the short form' do
before do
@set = @evaluator.evaluate('//c')
end
it_behaves_like :node_set, :length => 1
example 'return the <c> node' do
@set[0].should == @first_c
end
end
context 'descendants of descendants usign the short form' do
before do
@set = @evaluator.evaluate('//a//*')
end
it_behaves_like :node_set, :length => 3
example 'return the first <b> node' do
@set[0].should == @first_b
end
example 'return the second <b> node' do
@set[1].should == @second_b
end
example 'return the <c> node' do
@set[2].should == @first_c
end
end
context 'children of descendants using the short form' do
before do
@set = @evaluator.evaluate('//a/b')
end
it_behaves_like :node_set, :length => 1
example 'return the first <b> node' do
@set[0].should == @first_b
end
end end
end end
end end

View File

@ -4,59 +4,26 @@ describe Oga::XPath::Evaluator do
context 'descendant axis' do context 'descendant axis' do
before do before do
@document = parse('<a><b><c></c></b><a></a></a>') @document = parse('<a><b><c></c></b><a></a></a>')
@evaluator = described_class.new(@document)
@first_a = @document.children[0] @a1 = @document.children[0]
@second_a = @first_a.children[-1] @a2 = @a1.children[-1]
@c1 = @a1.children[0].children[0]
end end
context 'direct descendants' do example 'return a node set containing a direct descendant' do
before do evaluate_xpath(@document, 'descendant::a').should == node_set(@a1, @a2)
@set = @evaluator.evaluate('descendant::a')
end end
it_behaves_like :node_set, :length => 2 example 'return a node set containing a nested descendant' do
evaluate_xpath(@document, 'descendant::c').should == node_set(@c1)
example 'return the first <a> node' do
@set[0].should == @first_a
end end
example 'return the second <a> node' do example 'return a node set containing a descendant relative to a node' do
@set[1].should == @second_a evaluate_xpath(@document, 'a/descendant::a').should == node_set(@a2)
end
end end
context 'nested descendants' do example 'return an empty node set for non existing descendants' do
before do evaluate_xpath(@document, 'a/b/c/descendant::c').should == node_set
@set = @evaluator.evaluate('descendant::c')
end
it_behaves_like :node_set, :length => 1
example 'return the <c> node' do
@set[0].name.should == 'c'
end
end
context 'descendants of a specific node' do
before do
@set = @evaluator.evaluate('a/descendant::a')
end
it_behaves_like :node_set, :length => 1
example 'return the second <a> node' do
@set[0].should == @second_a
end
end
context 'non existing descendants' do
before do
# This should result in an empty set since <c> has no <c> children.
@set = @evaluator.evaluate('a/b/c/descendant::c')
end
it_behaves_like :empty_node_set
end end
end end
end end

View File

@ -16,44 +16,25 @@ describe Oga::XPath::Evaluator do
</root> </root>
EOF EOF
@first_baz = @document.children[0].children[0].children[1] @baz1 = @document.children[0].children[0].children[1]
@second_baz = @first_baz.children[0] @baz2 = @baz1.children[0]
@third_baz = @document.children[0].children[1] @baz3 = @document.children[0].children[1]
@evaluator = described_class.new(@document)
end end
# This should return an empty set since the document doesn't have any # This should return an empty set since the document doesn't have any
# following nodes. # following nodes.
context 'using a document as the root' do example 'return an empty node set for the sibling of a document' do
before do evaluate_xpath(@document, 'following-sibling::foo').should == node_set
@set = @evaluator.evaluate('following-sibling::foo')
end end
it_behaves_like :empty_node_set example 'return a node set containing the siblings of root/foo' do
evaluate_xpath(@document, 'root/foo/following-sibling::baz')
.should == node_set(@baz3)
end end
context 'matching nodes in the current context' do example 'return a node set containing the siblings of root/foo/bar' do
before do evaluate_xpath(@document, 'root/foo/bar/following-sibling::baz')
@set = @evaluator.evaluate('root/foo/following-sibling::baz') .should == node_set(@baz1)
end
it_behaves_like :node_set, :length => 1
example 'return the third <baz> node' do
@set[0].should == @third_baz
end
end
context 'matching nodes in a deeper context' do
before do
@set = @evaluator.evaluate('root/foo/bar/following-sibling::baz')
end
it_behaves_like :node_set, :length => 1
example 'return the first <baz> node' do
@set[0].should == @first_baz
end
end end
end end
end end

View File

@ -16,52 +16,25 @@ describe Oga::XPath::Evaluator do
</root> </root>
EOF EOF
@first_baz = @document.children[0].children[0].children[1] @baz1 = @document.children[0].children[0].children[1]
@second_baz = @first_baz.children[0] @baz2 = @baz1.children[0]
@third_baz = @document.children[0].children[1] @baz3 = @document.children[0].children[1]
@evaluator = described_class.new(@document)
end end
# This should return an empty set since the document doesn't have any # This should return an empty set since the document doesn't have any
# following nodes. # following nodes.
context 'using a document as the root' do example 'return an empty node set for the sibling of a document' do
before do evaluate_xpath(@document, 'following::foo').should == node_set
@set = @evaluator.evaluate('following::foo')
end end
it_behaves_like :empty_node_set example 'return a node set containing the following nodes of root/foo' do
evaluate_xpath(@document, 'root/foo/following::baz')
.should == node_set(@baz3)
end end
context 'matching nodes in the current context' do example 'return a node set containing the following nodes of root/foo/bar' do
before do evaluate_xpath(@document, 'root/foo/bar/following::baz')
@set = @evaluator.evaluate('root/foo/following::baz') .should == node_set(@baz1, @baz2, @baz3)
end
it_behaves_like :node_set, :length => 1
example 'return the third <baz> node' do
@set[0].should == @third_baz
end
end
context 'matching nodes in other contexts' do
before do
@set = @evaluator.evaluate('root/foo/bar/following::baz')
end
it_behaves_like :node_set, :length => 3
example 'return the first <baz> node' do
@set[0].should == @first_baz
end
example 'return the second <baz> node' do
@set[1].should == @second_baz
end
example 'return the third <baz> node' do
@set[2].should == @third_baz
end
end end
end end
end end

View File

@ -3,61 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'namespace axis' do context 'namespace axis' do
before do before do
@document = parse(<<-EOF.strip) @document = parse('<root xmlns:x="x"><foo xmlns:y="y"></foo></root>')
<root xmlns:x="x">
<foo xmlns:y="y"></foo>
</root>
EOF
@evaluator = described_class.new(@document) @ns_x = @document.children[0].namespaces['x']
@ns_y = @document.children[0].children[0].namespaces['y']
end end
context 'matching namespaces in the entire document' do example 'return an empty node set for the document' do
before do evaluate_xpath(@document, 'namespace::*').should == node_set
@set = @evaluator.evaluate('namespace::*')
end end
it_behaves_like :empty_node_set example 'return a node set containing the namespaces for root' do
evaluate_xpath(@document, 'root/namespace::x').should == node_set(@ns_x)
end end
context 'matching namespaces in the root element' do example 'return a node set containing the namespaces for root/foo' do
before do evaluate_xpath(@document, 'root/foo/namespace::*')
@set = @evaluator.evaluate('root/namespace::x') .should == node_set(@ns_y, @ns_x)
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing the namespaces for root using a wildcard' do
evaluate_xpath(@document, 'root/namespace::*').should == node_set(@ns_x)
example 'return a Namespace instance' do
@set[0].is_a?(Oga::XML::Namespace).should == true
end
example 'return the "x" namespace' do
@set[0].name.should == 'x'
end
end
context 'matching namespaces in a nested element' do
before do
@set = @evaluator.evaluate('root/foo/namespace::*')
end
it_behaves_like :node_set, :length => 2
example 'return the "y" namespace' do
@set[0].name.should == 'y'
end
example 'return the "x" namespace' do
@set[1].name.should == 'x'
end
end
context 'matching namespace nodes using a wildcard' do
before do
@set = @evaluator.evaluate('root/namespace::*')
end
it_behaves_like :node_set, :length => 1
end end
end end
end end

View File

@ -4,39 +4,20 @@ describe Oga::XPath::Evaluator do
context 'parent axis' do context 'parent axis' do
before do before do
@document = parse('<a><b></b></a>') @document = parse('<a><b></b></a>')
@evaluator = described_class.new(@document)
@a1 = @document.children[0]
end end
context 'matching nodes without parents' do example 'return an empty node set for non existing parents' do
before do evaluate_xpath(@document, 'parent::a').should == node_set
@set = @evaluator.evaluate('parent::a')
end end
it_behaves_like :empty_node_set example 'return a node set containing parents of a node' do
evaluate_xpath(@document, 'a/b/parent::a').should == node_set(@a1)
end end
context 'matching nodes with parents' do example 'return a node set containing parents of a node using the short form' do
before do evaluate_xpath(@document, 'a/b/..').should == node_set(@a1)
@set = @evaluator.evaluate('a/b/parent::a')
end
it_behaves_like :node_set, :length => 1
example 'return the <a> node' do
@set[0].should == @document.children[0]
end
end
context 'matching nodes with parents using the short form' do
before do
@set = @evaluator.evaluate('a/b/..')
end
it_behaves_like :node_set, :length => 1
example 'return the <a> node' do
@set[0].should == @document.children[0]
end
end end
end end
end end

View File

@ -14,20 +14,18 @@ describe Oga::XPath::Evaluator do
</root> </root>
EOF EOF
@second_foo = @document.children[0].children[1].children[0] @foo1 = @document.children[0].children[0]
@evaluator = described_class.new(@document) @foo2 = @document.children[0].children[1].children[0]
end end
context 'matching nodes in the current context' do example 'return a node set containing preceding siblings of root/bar' do
before do evaluate_xpath(@document, 'root/bar/preceding-sibling::foo')
@set = @evaluator.evaluate('root/bar/baz/preceding-sibling::foo') .should == node_set(@foo1)
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing preceding siblings of root/bar/baz' do
evaluate_xpath(@document, 'root/bar/baz/preceding-sibling::foo')
example 'return the second <foo> node' do .should == node_set(@foo2)
@set[0].should == @second_foo
end
end end
end end
end end

View File

@ -15,39 +15,20 @@ describe Oga::XPath::Evaluator do
</root> </root>
EOF EOF
@first_foo = @document.children[0].children[0] @foo1 = @document.children[0].children[0]
@first_bar = @first_foo.children[0] @bar1 = @foo1.children[0]
@first_baz = @first_foo.children[1] @baz1 = @foo1.children[1]
@second_baz = @first_baz.children[0] @baz2 = @baz1.children[0]
@evaluator = described_class.new(@document)
end end
context 'matching nodes in the current context' do example 'return a node set containing preceding nodes of root/foo/baz' do
before do evaluate_xpath(@document, 'root/foo/baz/preceding::bar')
@set = @evaluator.evaluate('root/foo/baz/preceding::bar') .should == node_set(@bar1)
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing preceding nodes for root/baz' do
evaluate_xpath(@document, 'root/baz/preceding::baz')
example 'return the first <bar> node' do .should == node_set(@baz1, @baz2)
@set[0].should == @first_bar
end
end
context 'matching nodes in other contexts' do
before do
@set = @evaluator.evaluate('root/baz/preceding::baz')
end
it_behaves_like :node_set, :length => 2
example 'return the first <baz> node' do
@set[0].should == @first_baz
end
example 'return the second <baz> node' do
@set[1].should == @second_baz
end
end end
end end
end end

View File

@ -4,87 +4,38 @@ describe Oga::XPath::Evaluator do
context 'self axis' do context 'self axis' do
before do before do
@document = parse('<a><b>foo</b><b>bar<c>test</c></b></a>') @document = parse('<a><b>foo</b><b>bar<c>test</c></b></a>')
@evaluator = described_class.new(@document)
@a1 = @document.children[0]
@b1 = @a1.children[0]
@b2 = @a1.children[1]
end end
context 'matching the context node itself' do example 'return a node set containing the context node' do
before do evaluate_xpath(@document, 'a/self::a').should == node_set(@a1)
@set = @evaluator.evaluate('a/self::a')
end end
it_behaves_like :node_set, :length => 1 example 'return an empty node set for non existing nodes' do
evaluate_xpath(@document, 'a/self::b').should == node_set
example 'return the <a> node' do
@set[0].should == @document.children[0]
end
end end
context 'matching non existing nodes' do example 'return a node set containing the context node using the short form' do
before do evaluate_xpath(@document, 'a/.').should == node_set(@a1)
@set = @evaluator.evaluate('a/self::b')
end end
it_behaves_like :empty_node_set example 'return a node set by matching the text of a node' do
evaluate_xpath(@document, 'a/b[. = "foo"]').should == node_set(@b1)
end end
context 'matching the context node itself using the short form' do example 'return a node set by matching the text of a path' do
before do evaluate_xpath(@document, 'a/b[c/. = "test"]').should == node_set(@b2)
@set = @evaluator.evaluate('a/.')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set by matching the text of a nested predicate' do
evaluate_xpath(@document, 'a/b[c[. = "test"]]').should == node_set(@b2)
example 'return the <a> node' do
@set[0].should == @document.children[0]
end
end end
context 'matching nodes inside predicates' do example 'return a node set containing the document itself' do
before do evaluate_xpath(@document, 'self::node()').should == node_set(@document)
@set = @evaluator.evaluate('a/b[. = "foo"]')
end
it_behaves_like :node_set, :length => 1
example 'return the first <b> node' do
@set[0].should == @document.children[0].children[0]
end
end
context 'using self inside a path inside a predicate' do
before do
@set = @evaluator.evaluate('a/b[c/. = "test"]')
end
it_behaves_like :node_set, :length => 1
example 'return the second <b> node' do
@set[0].should == @document.children[0].children[1]
end
end
context 'using self inside a nested predicate' do
before do
@set = @evaluator.evaluate('a/b[c[. = "test"]]')
end
it_behaves_like :node_set, :length => 1
example 'return the second <b> node' do
@set[0].should == @document.children[0].children[1]
end
end
context 'matching the document itself' do
before do
@set = @evaluator.evaluate('self::node()')
end
it_behaves_like :node_set, :length => 1
example 'return the document itself' do
@set[0].is_a?(Oga::XML::Document).should == true
end
end end
end end
end end