Rewrote all XPath evaluator type test specs.

This commit is contained in:
Yorick Peterse 2014-11-09 23:39:47 +01:00
parent ca5da3f9c9
commit c5c3c5dbc3
4 changed files with 39 additions and 134 deletions

View File

@ -4,39 +4,17 @@ describe Oga::XPath::Evaluator do
context 'comment() tests' do context 'comment() tests' do
before do before do
@document = parse('<a><!--foo--><b><!--bar--></b></a>') @document = parse('<a><!--foo--><b><!--bar--></b></a>')
@evaluator = described_class.new(@document)
@comment1 = @document.children[0].children[0]
@comment2 = @document.children[0].children[1].children[0]
end end
context 'matching comment nodes' do example 'return a node set containing comment nodes' do
before do evaluate_xpath(@document, 'a/comment()').should == node_set(@comment1)
@set = @evaluator.evaluate('a/comment()')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing nested comments' do
evaluate_xpath(@document, 'a/b/comment()').should == node_set(@comment2)
example 'return a Comment instance' do
@set[0].is_a?(Oga::XML::Comment).should == true
end
example 'return the "foo" comment node' do
@set[0].text.should == 'foo'
end
end
context 'matching nested comment nodes' do
before do
@set = @evaluator.evaluate('a/b/comment()')
end
it_behaves_like :node_set, :length => 1
example 'return a Comment instance' do
@set[0].is_a?(Oga::XML::Comment).should == true
end
example 'return the "bar" comment node' do
@set[0].text.should == 'bar'
end
end end
end end
end end

View File

@ -4,55 +4,24 @@ describe Oga::XPath::Evaluator do
context 'node() tests' do context 'node() tests' do
before do before do
@document = parse('<a><b>foo</b><!--foo--><![CDATA[bar]]></a>') @document = parse('<a><b>foo</b><!--foo--><![CDATA[bar]]></a>')
@evaluator = described_class.new(@document)
@a1 = @document.children[0]
@b1 = @a1.children[0]
@comment1 = @a1.children[1]
@cdata1 = @a1.children[2]
end end
context 'matching elements' do example 'return a node set containing elements' do
before do evaluate_xpath(@document, 'node()').should == node_set(@a1)
@set = @evaluator.evaluate('node()')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing elements, comments and CDATA tags' do
evaluate_xpath(@document, 'a/node()')
example 'return the <a> node' do .should == node_set(@b1, @comment1, @cdata1)
@set[0].name.should == 'a'
end
end end
context 'matching nested elements' do example 'return a node set containing text nodes' do
before do evaluate_xpath(@document, 'a/b/node()').should == node_set(@b1.children[0])
@set = @evaluator.evaluate('a/node()')
end
it_behaves_like :node_set, :length => 3
example 'return the <b> node' do
@set[0].name.should == 'b'
end
example 'return the "foo" comment' do
@set[1].text.should == 'foo'
end
example 'return the "bar" CDATA tag' do
@set[2].text.should == 'bar'
end
end
context 'matching text nodes' do
before do
@set = @evaluator.evaluate('a/b/node()')
end
it_behaves_like :node_set, :length => 1
example 'return a Text instance' do
@set[0].is_a?(Oga::XML::Text).should == true
end
example 'include the text' do
@set[0].text.should == 'foo'
end
end end
end end
end end

View File

@ -4,39 +4,19 @@ describe Oga::XPath::Evaluator do
context 'processing-instruction() tests' do context 'processing-instruction() tests' do
before do before do
@document = parse('<a><?a foo ?><b><?b bar ?></b></a>') @document = parse('<a><?a foo ?><b><?b bar ?></b></a>')
@evaluator = described_class.new(@document)
@proc_ins1 = @document.children[0].children[0]
@proc_ins2 = @document.children[0].children[1].children[0]
end end
context 'matching processing instruction nodes' do example 'return a node set containing processing instructions' do
before do evaluate_xpath(@document, 'a/processing-instruction()')
@set = @evaluator.evaluate('a/processing-instruction()') .should == node_set(@proc_ins1)
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing nested processing instructions' do
evaluate_xpath(@document, 'a/b/processing-instruction()')
example 'return a ProcessingInstruction instance' do .should == node_set(@proc_ins2)
@set[0].is_a?(Oga::XML::ProcessingInstruction).should == true
end
example 'return the "foo" node' do
@set[0].text.should == ' foo '
end
end
context 'matching nested processing instruction nodes' do
before do
@set = @evaluator.evaluate('a/b/processing-instruction()')
end
it_behaves_like :node_set, :length => 1
example 'return a ProcessingInstruction instance' do
@set[0].is_a?(Oga::XML::ProcessingInstruction).should == true
end
example 'return the "bar" node' do
@set[0].text.should == ' bar '
end
end end
end end
end end

View File

@ -4,39 +4,17 @@ describe Oga::XPath::Evaluator do
context 'text() tests' do context 'text() tests' do
before do before do
@document = parse('<a>foo<b>bar</b></a>') @document = parse('<a>foo<b>bar</b></a>')
@evaluator = described_class.new(@document)
@text1 = @document.children[0].children[0]
@text2 = @document.children[0].children[1].children[0]
end end
context 'matching text nodes' do example 'return a node set containing text nodes' do
before do evaluate_xpath(@document, 'a/text()').should == node_set(@text1)
@set = @evaluator.evaluate('a/text()')
end end
it_behaves_like :node_set, :length => 1 example 'return a node set containing nested text nodes' do
evaluate_xpath(@document, 'a/b/text()').should == node_set(@text2)
example 'return a Text instance' do
@set[0].is_a?(Oga::XML::Text).should == true
end
example 'return the "foo" text node' do
@set[0].text.should == 'foo'
end
end
context 'matching nested text nodes' do
before do
@set = @evaluator.evaluate('a/b/text()')
end
it_behaves_like :node_set, :length => 1
example 'return a Text instance' do
@set[0].is_a?(Oga::XML::Text).should == true
end
example 'return the "bar" text node' do
@set[0].text.should == 'bar'
end
end end
end end
end end