Rewrote all XPath evaluator type test specs.
This commit is contained in:
		
							parent
							
								
									ca5da3f9c9
								
							
						
					
					
						commit
						c5c3c5dbc3
					
				| 
						 | 
				
			
			@ -4,39 +4,17 @@ describe Oga::XPath::Evaluator do
 | 
			
		|||
  context 'comment() tests' do
 | 
			
		||||
    before do
 | 
			
		||||
      @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
 | 
			
		||||
 | 
			
		||||
    context 'matching comment nodes' do
 | 
			
		||||
      before do
 | 
			
		||||
        @set = @evaluator.evaluate('a/comment()')
 | 
			
		||||
    example 'return a node set containing comment nodes' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/comment()').should == node_set(@comment1)
 | 
			
		||||
    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 "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
 | 
			
		||||
    example 'return a node set containing nested comments' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/b/comment()').should == node_set(@comment2)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,55 +4,24 @@ describe Oga::XPath::Evaluator do
 | 
			
		|||
  context 'node() tests' do
 | 
			
		||||
    before do
 | 
			
		||||
      @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
 | 
			
		||||
 | 
			
		||||
    context 'matching elements' do
 | 
			
		||||
      before do
 | 
			
		||||
        @set = @evaluator.evaluate('node()')
 | 
			
		||||
    example 'return a node set containing elements' do
 | 
			
		||||
      evaluate_xpath(@document, 'node()').should == node_set(@a1)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
      it_behaves_like :node_set, :length => 1
 | 
			
		||||
 | 
			
		||||
      example 'return the <a> node' do
 | 
			
		||||
        @set[0].name.should == 'a'
 | 
			
		||||
      end
 | 
			
		||||
    example 'return a node set containing elements, comments and CDATA tags' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/node()')
 | 
			
		||||
        .should == node_set(@b1, @comment1, @cdata1)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    context 'matching nested elements' do
 | 
			
		||||
      before do
 | 
			
		||||
        @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
 | 
			
		||||
    example 'return a node set containing text nodes' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/b/node()').should == node_set(@b1.children[0])
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,39 +4,19 @@ describe Oga::XPath::Evaluator do
 | 
			
		|||
  context 'processing-instruction() tests' do
 | 
			
		||||
    before do
 | 
			
		||||
      @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
 | 
			
		||||
 | 
			
		||||
    context 'matching processing instruction nodes' do
 | 
			
		||||
      before do
 | 
			
		||||
        @set = @evaluator.evaluate('a/processing-instruction()')
 | 
			
		||||
    example 'return a node set containing processing instructions' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/processing-instruction()')
 | 
			
		||||
        .should == node_set(@proc_ins1)
 | 
			
		||||
    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 "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
 | 
			
		||||
    example 'return a node set containing nested processing instructions' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/b/processing-instruction()')
 | 
			
		||||
        .should == node_set(@proc_ins2)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,39 +4,17 @@ describe Oga::XPath::Evaluator do
 | 
			
		|||
  context 'text() tests' do
 | 
			
		||||
    before do
 | 
			
		||||
      @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
 | 
			
		||||
 | 
			
		||||
    context 'matching text nodes' do
 | 
			
		||||
      before do
 | 
			
		||||
        @set = @evaluator.evaluate('a/text()')
 | 
			
		||||
    example 'return a node set containing text nodes' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/text()').should == node_set(@text1)
 | 
			
		||||
    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 "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
 | 
			
		||||
    example 'return a node set containing nested text nodes' do
 | 
			
		||||
      evaluate_xpath(@document, 'a/b/text()').should == node_set(@text2)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue