Revamped compiler type test specs

This commit is contained in:
Yorick Peterse 2015-08-30 01:45:51 +02:00
parent 001c57e0ad
commit 1b62dd3256
5 changed files with 71 additions and 50 deletions

View File

@ -1276,7 +1276,7 @@ module Oga
# @return [Oga::Ruby::Node]
#
def on_type_test(ast, input, &block)
name, followng = *ast
name, following = *ast
handler = name.gsub('-', '_')

View File

@ -1,20 +1,24 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
describe 'comment() tests' do
before do
@document = parse('<a><!--foo--><b><!--bar--></b></a>')
before do
@document = parse('<a><!--foo--><b><!--bar--></b></a>')
@comment1 = @document.children[0].children[0]
@comment2 = @document.children[0].children[1].children[0]
@comment1 = @document.children[0].children[0]
@comment2 = @document.children[0].children[1].children[0]
end
describe 'relative to a document' do
describe 'a/comment()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@comment1)
end
end
it 'returns a node set containing comment nodes' do
evaluate_xpath(@document, 'a/comment()').should == node_set(@comment1)
end
it 'returns a node set containing nested comments' do
evaluate_xpath(@document, 'a/b/comment()').should == node_set(@comment2)
describe 'a/b/comment()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@comment2)
end
end
end
end

View File

@ -1,27 +1,38 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
describe 'node() tests' do
before do
@document = parse('<a><b>foo</b><!--foo--><![CDATA[bar]]></a>')
before do
@document = parse('<a><b>foo</b><!--foo--><![CDATA[bar]]></a>')
@a1 = @document.children[0]
@b1 = @a1.children[0]
@comment1 = @a1.children[1]
@cdata1 = @a1.children[2]
@a1 = @document.children[0]
@b1 = @a1.children[0]
@comment1 = @a1.children[1]
@cdata1 = @a1.children[2]
end
describe 'relative to a document' do
describe 'node()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@a1)
end
end
it 'returns a node set containing elements' do
evaluate_xpath(@document, 'node()').should == node_set(@a1)
describe 'a/node()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@b1, @comment1, @cdata1)
end
end
it 'returns a node set containing elements, comments and CDATA tags' do
evaluate_xpath(@document, 'a/node()')
.should == node_set(@b1, @comment1, @cdata1)
describe 'a/b/node()' do
it 'returns NodeSet' do
evaluate_xpath(@document).should == node_set(@b1.children[0])
end
end
it 'returns a node set containing text nodes' do
evaluate_xpath(@document, 'a/b/node()').should == node_set(@b1.children[0])
describe 'node()/b' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@b1)
end
end
end
end

View File

@ -1,22 +1,24 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
describe 'processing-instruction() tests' do
before do
@document = parse('<a><?a foo ?><b><?b bar ?></b></a>')
before do
@document = parse('<a><?a foo ?><b><?b bar ?></b></a>')
@proc_ins1 = @document.children[0].children[0]
@proc_ins2 = @document.children[0].children[1].children[0]
@proc_ins1 = @document.children[0].children[0]
@proc_ins2 = @document.children[0].children[1].children[0]
end
describe 'relative to a document' do
describe 'a/processing-instruction()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@proc_ins1)
end
end
it 'returns a node set containing processing instructions' do
evaluate_xpath(@document, 'a/processing-instruction()')
.should == node_set(@proc_ins1)
end
it 'returns a node set containing nested processing instructions' do
evaluate_xpath(@document, 'a/b/processing-instruction()')
.should == node_set(@proc_ins2)
describe 'a/b/processing-instruction()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@proc_ins2)
end
end
end
end

View File

@ -1,20 +1,24 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
describe 'text() tests' do
before do
@document = parse('<a>foo<b>bar</b></a>')
before do
@document = parse('<a>foo<b>bar</b></a>')
@text1 = @document.children[0].children[0]
@text2 = @document.children[0].children[1].children[0]
@text1 = @document.children[0].children[0]
@text2 = @document.children[0].children[1].children[0]
end
describe 'relative to a document' do
describe 'a/text()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@text1)
end
end
it 'returns a node set containing text nodes' do
evaluate_xpath(@document, 'a/text()').should == node_set(@text1)
end
it 'returns a node set containing nested text nodes' do
evaluate_xpath(@document, 'a/b/text()').should == node_set(@text2)
describe 'a/b/text()' do
it 'returns a NodeSet' do
evaluate_xpath(@document).should == node_set(@text2)
end
end
end
end