Use describe/it instead of context/example.

This keeps things consistent with the general testing guidelines in the Ruby
community. This in turn should hopefully make my life easier as I don't have to
tell people to use this rather odd stlye I was using before.
This commit is contained in:
Yorick Peterse 2015-01-08 23:01:53 +01:00
parent e138aa15ac
commit 47a3c5e7f8
182 changed files with 1444 additions and 1444 deletions

View File

@ -1,28 +1,28 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context 'axes' do
context '> axis' do
describe 'axes' do
describe '> axis' do
before do
@document = parse('<root><a><a /></a></root>')
@a1 = @document.children[0].children[0]
end
example 'return a node set containing direct child nodes' do
it 'returns a node set containing direct child nodes' do
evaluate_css(@document, 'root > a').should == node_set(@a1)
end
example 'return a node set containing direct child nodes relative to a node' do
it 'returns a node set containing direct child nodes relative to a node' do
evaluate_css(@a1, '> a').should == @a1.children
end
example 'return an empty node set for non matching child nodes' do
it 'returns an empty node set for non matching child nodes' do
evaluate_css(@document, '> a').should == node_set
end
end
context '+ axis' do
describe '+ axis' do
before do
@document = parse('<root><a /><b /><b /></root>')
@ -30,20 +30,20 @@ describe 'CSS selector evaluation' do
@b2 = @document.children[0].children[2]
end
example 'return a node set containing following siblings' do
it 'returns a node set containing following siblings' do
evaluate_css(@document, 'root a + b').should == node_set(@b1)
end
example 'return a node set containing following siblings relatie to a node' do
it 'returns a node set containing following siblings relatie to a node' do
evaluate_css(@b1, '+ b').should == node_set(@b2)
end
example 'return an empty node set for non matching following siblings' do
it 'returns an empty node set for non matching following siblings' do
evaluate_css(@document, 'root a + c').should == node_set
end
end
context '~ axis' do
describe '~ axis' do
before do
@document = parse('<root><a /><b /><b /></root>')
@ -51,15 +51,15 @@ describe 'CSS selector evaluation' do
@b2 = @document.children[0].children[2]
end
example 'return a node set containing following siblings' do
it 'returns a node set containing following siblings' do
evaluate_css(@document, 'root a ~ b').should == node_set(@b1, @b2)
end
example 'return a node set containing following siblings relative to a node' do
it 'returns a node set containing following siblings relative to a node' do
evaluate_css(@b1, '~ b').should == node_set(@b2)
end
example 'return an empty node set for non matching following siblings' do
it 'returns an empty node set for non matching following siblings' do
evaluate_css(@document, 'root a ~ c').should == node_set
end
end

View File

@ -1,26 +1,26 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context 'classes' do
example 'return a node set containing a node with a single class' do
describe 'classes' do
it 'returns a node set containing a node with a single class' do
document = parse('<x class="foo" />')
evaluate_css(document, '.foo').should == document.children
end
example 'return a node set containing a node having one of two classes' do
it 'returns a node set containing a node having one of two classes' do
document = parse('<x class="foo bar" />')
evaluate_css(document, '.foo').should == document.children
end
example 'return a node set containing a node having both classes' do
it 'returns a node set containing a node having both classes' do
document = parse('<x class="foo bar" />')
evaluate_css(document, '.foo.bar').should == document.children
end
example 'return an empty node set for non matching classes' do
it 'returns an empty node set for non matching classes' do
document = parse('<x class="bar" />')
evaluate_css(document, '.foo').should == node_set

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context 'IDs' do
describe 'IDs' do
before do
@document = parse('<x id="foo" />')
end
example 'return a node set containing a node with a single ID' do
it 'returns a node set containing a node with a single ID' do
evaluate_css(@document, '#foo').should == @document.children
end
example 'return an empty node set for non matching IDs' do
it 'returns an empty node set for non matching IDs' do
evaluate_css(@document, '#bar').should == node_set
end
end

View File

@ -1,97 +1,97 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context 'operators' do
context '= operator' do
describe 'operators' do
describe '= operator' do
before do
@document = parse('<x a="b" />')
end
example 'return a node set containing nodes with matching attributes' do
it 'returns a node set containing nodes with matching attributes' do
evaluate_css(@document, 'x[a = "b"]').should == @document.children
end
example 'return an empty node set for non matching attribute values' do
it 'returns an empty node set for non matching attribute values' do
evaluate_css(@document, 'x[a = "c"]').should == node_set
end
end
context '~= operator' do
example 'return a node set containing nodes with matching attributes' do
describe '~= operator' do
it 'returns a node set containing nodes with matching attributes' do
document = parse('<x a="1 2 3" />')
evaluate_css(document, 'x[a ~= "2"]').should == document.children
end
example 'return a node set containing nodes with single attribute values' do
it 'returns a node set containing nodes with single attribute values' do
document = parse('<x a="1" />')
evaluate_css(document, 'x[a ~= "1"]').should == document.children
end
example 'return an empty node set for non matching attributes' do
it 'returns an empty node set for non matching attributes' do
document = parse('<x a="1 2 3" />')
evaluate_css(document, 'x[a ~= "4"]').should == node_set
end
end
context '^= operator' do
describe '^= operator' do
before do
@document = parse('<x a="foo" />')
end
example 'return a node set containing nodes with matching attributes' do
it 'returns a node set containing nodes with matching attributes' do
evaluate_css(@document, 'x[a ^= "fo"]').should == @document.children
end
example 'return an empty node set for non matching attributes' do
it 'returns an empty node set for non matching attributes' do
evaluate_css(@document, 'x[a ^= "bar"]').should == node_set
end
end
context '$= operator' do
describe '$= operator' do
before do
@document = parse('<x a="foo" />')
end
example 'return a node set containing nodes with matching attributes' do
it 'returns a node set containing nodes with matching attributes' do
evaluate_css(@document, 'x[a $= "oo"]').should == @document.children
end
example 'return an empty node set for non matching attributes' do
it 'returns an empty node set for non matching attributes' do
evaluate_css(@document, 'x[a $= "x"]').should == node_set
end
end
context '*= operator' do
describe '*= operator' do
before do
@document = parse('<x a="foo" />')
end
example 'return a node set containing nodes with matching attributes' do
it 'returns a node set containing nodes with matching attributes' do
evaluate_css(@document, 'x[a *= "o"]').should == @document.children
end
example 'return an empty node set for non matching attributes' do
it 'returns an empty node set for non matching attributes' do
evaluate_css(@document, 'x[a *= "x"]').should == node_set
end
end
context '|= operator' do
example 'return a node set containing nodes with matching attributes' do
describe '|= operator' do
it 'returns a node set containing nodes with matching attributes' do
document = parse('<x a="foo-bar" />')
evaluate_css(document, 'x[a |= "foo"]').should == document.children
end
example 'return a node set containing nodes with single attribute values' do
it 'returns a node set containing nodes with single attribute values' do
document = parse('<x a="foo" />')
evaluate_css(document, 'x[a |= "foo"]').should == document.children
end
example 'return an empty node set for non matching attributes' do
it 'returns an empty node set for non matching attributes' do
document = parse('<x a="bar" />')
evaluate_css(document, 'x[a |= "foo"]').should == node_set

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context 'paths' do
describe 'paths' do
before do
@document = parse('<a xmlns:ns1="x"><b></b><b></b><ns1:c></ns1:c></a>')
@ -11,31 +11,31 @@ describe 'CSS selector evaluation' do
@c1 = @a1.children[2]
end
example 'return a node set containing the root node' do
it 'returns a node set containing the root node' do
evaluate_css(@document, 'a').should == node_set(@a1)
end
example 'return a node set containing nested nodes' do
it 'returns a node set containing nested nodes' do
evaluate_css(@document, 'a b').should == node_set(@b1, @b2)
end
example 'return a node set containing namespaced nodes' do
it 'returns a node set containing namespaced nodes' do
evaluate_css(@document, 'a ns1|c').should == node_set(@c1)
end
example 'return a node set containing wildcard nodes' do
it 'returns a node set containing wildcard nodes' do
evaluate_css(@document, 'a *').should == node_set(@b1, @b2, @c1)
end
example 'return a node set containing nodes with namespace wildcards' do
it 'returns a node set containing nodes with namespace wildcards' do
evaluate_css(@document, 'a *|c')
end
example 'return a node set containing nodes with a namespace name and name wildcard' do
it 'returns a node set containing nodes with a namespace name and name wildcard' do
evaluate_css(@document, 'a ns1|*').should == node_set(@c1)
end
example 'return a node set containing nodes using full wildcards' do
it 'returns a node set containing nodes using full wildcards' do
evaluate_css(@document, 'a *|*').should == node_set(@b1, @b2, @c1)
end
end

View File

@ -1,18 +1,18 @@
require 'spec_helper'
context 'CSS selector evaluation' do
context 'predicates' do
describe 'CSS selector evaluation' do
describe 'predicates' do
before do
@document = parse('<root><a class="foo" /></root>')
@a1 = @document.children[0].children[0]
end
example 'return a node set containing nodes with an attribute' do
it 'returns a node set containing nodes with an attribute' do
evaluate_css(@document, 'root a[class]').should == node_set(@a1)
end
example 'return a node set containing nodes with a matching attribute value' do
it 'returns a node set containing nodes with a matching attribute value' do
evaluate_css(@document, 'root a[class="foo"]').should == node_set(@a1)
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':empty pseudo class' do
describe ':empty pseudo class' do
before do
@document = parse('<root><a></a><b>foo</b></root>')
@ -9,15 +9,15 @@ describe 'CSS selector evaluation' do
@b1 = @document.children[0].children[1]
end
example 'return a node set containing empty nodes' do
it 'returns a node set containing empty nodes' do
evaluate_css(@document, 'root :empty').should == node_set(@a1)
end
example 'return a node set containing empty nodes with a node test' do
it 'returns a node set containing empty nodes with a node test' do
evaluate_css(@document, 'root a:empty').should == node_set(@a1)
end
example 'return an empty node set containing non empty nodes' do
it 'returns an empty node set containing non empty nodes' do
evaluate_css(@document, 'root b:empty').should == node_set
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':first-child pseudo class' do
describe ':first-child pseudo class' do
before do
@document = parse('<root><a /><b /></root>')
@ -9,15 +9,15 @@ describe 'CSS selector evaluation' do
@b1 = @document.children[0].children[1]
end
example 'return a node set containing the first child node' do
it 'returns a node set containing the first child node' do
evaluate_css(@document, 'root :first-child').should == node_set(@a1)
end
example 'return a node set containing the first child node with a node test' do
it 'returns a node set containing the first child node with a node test' do
evaluate_css(@document, 'root a:first-child').should == node_set(@a1)
end
example 'return an empty node set for non first-child nodes' do
it 'returns an empty node set for non first-child nodes' do
evaluate_css(@document, 'root b:first-child').should == node_set
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':first-of-type pseudo class' do
describe ':first-of-type pseudo class' do
before do
@document = parse(<<-EOF)
<root>
@ -17,7 +17,7 @@ describe 'CSS selector evaluation' do
@a3 = @document.at_xpath('root/a[2]/a[1]')
end
example 'return a node set containing all first <a> nodes' do
it 'returns a node set containing all first <a> nodes' do
evaluate_css(@document, 'root a:first-of-type')
.should == node_set(@a1, @a3)
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':last-child pseudo class' do
describe ':last-child pseudo class' do
before do
@document = parse('<root><a /><b /></root>')
@ -9,15 +9,15 @@ describe 'CSS selector evaluation' do
@b1 = @document.children[0].children[1]
end
example 'return a node set containing the last child node' do
it 'returns a node set containing the last child node' do
evaluate_css(@document, 'root :last-child').should == node_set(@b1)
end
example 'return a node set containing the last child node with a node test' do
it 'returns a node set containing the last child node with a node test' do
evaluate_css(@document, 'root b:last-child').should == node_set(@b1)
end
example 'return an empty node set for non last-child nodes' do
it 'returns an empty node set for non last-child nodes' do
evaluate_css(@document, 'root a:last-child').should == node_set
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':last-of-type pseudo class' do
describe ':last-of-type pseudo class' do
before do
@document = parse(<<-EOF)
<root>
@ -17,7 +17,7 @@ describe 'CSS selector evaluation' do
@a4 = @document.at_xpath('root/a[2]/a[2]')
end
example 'return a node set containing all last <a> nodes' do
it 'returns a node set containing all last <a> nodes' do
evaluate_css(@document, 'root a:last-of-type')
.should == node_set(@a2, @a4)
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':nth-child pseudo class' do
describe ':nth-child pseudo class' do
before do
@document = parse('<root><a1 /><a2 /><a3 /><a4 /></root>')
@ -12,35 +12,35 @@ describe 'CSS selector evaluation' do
@a4 = @root.children[3]
end
example 'return a node set containing the first child node' do
it 'returns a node set containing the first child node' do
evaluate_css(@document, 'root :nth-child(1)').should == node_set(@a1)
end
example 'return a node set containing even nodes' do
it 'returns a node set containing even nodes' do
evaluate_css(@document, 'root :nth-child(even)')
.should == node_set(@a2, @a4)
end
example 'return a node set containing odd nodes' do
it 'returns a node set containing odd nodes' do
evaluate_css(@document, 'root :nth-child(odd)')
.should == node_set(@a1, @a3)
end
example 'return a node set containing every 2 nodes starting at node 2' do
it 'returns a node set containing every 2 nodes starting at node 2' do
evaluate_css(@document, 'root :nth-child(2n+2)')
.should == node_set(@a2, @a4)
end
example 'return a node set containing all nodes' do
it 'returns a node set containing all nodes' do
evaluate_css(@document, 'root :nth-child(n)').should == @root.children
end
example 'return a node set containing the first two nodes' do
it 'returns a node set containing the first two nodes' do
evaluate_css(@document, 'root :nth-child(-n+2)')
.should == node_set(@a1, @a2)
end
example 'return a node set containing all nodes starting at node 2' do
it 'returns a node set containing all nodes starting at node 2' do
evaluate_css(@document, 'root :nth-child(n+2)')
.should == node_set(@a2, @a3, @a4)
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':nth-last-child pseudo class' do
describe ':nth-last-child pseudo class' do
before do
@document = parse('<root><a1 /><a2 /><a3 /><a4 /></root>')
@ -12,36 +12,36 @@ describe 'CSS selector evaluation' do
@a4 = @root.children[3]
end
example 'return a node set containing the last child node' do
it 'returns a node set containing the last child node' do
evaluate_css(@document, 'root :nth-last-child(1)').should == node_set(@a4)
end
example 'return a node set containing even nodes' do
it 'returns a node set containing even nodes' do
evaluate_css(@document, 'root :nth-last-child(even)')
.should == node_set(@a1, @a3)
end
example 'return a node set containing odd nodes' do
it 'returns a node set containing odd nodes' do
evaluate_css(@document, 'root :nth-last-child(odd)')
.should == node_set(@a2, @a4)
end
example 'return a node set containing every 2 nodes starting at node 3' do
it 'returns a node set containing every 2 nodes starting at node 3' do
evaluate_css(@document, 'root :nth-last-child(2n+2)')
.should == node_set(@a1, @a3)
end
example 'return a node set containing all nodes' do
it 'returns a node set containing all nodes' do
evaluate_css(@document, 'root :nth-last-child(n)')
.should == @root.children
end
example 'return a node set containing the first two nodes' do
it 'returns a node set containing the first two nodes' do
evaluate_css(@document, 'root :nth-last-child(-n+2)')
.should == node_set(@a3, @a4)
end
example 'return a node set containing all nodes starting at node 2' do
it 'returns a node set containing all nodes starting at node 2' do
evaluate_css(@document, 'root :nth-last-child(n+2)')
.should == node_set(@a1, @a2, @a3)
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':nth-last-of-type pseudo class' do
describe ':nth-last-of-type pseudo class' do
before do
@document = parse(<<-EOF.strip)
<root>
@ -21,37 +21,37 @@ describe 'CSS selector evaluation' do
@a4 = @root.at_xpath('b/a')
end
example 'return a node set containing the first child node' do
it 'returns a node set containing the first child node' do
evaluate_css(@document, 'root a:nth-last-of-type(1)')
.should == node_set(@a3, @a4)
end
example 'return a node set containing even nodes' do
it 'returns a node set containing even nodes' do
evaluate_css(@document, 'root a:nth-last-of-type(even)')
.should == node_set(@a2)
end
example 'return a node set containing odd nodes' do
it 'returns a node set containing odd nodes' do
evaluate_css(@document, 'root a:nth-last-of-type(odd)')
.should == node_set(@a1, @a3, @a4)
end
example 'return a node set containing every 2 nodes starting at node 2' do
it 'returns a node set containing every 2 nodes starting at node 2' do
evaluate_css(@document, 'root a:nth-last-of-type(2n+2)')
.should == node_set(@a2)
end
example 'return a node set containing all nodes' do
it 'returns a node set containing all nodes' do
evaluate_css(@document, 'root a:nth-last-of-type(n)')
.should == node_set(@a1, @a2, @a3, @a4)
end
example 'return a node set containing the first two nodes' do
it 'returns a node set containing the first two nodes' do
evaluate_css(@document, 'root a:nth-last-of-type(-n+2)')
.should == node_set(@a2, @a3, @a4)
end
example 'return a node set containing all nodes starting at node 2' do
it 'returns a node set containing all nodes starting at node 2' do
evaluate_css(@document, 'root a:nth-last-of-type(n+2)')
.should == node_set(@a1, @a2)
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':nth-of-type pseudo class' do
describe ':nth-of-type pseudo class' do
before do
@document = parse(<<-EOF.strip)
<root>
@ -21,37 +21,37 @@ describe 'CSS selector evaluation' do
@a4 = @root.at_xpath('b/a')
end
example 'return a node set containing the first child node' do
it 'returns a node set containing the first child node' do
evaluate_css(@document, 'root a:nth-of-type(1)')
.should == node_set(@a1, @a4)
end
example 'return a node set containing even nodes' do
it 'returns a node set containing even nodes' do
evaluate_css(@document, 'root a:nth-of-type(even)')
.should == node_set(@a2)
end
example 'return a node set containing odd nodes' do
it 'returns a node set containing odd nodes' do
evaluate_css(@document, 'root a:nth-of-type(odd)')
.should == node_set(@a1, @a3, @a4)
end
example 'return a node set containing every 2 nodes starting at node 2' do
it 'returns a node set containing every 2 nodes starting at node 2' do
evaluate_css(@document, 'root a:nth-of-type(2n+2)')
.should == node_set(@a2)
end
example 'return a node set containing all nodes' do
it 'returns a node set containing all nodes' do
evaluate_css(@document, 'root a:nth-of-type(n)')
.should == node_set(@a1, @a2, @a3, @a4)
end
example 'return a node set containing the first two nodes' do
it 'returns a node set containing the first two nodes' do
evaluate_css(@document, 'root a:nth-of-type(-n+2)')
.should == node_set(@a1, @a2, @a4)
end
example 'return a node set containing all nodes starting at node 2' do
it 'returns a node set containing all nodes starting at node 2' do
evaluate_css(@document, 'root a:nth-of-type(n+2)')
.should == node_set(@a2, @a3)
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':only-child pseudo class' do
describe ':only-child pseudo class' do
before do
@document = parse('<root><a><c /></a><b><c /></b></root>')
@ -10,7 +10,7 @@ describe 'CSS selector evaluation' do
@c2 = @root.children[1].children[0]
end
example 'return a node set containing <c> nodes' do
it 'returns a node set containing <c> nodes' do
evaluate_css(@document, 'root :only-child').should == node_set(@c1, @c2)
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':only-of-type pseudo class' do
describe ':only-of-type pseudo class' do
before do
@document = parse('<root><a><c /></a><b><c /></b></root>')
@ -10,7 +10,7 @@ describe 'CSS selector evaluation' do
@c2 = @root.children[1].children[0]
end
example 'return a node set containing <c> nodes' do
it 'returns a node set containing <c> nodes' do
evaluate_css(@document, 'root a :only-of-type').should == node_set(@c1)
end
end

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe 'CSS selector evaluation' do
context ':root pseudo class' do
describe ':root pseudo class' do
before do
@document = parse('<root><a /></root>')
end
example 'return a node set containing the root node' do
it 'returns a node set containing the root node' do
evaluate_css(@document, ':root').should == @document.children
end
end

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'axes' do
example 'lex the > axis' do
describe 'axes' do
it 'lexes the > axis' do
lex_css('>').should == [[:T_GREATER, nil]]
end
example 'lex the expression "> y"' do
it 'lexes the expression "> y"' do
lex_css('> y').should == [[:T_GREATER, nil], [:T_IDENT, 'y']]
end
example 'lex the expression "x > y"' do
it 'lexes the expression "x > y"' do
lex_css('x > y').should == [
[:T_IDENT, 'x'],
[:T_SPACE, nil],
@ -19,15 +19,15 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the + axis' do
it 'lexes the + axis' do
lex_css('+').should == [[:T_PLUS, nil]]
end
example 'lex the expression "+ y"' do
it 'lexes the expression "+ y"' do
lex_css('+ y').should == [[:T_PLUS, nil], [:T_IDENT, 'y']]
end
example 'lex the expression "x + y"' do
it 'lexes the expression "x + y"' do
lex_css('x + y').should == [
[:T_IDENT, 'x'],
[:T_SPACE, nil],
@ -36,15 +36,15 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the ~ axis' do
it 'lexes the ~ axis' do
lex_css('~').should == [[:T_TILDE, nil]]
end
example 'lex the expression "~ y"' do
it 'lexes the expression "~ y"' do
lex_css('~ y').should == [[:T_TILDE, nil], [:T_IDENT, 'y']]
end
example 'lex the expression "x ~ y"' do
it 'lexes the expression "x ~ y"' do
lex_css('x ~ y').should == [
[:T_IDENT, 'x'],
[:T_SPACE, nil],

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'namespaces' do
example 'lex a path containing a namespace name' do
describe 'namespaces' do
it 'lexes a path containing a namespace name' do
lex_css('foo|bar').should == [
[:T_IDENT, 'foo'],
[:T_PIPE, nil],
@ -10,7 +10,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex a path containing a namespace wildcard' do
it 'lexes a path containing a namespace wildcard' do
lex_css('*|foo').should == [
[:T_IDENT, '*'],
[:T_PIPE, nil],

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'operators' do
example 'lex the = operator' do
describe 'operators' do
it 'lexes the = operator' do
lex_css('[=]').should == [
[:T_LBRACK, nil],
[:T_EQ, nil],
@ -10,7 +10,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the ~= operator' do
it 'lexes the ~= operator' do
lex_css('[~=]').should == [
[:T_LBRACK, nil],
[:T_SPACE_IN, nil],
@ -18,7 +18,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the ^= operator' do
it 'lexes the ^= operator' do
lex_css('[^=]').should == [
[:T_LBRACK, nil],
[:T_STARTS_WITH, nil],
@ -26,7 +26,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the $= operator' do
it 'lexes the $= operator' do
lex_css('[$=]').should == [
[:T_LBRACK, nil],
[:T_ENDS_WITH, nil],
@ -34,7 +34,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the *= operator' do
it 'lexes the *= operator' do
lex_css('[*=]').should == [
[:T_LBRACK, nil],
[:T_IN, nil],
@ -42,7 +42,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex an identifier followed by the *= operator' do
it 'lexes an identifier followed by the *= operator' do
lex_css('[foo *=]').should == [
[:T_LBRACK, nil],
[:T_IDENT, 'foo'],
@ -51,7 +51,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the |= operator' do
it 'lexes the |= operator' do
lex_css('[|=]').should == [
[:T_LBRACK, nil],
[:T_HYPHEN_IN, nil],

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'paths' do
example 'lex a simple path' do
describe 'paths' do
it 'lexes a simple path' do
lex_css('h3').should == [[:T_IDENT, 'h3']]
end
example 'lex a simple path starting with an underscore' do
it 'lexes a simple path starting with an underscore' do
lex_css('_h3').should == [[:T_IDENT, '_h3']]
end
example 'lex a path with two members' do
it 'lexes a path with two members' do
lex_css('div h3').should == [
[:T_IDENT, 'div'],
[:T_SPACE, nil],
@ -18,7 +18,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex a path with two members separated by multiple spaces' do
it 'lexes a path with two members separated by multiple spaces' do
lex_css('div h3').should == [
[:T_IDENT, 'div'],
[:T_SPACE, nil],
@ -26,7 +26,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex two paths' do
it 'lexes two paths' do
lex_css('foo, bar').should == [
[:T_IDENT, 'foo'],
[:T_COMMA, nil],
@ -34,21 +34,21 @@ describe Oga::CSS::Lexer do
]
end
example 'lex a path selecting an ID' do
it 'lexes a path selecting an ID' do
lex_css('#foo').should == [
[:T_HASH, nil],
[:T_IDENT, 'foo']
]
end
example 'lex a path selecting a class' do
it 'lexes a path selecting a class' do
lex_css('.foo').should == [
[:T_DOT, nil],
[:T_IDENT, 'foo']
]
end
example 'lex a wildcard path' do
it 'lexes a wildcard path' do
lex_css('*').should == [[:T_IDENT, '*']]
end
end

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'predicates' do
example 'lex a path containing a simple predicate' do
describe 'predicates' do
it 'lexes a path containing a simple predicate' do
lex_css('foo[bar]').should == [
[:T_IDENT, 'foo'],
[:T_LBRACK, nil],

View File

@ -1,15 +1,15 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'pseudo classes' do
example 'lex the :root pseudo class' do
describe 'pseudo classes' do
it 'lexes the :root pseudo class' do
lex_css(':root').should == [
[:T_COLON, nil],
[:T_IDENT, 'root']
]
end
example 'lex the :nth-child pseudo class' do
it 'lexes the :nth-child pseudo class' do
lex_css(':nth-child(1)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -19,7 +19,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child pseudo class with extra whitespace' do
it 'lexes the :nth-child pseudo class with extra whitespace' do
lex_css(':nth-child( 1)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -29,7 +29,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(odd) pseudo class' do
it 'lexes the :nth-child(odd) pseudo class' do
lex_css(':nth-child(odd)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -39,7 +39,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(even) pseudo class' do
it 'lexes the :nth-child(even) pseudo class' do
lex_css(':nth-child(even)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -49,7 +49,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(n) pseudo class' do
it 'lexes the :nth-child(n) pseudo class' do
lex_css(':nth-child(n)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -59,7 +59,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(-n) pseudo class' do
it 'lexes the :nth-child(-n) pseudo class' do
lex_css(':nth-child(-n)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -70,7 +70,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(2n) pseudo class' do
it 'lexes the :nth-child(2n) pseudo class' do
lex_css(':nth-child(2n)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -81,7 +81,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(2n+1) pseudo class' do
it 'lexes the :nth-child(2n+1) pseudo class' do
lex_css(':nth-child(2n+1)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -93,7 +93,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(2n-1) pseudo class' do
it 'lexes the :nth-child(2n-1) pseudo class' do
lex_css(':nth-child(2n-1)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -105,7 +105,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :nth-child(-2n-1) pseudo class' do
it 'lexes the :nth-child(-2n-1) pseudo class' do
lex_css(':nth-child(-2n-1)').should == [
[:T_COLON, nil],
[:T_IDENT, 'nth-child'],
@ -117,7 +117,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex the :lang(fr) pseudo class' do
it 'lexes the :lang(fr) pseudo class' do
lex_css(':lang(fr)').should == [
[:T_COLON, nil],
[:T_IDENT, 'lang'],

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Lexer do
context 'strings' do
example 'lex a single quoted string' do
describe 'strings' do
it 'lexes a single quoted string' do
lex_css("['foo']").should == [
[:T_LBRACK, nil],
[:T_STRING, 'foo'],
@ -10,7 +10,7 @@ describe Oga::CSS::Lexer do
]
end
example 'lex a double quoted string' do
it 'lexes a double quoted string' do
lex_css('["foo"]').should == [
[:T_LBRACK, nil],
[:T_STRING, 'foo'],

View File

@ -1,53 +1,53 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'axes' do
example 'parse the > axis' do
describe 'axes' do
it 'parses the > axis' do
parse_css('x > y').should == parse_xpath('descendant::x/y')
end
example 'parse the > axis called on another > axis' do
it 'parses the > axis called on another > axis' do
parse_css('a > b > c').should == parse_xpath('descendant::a/b/c')
end
example 'parse an > axis followed by an element with an ID' do
it 'parses an > axis followed by an element with an ID' do
parse_css('x > foo#bar').should == parse_xpath(
'descendant::x/foo[@id="bar"]'
)
end
example 'parse an > axis followed by an element with a class' do
it 'parses an > axis followed by an element with a class' do
parse_css('x > foo.bar').should == parse_xpath(
'descendant::x/foo[contains(concat(" ", @class, " "), " bar ")]'
)
end
example 'parse the + axis' do
it 'parses the + axis' do
parse_css('x + y').should == parse_xpath(
'descendant::x/following-sibling::*[1]/self::y'
)
end
example 'parse the + axis called on another + axis' do
it 'parses the + axis called on another + axis' do
parse_css('a + b + c').should == parse_xpath(
'descendant::a/following-sibling::*[1]/self::b/' \
'following-sibling::*[1]/self::c'
)
end
example 'parse the ~ axis' do
it 'parses the ~ axis' do
parse_css('x ~ y').should == parse_xpath(
'descendant::x/following-sibling::y'
)
end
example 'parse the ~ axis followed by another node test' do
it 'parses the ~ axis followed by another node test' do
parse_css('x ~ y z').should == parse_xpath(
'descendant::x/following-sibling::y/descendant::z'
)
end
example 'parse the ~ axis called on another ~ axis' do
it 'parses the ~ axis called on another ~ axis' do
parse_css('a ~ b ~ c').should == parse_xpath(
'descendant::a/following-sibling::b/following-sibling::c'
)

View File

@ -1,27 +1,27 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'classes' do
example 'parse a class selector' do
describe 'classes' do
it 'parses a class selector' do
parse_css('.foo').should == parse_xpath(
'descendant::*[contains(concat(" ", @class, " "), " foo ")]'
)
end
example 'parse a selector for an element with a class' do
it 'parses a selector for an element with a class' do
parse_css('foo.bar').should == parse_xpath(
'descendant::foo[contains(concat(" ", @class, " "), " bar ")]'
)
end
example 'parse a selector using multiple classes' do
it 'parses a selector using multiple classes' do
parse_css('.foo.bar').should == parse_xpath(
'descendant::*[contains(concat(" ", @class, " "), " foo ") ' \
'and contains(concat(" ", @class, " "), " bar ")]'
)
end
example 'parse a selector using a class and an ID' do
it 'parses a selector using a class and an ID' do
parse_css('#foo.bar').should == parse_xpath(
'descendant::*[@id="foo" and ' \
'contains(concat(" ", @class, " "), " bar ")]'

View File

@ -1,22 +1,22 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'IDs' do
example 'parse an ID selector' do
describe 'IDs' do
it 'parses an ID selector' do
parse_css('#foo').should == parse_xpath('descendant::*[@id="foo"]')
end
example 'parse a selector for an element with an ID' do
it 'parses a selector for an element with an ID' do
parse_css('foo#bar').should == parse_xpath('descendant::foo[@id="bar"]')
end
example 'parse a selector using multiple IDs' do
it 'parses a selector using multiple IDs' do
parse_css('#foo#bar').should == parse_xpath(
'descendant::*[@id="foo" and @id="bar"]'
)
end
example 'parse a selector using an ID and a class' do
it 'parses a selector using an ID and a class' do
parse_css('.foo#bar').should == parse_xpath(
'descendant::*[contains(concat(" ", @class, " "), " foo ") ' \
'and @id="bar"]'

View File

@ -1,38 +1,38 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'operators' do
example 'parse the = operator' do
describe 'operators' do
it 'parses the = operator' do
parse_css('x[a="b"]').should == parse_xpath('descendant::x[@a="b"]')
end
example 'parse the ~= operator' do
it 'parses the ~= operator' do
parse_css('x[a~="b"]').should == parse_xpath(
'descendant::x[contains(concat(" ", @a, " "), ' \
'concat(" ", "b", " "))]'
)
end
example 'parse the ^= operator' do
it 'parses the ^= operator' do
parse_css('x[a^="b"]').should == parse_xpath(
'descendant::x[starts-with(@a, "b")]'
)
end
example 'parse the $= operator' do
it 'parses the $= operator' do
parse_css('x[a$="b"]').should == parse_xpath(
'descendant::x[substring(@a, string-length(@a) - ' \
'string-length("b") + 1, string-length("b")) = "b"]'
)
end
example 'parse the *= operator' do
it 'parses the *= operator' do
parse_css('x[a*="b"]').should == parse_xpath(
'descendant::x[contains(@a, "b")]'
)
end
example 'parse the |= operator' do
it 'parses the |= operator' do
parse_css('x[a|="b"]').should == parse_xpath(
'descendant::x[@a = "b" or starts-with(@a, concat("b", "-"))]'
)

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'paths' do
example 'parse a single path' do
describe 'paths' do
it 'parses a single path' do
parse_css('foo').should == parse_xpath('descendant::foo')
end
example 'parse a path using a namespace' do
it 'parses a path using a namespace' do
parse_css('ns|foo').should == parse_xpath('descendant::ns:foo')
end
example 'parse a path using two selectors' do
it 'parses a path using two selectors' do
parse_css('foo bar').should == parse_xpath(
'descendant::foo/descendant::bar'
)

View File

@ -1,18 +1,18 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'predicates' do
example 'parse a predicate' do
describe 'predicates' do
it 'parses a predicate' do
parse_css('foo[bar]').should == parse_xpath('descendant::foo[@bar]')
end
example 'parse a node test followed by a node test with a predicate' do
it 'parses a node test followed by a node test with a predicate' do
parse_css('foo bar[baz]').should == parse_xpath(
'descendant::foo/descendant::bar[@baz]'
)
end
example 'parse a predicate testing an attribute value' do
it 'parses a predicate testing an attribute value' do
parse_css('foo[bar="baz"]').should == parse_xpath(
'descendant::foo[@bar="baz"]'
)

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':empty pseudo class' do
example 'parse the :empty pseudo class' do
describe ':empty pseudo class' do
it 'parses the :empty pseudo class' do
parse_css(':empty').should == parse_xpath('descendant::*[not(node())]')
end
end

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':first-child pseudo class' do
example 'parse the :first-child pseudo class' do
describe ':first-child pseudo class' do
it 'parses the :first-child pseudo class' do
parse_css(':first-child').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0]'
)

View File

@ -1,14 +1,14 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':first-of-type pseudo class' do
example 'parse the :first-of-type pseudo class' do
describe ':first-of-type pseudo class' do
it 'parses the :first-of-type pseudo class' do
parse_css(':first-of-type').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0]'
)
end
example 'parse the a:first-of-type pseudo class' do
it 'parses the a:first-of-type pseudo class' do
parse_css('a:first-of-type').should == parse_xpath(
'descendant::a[count(preceding-sibling::a) = 0]'
)

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':last-child pseudo class' do
example 'parse the :last-child pseudo class' do
describe ':last-child pseudo class' do
it 'parses the :last-child pseudo class' do
parse_css(':last-child').should == parse_xpath(
'descendant::*[count(following-sibling::*) = 0]'
)

View File

@ -1,14 +1,14 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':last-of-type pseudo class' do
example 'parse the :last-of-type pseudo class' do
describe ':last-of-type pseudo class' do
it 'parses the :last-of-type pseudo class' do
parse_css(':last-of-type').should == parse_xpath(
'descendant::*[count(following-sibling::*) = 0]'
)
end
example 'parse the a:last-of-type pseudo class' do
it 'parses the a:last-of-type pseudo class' do
parse_css('a:last-of-type').should == parse_xpath(
'descendant::a[count(following-sibling::a) = 0]'
)

View File

@ -1,90 +1,90 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':nth-child pseudo class' do
example 'parse the x:nth-child(1) pseudo class' do
describe ':nth-child pseudo class' do
it 'parses the x:nth-child(1) pseudo class' do
parse_css('x:nth-child(1)').should == parse_xpath(
'descendant::x[count(preceding-sibling::*) = 0]'
)
end
example 'parse the :nth-child(1) pseudo class' do
it 'parses the :nth-child(1) pseudo class' do
parse_css(':nth-child(1)').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0]'
)
end
example 'parse the :nth-child(2) pseudo class' do
it 'parses the :nth-child(2) pseudo class' do
parse_css(':nth-child(2)').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 1]'
)
end
example 'parse the x:nth-child(even) pseudo class' do
it 'parses the x:nth-child(even) pseudo class' do
parse_css('x:nth-child(even)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::*) + 1) mod 2) = 0]'
)
end
example 'parse the x:nth-child(odd) pseudo class' do
it 'parses the x:nth-child(odd) pseudo class' do
parse_css('x:nth-child(odd)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::*) + 1) >= 1 ' \
'and (((count(preceding-sibling::*) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-child(n) pseudo class' do
it 'parses the x:nth-child(n) pseudo class' do
parse_css('x:nth-child(n)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::*) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-child(-n) pseudo class' do
it 'parses the x:nth-child(-n) pseudo class' do
parse_css('x:nth-child(-n)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::*) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-child(-n+6) pseudo class' do
it 'parses the x:nth-child(-n+6) pseudo class' do
parse_css('x:nth-child(-n+6)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::*) + 1) <= 6) ' \
'and (((count(preceding-sibling::*) + 1) - 6) mod 1) = 0]'
)
end
example 'parse the x:nth-child(n+5) pseudo class' do
it 'parses the x:nth-child(n+5) pseudo class' do
parse_css('x:nth-child(n+5)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::*) + 1) >= 5 ' \
'and (((count(preceding-sibling::*) + 1) - 5) mod 1) = 0]'
)
end
example 'parse the x:nth-child(2n) pseudo class' do
it 'parses the x:nth-child(2n) pseudo class' do
parse_css('x:nth-child(2n)').should == parse_css('x:nth-child(even)')
end
example 'parse the x:nth-child(2n+1) pseudo class' do
it 'parses the x:nth-child(2n+1) pseudo class' do
parse_css('x:nth-child(2n+1)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::*) + 1) >= 1 ' \
'and (((count(preceding-sibling::*) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-child(3n+1) pseudo class' do
it 'parses the x:nth-child(3n+1) pseudo class' do
parse_css('x:nth-child(3n+1)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::*) + 1) >= 1 ' \
'and (((count(preceding-sibling::*) + 1) - 1) mod 3) = 0]'
)
end
example 'parse the x:nth-child(2n-6) pseudo class' do
it 'parses the x:nth-child(2n-6) pseudo class' do
parse_css('x:nth-child(2n-6)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::*) + 1) >= 2 ' \
'and (((count(preceding-sibling::*) + 1) - 2) mod 2) = 0]'
)
end
example 'parse the x:nth-child(-2n+6) pseudo class' do
it 'parses the x:nth-child(-2n+6) pseudo class' do
parse_css('x:nth-child(-2n+6)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::*) + 1) <= 6) ' \
'and (((count(preceding-sibling::*) + 1) - 6) mod 2) = 0]'

View File

@ -1,85 +1,85 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':nth-last-child pseudo class' do
example 'parse the x:nth-last-child(1) pseudo class' do
describe ':nth-last-child pseudo class' do
it 'parses the x:nth-last-child(1) pseudo class' do
parse_css('x:nth-last-child(1)').should == parse_xpath(
'descendant::x[count(following-sibling::*) = 0]'
)
end
example 'parse the :nth-last-child(1) pseudo class' do
it 'parses the :nth-last-child(1) pseudo class' do
parse_css(':nth-last-child(1)').should == parse_xpath(
'descendant::*[count(following-sibling::*) = 0]'
)
end
example 'parse the :nth-last-child(2) pseudo class' do
it 'parses the :nth-last-child(2) pseudo class' do
parse_css(':nth-last-child(2)').should == parse_xpath(
'descendant::*[count(following-sibling::*) = 1]'
)
end
example 'parse the x:nth-last-child(even) pseudo class' do
it 'parses the x:nth-last-child(even) pseudo class' do
parse_css('x:nth-last-child(even)').should == parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) mod 2) = 0]'
)
end
example 'parse the x:nth-last-child(odd) pseudo class' do
it 'parses the x:nth-last-child(odd) pseudo class' do
parse_css('x:nth-last-child(odd)').should == parse_xpath(
'descendant::x[(count(following-sibling::*) + 1) >= 1 ' \
'and (((count(following-sibling::*) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-last-child(n) pseudo class' do
it 'parses the x:nth-last-child(n) pseudo class' do
parse_css('x:nth-last-child(n)').should == parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-last-child(-n) pseudo class' do
it 'parses the x:nth-last-child(-n) pseudo class' do
parse_css('x:nth-last-child(-n)').should == parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-last-child(-n+6) pseudo class' do
it 'parses the x:nth-last-child(-n+6) pseudo class' do
parse_css('x:nth-last-child(-n+6)').should == parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) <= 6) ' \
'and (((count(following-sibling::*) + 1) - 6) mod 1) = 0]'
)
end
example 'parse the x:nth-last-child(2n) pseudo class' do
it 'parses the x:nth-last-child(2n) pseudo class' do
parse_css('x:nth-last-child(2n)').should == parse_css(
'x:nth-last-child(even)'
)
end
example 'parse the x:nth-last-child(2n+1) pseudo class' do
it 'parses the x:nth-last-child(2n+1) pseudo class' do
parse_css('x:nth-last-child(2n+1)').should == parse_xpath(
'descendant::x[(count(following-sibling::*) + 1) >= 1 ' \
'and (((count(following-sibling::*) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-last-child(2n-6) pseudo class' do
it 'parses the x:nth-last-child(2n-6) pseudo class' do
parse_css('x:nth-last-child(2n-6)').should == parse_xpath(
'descendant::x[(count(following-sibling::*) + 1) >= 2 ' \
'and (((count(following-sibling::*) + 1) - 2) mod 2) = 0]'
)
end
example 'parse the x:nth-last-child(-2n-6) pseudo class' do
it 'parses the x:nth-last-child(-2n-6) pseudo class' do
parse_css('x:nth-last-child(-2n-6)').should == parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) <= -2) ' \
'and (((count(following-sibling::*) + 1) - -2) mod 2) = 0]'
)
end
example 'parse the x:nth-last-child(-2n+6) pseudo class' do
it 'parses the x:nth-last-child(-2n+6) pseudo class' do
parse_css('x:nth-last-child(-2n+6)').should == parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) <= 6) ' \
'and (((count(following-sibling::*) + 1) - 6) mod 2) = 0]'

View File

@ -1,91 +1,91 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':nth-last-of-type pseudo class' do
example 'parse the x:nth-last-of-type(1) pseudo class' do
describe ':nth-last-of-type pseudo class' do
it 'parses the x:nth-last-of-type(1) pseudo class' do
parse_css('x:nth-last-of-type(1)').should == parse_xpath(
'descendant::x[count(following-sibling::x) = 0]'
)
end
example 'parse the :nth-last-of-type(1) pseudo class' do
it 'parses the :nth-last-of-type(1) pseudo class' do
parse_css(':nth-last-of-type(1)').should == parse_xpath(
'descendant::*[count(following-sibling::*) = 0]'
)
end
example 'parse the :nth-last-of-type(2) pseudo class' do
it 'parses the :nth-last-of-type(2) pseudo class' do
parse_css(':nth-last-of-type(2)').should == parse_xpath(
'descendant::*[count(following-sibling::*) = 1]'
)
end
example 'parse the x:nth-last-of-type(even) pseudo class' do
it 'parses the x:nth-last-of-type(even) pseudo class' do
parse_css('x:nth-last-of-type(even)').should == parse_xpath(
'descendant::x[((count(following-sibling::x) + 1) mod 2) = 0]'
)
end
example 'parse the x:nth-last-of-type(odd) pseudo class' do
it 'parses the x:nth-last-of-type(odd) pseudo class' do
parse_css('x:nth-last-of-type(odd)').should == parse_xpath(
'descendant::x[(count(following-sibling::x) + 1) >= 1 ' \
'and (((count(following-sibling::x) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-last-of-type(n) pseudo class' do
it 'parses the x:nth-last-of-type(n) pseudo class' do
parse_css('x:nth-last-of-type(n)').should == parse_xpath(
'descendant::x[((count(following-sibling::x) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-last-of-type(-n) pseudo class' do
it 'parses the x:nth-last-of-type(-n) pseudo class' do
parse_css('x:nth-last-of-type(-n)').should == parse_xpath(
'descendant::x[((count(following-sibling::x) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-last-of-type(-n+6) pseudo class' do
it 'parses the x:nth-last-of-type(-n+6) pseudo class' do
parse_css('x:nth-last-of-type(-n+6)').should == parse_xpath(
'descendant::x[((count(following-sibling::x) + 1) <= 6) ' \
'and (((count(following-sibling::x) + 1) - 6) mod 1) = 0]'
)
end
example 'parse the x:nth-last-of-type(n+5) pseudo class' do
it 'parses the x:nth-last-of-type(n+5) pseudo class' do
parse_css('x:nth-last-of-type(n+5)').should == parse_xpath(
'descendant::x[(count(following-sibling::x) + 1) >= 5 ' \
'and (((count(following-sibling::x) + 1) - 5) mod 1) = 0]'
)
end
example 'parse the x:nth-last-of-type(2n) pseudo class' do
it 'parses the x:nth-last-of-type(2n) pseudo class' do
parse_css('x:nth-last-of-type(2n)')
.should == parse_css('x:nth-last-of-type(even)')
end
example 'parse the x:nth-last-of-type(2n+1) pseudo class' do
it 'parses the x:nth-last-of-type(2n+1) pseudo class' do
parse_css('x:nth-last-of-type(2n+1)').should == parse_xpath(
'descendant::x[(count(following-sibling::x) + 1) >= 1 ' \
'and (((count(following-sibling::x) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-last-of-type(3n+1) pseudo class' do
it 'parses the x:nth-last-of-type(3n+1) pseudo class' do
parse_css('x:nth-last-of-type(3n+1)').should == parse_xpath(
'descendant::x[(count(following-sibling::x) + 1) >= 1 ' \
'and (((count(following-sibling::x) + 1) - 1) mod 3) = 0]'
)
end
example 'parse the x:nth-last-of-type(2n-6) pseudo class' do
it 'parses the x:nth-last-of-type(2n-6) pseudo class' do
parse_css('x:nth-last-of-type(2n-6)').should == parse_xpath(
'descendant::x[(count(following-sibling::x) + 1) >= 2 ' \
'and (((count(following-sibling::x) + 1) - 2) mod 2) = 0]'
)
end
example 'parse the x:nth-last-of-type(-2n+6) pseudo class' do
it 'parses the x:nth-last-of-type(-2n+6) pseudo class' do
parse_css('x:nth-last-of-type(-2n+6)').should == parse_xpath(
'descendant::x[((count(following-sibling::x) + 1) <= 6) ' \
'and (((count(following-sibling::x) + 1) - 6) mod 2) = 0]'

View File

@ -1,90 +1,90 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':nth-of-type pseudo class' do
example 'parse the x:nth-of-type(1) pseudo class' do
describe ':nth-of-type pseudo class' do
it 'parses the x:nth-of-type(1) pseudo class' do
parse_css('x:nth-of-type(1)').should == parse_xpath(
'descendant::x[count(preceding-sibling::x) = 0]'
)
end
example 'parse the :nth-of-type(1) pseudo class' do
it 'parses the :nth-of-type(1) pseudo class' do
parse_css(':nth-of-type(1)').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0]'
)
end
example 'parse the :nth-of-type(2) pseudo class' do
it 'parses the :nth-of-type(2) pseudo class' do
parse_css(':nth-of-type(2)').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 1]'
)
end
example 'parse the x:nth-of-type(even) pseudo class' do
it 'parses the x:nth-of-type(even) pseudo class' do
parse_css('x:nth-of-type(even)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::x) + 1) mod 2) = 0]'
)
end
example 'parse the x:nth-of-type(odd) pseudo class' do
it 'parses the x:nth-of-type(odd) pseudo class' do
parse_css('x:nth-of-type(odd)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::x) + 1) >= 1 ' \
'and (((count(preceding-sibling::x) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-of-type(n) pseudo class' do
it 'parses the x:nth-of-type(n) pseudo class' do
parse_css('x:nth-of-type(n)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::x) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-of-type(-n) pseudo class' do
it 'parses the x:nth-of-type(-n) pseudo class' do
parse_css('x:nth-of-type(-n)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::x) + 1) mod 1) = 0]'
)
end
example 'parse the x:nth-of-type(-n+6) pseudo class' do
it 'parses the x:nth-of-type(-n+6) pseudo class' do
parse_css('x:nth-of-type(-n+6)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::x) + 1) <= 6) ' \
'and (((count(preceding-sibling::x) + 1) - 6) mod 1) = 0]'
)
end
example 'parse the x:nth-of-type(n+5) pseudo class' do
it 'parses the x:nth-of-type(n+5) pseudo class' do
parse_css('x:nth-of-type(n+5)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::x) + 1) >= 5 ' \
'and (((count(preceding-sibling::x) + 1) - 5) mod 1) = 0]'
)
end
example 'parse the x:nth-of-type(2n) pseudo class' do
it 'parses the x:nth-of-type(2n) pseudo class' do
parse_css('x:nth-of-type(2n)').should == parse_css('x:nth-of-type(even)')
end
example 'parse the x:nth-of-type(2n+1) pseudo class' do
it 'parses the x:nth-of-type(2n+1) pseudo class' do
parse_css('x:nth-of-type(2n+1)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::x) + 1) >= 1 ' \
'and (((count(preceding-sibling::x) + 1) - 1) mod 2) = 0]'
)
end
example 'parse the x:nth-of-type(3n+1) pseudo class' do
it 'parses the x:nth-of-type(3n+1) pseudo class' do
parse_css('x:nth-of-type(3n+1)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::x) + 1) >= 1 ' \
'and (((count(preceding-sibling::x) + 1) - 1) mod 3) = 0]'
)
end
example 'parse the x:nth-of-type(2n-6) pseudo class' do
it 'parses the x:nth-of-type(2n-6) pseudo class' do
parse_css('x:nth-of-type(2n-6)').should == parse_xpath(
'descendant::x[(count(preceding-sibling::x) + 1) >= 2 ' \
'and (((count(preceding-sibling::x) + 1) - 2) mod 2) = 0]'
)
end
example 'parse the x:nth-of-type(-2n+6) pseudo class' do
it 'parses the x:nth-of-type(-2n+6) pseudo class' do
parse_css('x:nth-of-type(-2n+6)').should == parse_xpath(
'descendant::x[((count(preceding-sibling::x) + 1) <= 6) ' \
'and (((count(preceding-sibling::x) + 1) - 6) mod 2) = 0]'

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':only-child pseudo class' do
example 'parse the :only-child pseudo class' do
describe ':only-child pseudo class' do
it 'parses the :only-child pseudo class' do
parse_css(':only-child').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0 ' \
'and count(following-sibling::*) = 0]'

View File

@ -1,15 +1,15 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':only-of-type pseudo class' do
example 'parse the :only-of-type pseudo class' do
describe ':only-of-type pseudo class' do
it 'parses the :only-of-type pseudo class' do
parse_css(':only-of-type').should == parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0 and ' \
'count(following-sibling::*) = 0]'
)
end
example 'parse the a:only-of-type pseudo class' do
it 'parses the a:only-of-type pseudo class' do
parse_css('a:only-of-type').should == parse_xpath(
'descendant::a[count(preceding-sibling::a) = 0 and ' \
'count(following-sibling::a) = 0]'

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':root pseudo class' do
example 'parse the x:root pseudo class' do
describe ':root pseudo class' do
it 'parses the x:root pseudo class' do
parse_css('x:root').should == parse_xpath('descendant::x[not(parent::*)]')
end
example 'parse the :root pseudo class' do
it 'parses the :root pseudo class' do
parse_css(':root').should == parse_xpath('descendant::*[not(parent::*)]')
end
end

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context 'wildcards' do
example 'parse a wildcard name test' do
describe 'wildcards' do
it 'parses a wildcard name test' do
parse_css('*').should == parse_xpath('descendant::*')
end
example 'parse a wildcard namespace test' do
it 'parses a wildcard namespace test' do
parse_css('*|foo').should == parse_xpath('descendant::*:foo')
end
example 'parse a wildcard namespace and name test' do
it 'parses a wildcard namespace and name test' do
parse_css('*|*').should == parse_xpath('descendant::*:*')
end
end

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe Oga::HTML::Parser do
context 'HTML void elements' do
describe 'HTML void elements' do
before :all do
@node = parse_html('<meta>').children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@node.is_a?(Oga::XML::Element).should == true
end
example 'set the name of the element' do
it 'sets the name of the element' do
@node.name.should == 'meta'
end
end

View File

@ -11,7 +11,7 @@ describe Oga::HTML::SaxParser do
end
end
example 'use custom callback methods if defined' do
it 'uses custom callback methods if defined' do
handler = @handler.new
parser = described_class.new(handler, '<link>')

View File

@ -1,19 +1,19 @@
require 'spec_helper'
describe Oga do
example 'parse an XML document' do
it 'parses an XML document' do
document = described_class.parse_xml('<root>foo</root>')
document.is_a?(Oga::XML::Document).should == true
end
example 'parse an HTML document' do
it 'parses an HTML document' do
document = described_class.parse_xml('<html><body></body></html>')
document.is_a?(Oga::XML::Document).should == true
end
context 'SAX parsing' do
describe 'SAX parsing' do
before do
klass = Class.new do
attr_reader :name
@ -26,13 +26,13 @@ describe Oga do
@handler = klass.new
end
example 'parse an XML document using the SAX parser' do
it 'parses an XML document using the SAX parser' do
Oga.sax_parse_xml(@handler, '<foo />')
@handler.name.should == 'foo'
end
example 'parse an HTML document using the SAX parser' do
it 'parses an HTML document using the SAX parser' do
Oga.sax_parse_xml(@handler, '<link>')
@handler.name.should == 'link'

View File

@ -1,17 +1,17 @@
require 'spec_helper'
describe Oga::XML::Attribute do
context '#initialize' do
example 'set the name' do
describe '#initialize' do
it 'sets the name' do
described_class.new(:name => 'a').name.should == 'a'
end
example 'set the value' do
it 'sets the value' do
described_class.new(:value => 'a').value.should == 'a'
end
end
context '#namespace' do
describe '#namespace' do
before do
@namespace = Oga::XML::Namespace.new(:name => 'b')
@ -28,33 +28,33 @@ describe Oga::XML::Attribute do
@default = described_class.new(:namespace_name => 'xml', :name => 'x')
end
example 'return a Namespace instance' do
it 'returns a Namespace instance' do
@attribute.namespace.should == @namespace
end
example 'return the default XML namespace when the "xml" prefix is used' do
it 'returns the default XML namespace when the "xml" prefix is used' do
@default.namespace.should == Oga::XML::Attribute::DEFAULT_NAMESPACE
end
end
context '#text' do
example 'return an empty String when there is no value' do
describe '#text' do
it 'returns an empty String when there is no value' do
described_class.new.text.should == ''
end
example 'return the value if it is present' do
it 'returns the value if it is present' do
described_class.new(:value => 'a').text.should == 'a'
end
end
context '#to_xml' do
example 'convert an attribute to XML' do
describe '#to_xml' do
it 'converts an attribute to XML' do
attr = described_class.new(:name => 'foo', :value => 'bar')
attr.to_xml.should == 'foo="bar"'
end
example 'include the namespace when converting an attribute to XML' do
it 'includes the namespace when converting an attribute to XML' do
element = Oga::XML::Element.new
element.register_namespace('foo', 'http://foo')
@ -69,7 +69,7 @@ describe Oga::XML::Attribute do
attr.to_xml.should == 'foo:class="10"'
end
example 'include the "xmlns" namespace when present but not registered' do
it 'includes the "xmlns" namespace when present but not registered' do
attr = described_class.new(
:name => 'class',
:namespace_name => 'xmlns',
@ -79,15 +79,15 @@ describe Oga::XML::Attribute do
attr.to_xml.should == 'xmlns:class=""'
end
example 'convert special characters to XML entities' do
it 'converts special characters to XML entities' do
attr = described_class.new(:name => 'href', :value => '&<>')
attr.to_xml.should == 'href="&amp;&lt;&gt;"'
end
end
context '#inspect' do
example 'return the inspect value' do
describe '#inspect' do
it 'returns the inspect value' do
element = Oga::XML::Element.new(
:namespaces => {'b' => Oga::XML::Namespace.new(:name => 'b')}
)

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::Cdata do
context 'setting attributes' do
example 'set the text via the constructor' do
describe 'setting attributes' do
it 'sets the text via the constructor' do
described_class.new(:text => 'foo').text.should == 'foo'
end
example 'set the text via a setter' do
it 'sets the text via a setter' do
instance = described_class.new
instance.text = 'foo'
@ -14,22 +14,22 @@ describe Oga::XML::Cdata do
end
end
context '#to_xml' do
describe '#to_xml' do
before do
@instance = described_class.new(:text => 'foo')
end
example 'generate the corresponding XML' do
it 'generates the corresponding XML' do
@instance.to_xml.should == '<![CDATA[foo]]>'
end
end
context '#inspect' do
describe '#inspect' do
before do
@instance = described_class.new(:text => 'foo')
end
example 'return the inspect value' do
it 'returns the inspect value' do
@instance.inspect.should == 'Cdata("foo")'
end
end

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::CharacterNode do
context '#initialize' do
example 'set the text in the constructor' do
describe '#initialize' do
it 'sets the text in the constructor' do
described_class.new(:text => 'a').text.should == 'a'
end
example 'set the text via an attribute' do
it 'sets the text via an attribute' do
node = described_class.new
node.text = 'a'
@ -14,14 +14,14 @@ describe Oga::XML::CharacterNode do
end
end
context '#to_xml' do
example 'convert the node to XML' do
describe '#to_xml' do
it 'converts the node to XML' do
described_class.new(:text => 'a').to_xml.should == 'a'
end
end
context '#inspect' do
example 'return the inspect value' do
describe '#inspect' do
it 'returns the inspect value' do
described_class.new(:text => 'a').inspect.should == 'CharacterNode("a")'
end
end

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::Comment do
context 'setting attributes' do
example 'set the text via the constructor' do
describe 'setting attributes' do
it 'sets the text via the constructor' do
described_class.new(:text => 'foo').text.should == 'foo'
end
example 'set the text via a setter' do
it 'sets the text via a setter' do
instance = described_class.new
instance.text = 'foo'
@ -14,22 +14,22 @@ describe Oga::XML::Comment do
end
end
context '#to_xml' do
describe '#to_xml' do
before do
@instance = described_class.new(:text => 'foo')
end
example 'generate the corresponding XML' do
it 'generates the corresponding XML' do
@instance.to_xml.should == '<!--foo-->'
end
end
context '#inspect' do
describe '#inspect' do
before do
@instance = described_class.new(:text => 'foo')
end
example 'return the inspect value' do
it 'returns the inspect value' do
@instance.inspect.should == 'Comment("foo")'
end
end

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::Doctype do
context 'setting attributes' do
example 'set the name via the constructor' do
describe 'setting attributes' do
it 'sets the name via the constructor' do
described_class.new(:name => 'html').name.should == 'html'
end
example 'set the name via a setter' do
it 'sets the name via a setter' do
instance = described_class.new
instance.name = 'html'
@ -14,18 +14,18 @@ describe Oga::XML::Doctype do
end
end
context '#to_xml' do
example 'generate a bare minimum representation' do
describe '#to_xml' do
it 'generates a bare minimum representation' do
described_class.new(:name => 'html').to_xml.should == '<!DOCTYPE html>'
end
example 'include the type if present' do
it 'includes the type if present' do
instance = described_class.new(:name => 'html', :type => 'PUBLIC')
instance.to_xml.should == '<!DOCTYPE html PUBLIC>'
end
example 'include the public ID if present' do
it 'includes the public ID if present' do
instance = described_class.new(
:name => 'html',
:type => 'PUBLIC',
@ -35,7 +35,7 @@ describe Oga::XML::Doctype do
instance.to_xml.should == '<!DOCTYPE html PUBLIC "foo">'
end
example 'include the system ID if present' do
it 'includes the system ID if present' do
instance = described_class.new(
:name => 'html',
:type => 'PUBLIC',
@ -46,7 +46,7 @@ describe Oga::XML::Doctype do
instance.to_xml.should == '<!DOCTYPE html PUBLIC "foo" "bar">'
end
example 'include the inline rules if present' do
it 'includes the inline rules if present' do
instance = described_class.new(
:name => 'html',
:inline_rules => '<!ELEMENT foo>'
@ -56,7 +56,7 @@ describe Oga::XML::Doctype do
end
end
context '#inspect' do
describe '#inspect' do
before do
@instance = described_class.new(
:name => 'html',
@ -65,7 +65,7 @@ describe Oga::XML::Doctype do
)
end
example 'pretty-print the node' do
it 'pretty-prints the node' do
@instance.inspect.should == <<-EOF.strip
Doctype(name: "html" type: "PUBLIC" inline_rules: "<!ELEMENT foo>")
EOF

View File

@ -1,21 +1,21 @@
require 'spec_helper'
describe Oga::XML::Document do
context 'setting attributes' do
example 'set the child nodes via the constructor' do
describe 'setting attributes' do
it 'sets the child nodes via the constructor' do
child = Oga::XML::Comment.new(:text => 'foo')
document = described_class.new(:children => [child])
document.children[0].should == child
end
example 'set the document type' do
it 'sets the document type' do
described_class.new(:type => :html).type.should == :html
end
end
context '#children=' do
example 'set the child nodes using an Array' do
describe '#children=' do
it 'sets the child nodes using an Array' do
child = Oga::XML::Comment.new(:text => 'foo')
document = described_class.new
@ -24,7 +24,7 @@ describe Oga::XML::Document do
document.children[0].should == child
end
example 'set the child nodes using a NodeSet' do
it 'sets the child nodes using a NodeSet' do
child = Oga::XML::Comment.new(:text => 'foo')
document = described_class.new
@ -34,18 +34,18 @@ describe Oga::XML::Document do
end
end
context '#to_xml' do
describe '#to_xml' do
before do
child = Oga::XML::Comment.new(:text => 'foo')
@document = described_class.new(:children => [child])
end
example 'generate the corresponding XML' do
it 'generates the corresponding XML' do
@document.to_xml.should == '<!--foo-->'
end
end
context '#to_xml with XML declarations' do
describe '#to_xml with XML declarations' do
before do
decl = Oga::XML::XmlDeclaration.new(:version => '5.0')
children = [Oga::XML::Comment.new(:text => 'foo')]
@ -56,13 +56,13 @@ describe Oga::XML::Document do
)
end
example 'include the XML of the declaration tag' do
it 'includes the XML of the declaration tag' do
@document.to_xml
.should == %Q{<?xml version="5.0" encoding="UTF-8" ?>\n<!--foo-->}
end
end
context '#to_xml with doctypes' do
describe '#to_xml with doctypes' do
before do
doctype = Oga::XML::Doctype.new(:name => 'html', :type => 'PUBLIC')
children = [Oga::XML::Comment.new(:text => 'foo')]
@ -73,12 +73,12 @@ describe Oga::XML::Document do
)
end
example 'include the doctype' do
it 'includes the doctype' do
@document.to_xml.should == %Q{<!DOCTYPE html PUBLIC>\n<!--foo-->}
end
end
context '#to_xml with XML declarations and doctypes' do
describe '#to_xml with XML declarations and doctypes' do
before do
decl = Oga::XML::XmlDeclaration.new(:version => '5.0')
doctype = Oga::XML::Doctype.new(:name => 'html', :type => 'PUBLIC')
@ -91,13 +91,13 @@ describe Oga::XML::Document do
)
end
example 'include the doctype and XML declaration' do
it 'includes the doctype and XML declaration' do
@document.to_xml.should == '<?xml version="5.0" encoding="UTF-8" ?>' \
"\n<!DOCTYPE html PUBLIC>\n<!--foo-->"
end
end
context '#inspect' do
describe '#inspect' do
before do
@instance = described_class.new(
:doctype => Oga::XML::Doctype.new(:name => 'html'),
@ -106,7 +106,7 @@ describe Oga::XML::Document do
)
end
example 'return the inspect value' do
it 'returns the inspect value' do
@instance.inspect.should == <<-EOF.strip
Document(
doctype: Doctype(name: "html")
@ -116,7 +116,7 @@ Document(
EOF
end
example 'return the inspect value of an empty document' do
it 'returns the inspect value of an empty document' do
described_class.new.inspect.should == <<-EOF.strip
Document(
children: NodeSet()

View File

@ -1,52 +1,52 @@
require 'spec_helper'
describe Oga::XML::Element do
context 'setting attributes' do
example 'set the name via the constructor' do
describe 'setting attributes' do
it 'sets the name via the constructor' do
described_class.new(:name => 'p').name.should == 'p'
end
example 'set the name via a setter' do
it 'sets the name via a setter' do
instance = described_class.new
instance.name = 'p'
instance.name.should == 'p'
end
example 'set the default attributes' do
it 'sets the default attributes' do
described_class.new.attributes.should == []
end
end
context 'setting namespaces via attributes' do
describe 'setting namespaces via attributes' do
before do
attr = Oga::XML::Attribute.new(:name => 'foo', :namespace_name => 'xmlns')
@element = described_class.new(:attributes => [attr])
end
example 'register the "foo" namespace' do
it 'registers the "foo" namespace' do
@element.namespaces['foo'].is_a?(Oga::XML::Namespace).should == true
end
example 'keep the attributes after registering the namespaces' do
it 'keeps the attributes after registering the namespaces' do
@element.attributes.empty?.should == false
end
end
context 'setting the default namespace without a prefix' do
describe 'setting the default namespace without a prefix' do
before do
attr = Oga::XML::Attribute.new(:name => 'xmlns', :value => 'foo')
@element = described_class.new(:attributes => [attr])
end
example 'register the default namespace' do
it 'registers the default namespace' do
@element.namespaces['xmlns'].is_a?(Oga::XML::Namespace).should == true
end
end
context '#attribute' do
describe '#attribute' do
before do
attributes = [
Oga::XML::Attribute.new(:name => 'key', :value => 'value'),
@ -68,90 +68,90 @@ describe Oga::XML::Element do
)
end
example 'return an attribute with only a name' do
it 'returns an attribute with only a name' do
@instance.attribute('key').value.should == 'value'
end
example 'return an attribute with only a name when using a Symbol' do
it 'returns an attribute with only a name when using a Symbol' do
@instance.attribute(:key).value.should == 'value'
end
example 'return an attribute with a name and namespace' do
it 'returns an attribute with a name and namespace' do
@instance.attribute('x:key').value.should == 'foo'
end
example 'return an attribute with a name and namespace when using a Symbol' do
it 'returns an attribute with a name and namespace when using a Symbol' do
@instance.attribute(:'x:key').value.should == 'foo'
end
example 'return nil when the name matches but the namespace does not' do
it 'returns nil when the name matches but the namespace does not' do
@instance.attribute('y:key').nil?.should == true
end
example 'return nil when the namespace matches but the name does not' do
it 'returns nil when the namespace matches but the name does not' do
@instance.attribute('x:foobar').nil?.should == true
end
example 'return nil for a non existing attribute' do
it 'returns nil for a non existing attribute' do
@instance.attribute('foobar').nil?.should == true
end
example 'return nil if an attribute has a namespace that is not given' do
it 'returns nil if an attribute has a namespace that is not given' do
@instance.attribute('bar').nil?.should == true
end
end
context '#get' do
describe '#get' do
before do
attr = Oga::XML::Attribute.new(:name => 'foo', :value => 'bar')
@element = described_class.new(:attributes => [attr])
end
example 'return the value of an attribute' do
it 'returns the value of an attribute' do
@element.get('foo').should == 'bar'
end
end
context '#add_attribute' do
describe '#add_attribute' do
before do
@element = described_class.new
@attribute = Oga::XML::Attribute.new(:name => 'foo', :value => 'bar')
end
example 'add an Attribute to the element' do
it 'adds an Attribute to the element' do
@element.add_attribute(@attribute)
@element.attribute('foo').should == @attribute
end
example 'set the element of the attribute when adding it' do
it 'sets the element of the attribute when adding it' do
@element.add_attribute(@attribute)
@attribute.element.should == @element
end
end
context '#set' do
describe '#set' do
before do
@element = described_class.new
@element.register_namespace('x', 'test')
end
example 'add a new attribute' do
it 'adds a new attribute' do
@element.set('class', 'foo')
@element.get('class').should == 'foo'
end
example 'add a new attribute with a namespace' do
it 'adds a new attribute with a namespace' do
@element.set('x:bar', 'foo')
@element.get('x:bar').should == 'foo'
end
example 'set the namespace of an attribute' do
it 'sets the namespace of an attribute' do
@element.set('x:bar', 'foo')
attr = @element.attribute('x:bar')
@ -159,7 +159,7 @@ describe Oga::XML::Element do
attr.namespace.is_a?(Oga::XML::Namespace).should == true
end
example 'overwrite the value of an existing attribute' do
it 'overwrites the value of an existing attribute' do
attr = Oga::XML::Attribute.new(:name => 'foo', :value => 'bar')
@element.add_attribute(attr)
@ -170,7 +170,7 @@ describe Oga::XML::Element do
end
end
context '#unset' do
describe '#unset' do
before do
@element = described_class.new
@ -180,21 +180,21 @@ describe Oga::XML::Element do
@element.set('x:foo', 'bar')
end
example 'remove an attribute by its name' do
it 'removes an attribute by its name' do
@element.unset('foo')
@element.get('foo').should be_nil
end
example 'remove an attribute using a namespace' do
it 'removes an attribute using a namespace' do
@element.unset('x:foo')
@element.get('x:foo').should be_nil
end
end
context '#namespace' do
example 'return the namespace' do
describe '#namespace' do
it 'returns the namespace' do
namespace = Oga::XML::Namespace.new(:name => 'x')
element = described_class.new(
:namespace_name => 'x',
@ -204,7 +204,7 @@ describe Oga::XML::Element do
element.namespace.should == namespace
end
example 'return the default namespace if available' do
it 'returns the default namespace if available' do
namespace = Oga::XML::Namespace.new(:name => 'xmlns')
element = described_class.new(
:namespaces => {'xmlns' => namespace}
@ -214,7 +214,7 @@ describe Oga::XML::Element do
end
end
context '#text' do
describe '#text' do
before do
t1 = Oga::XML::Text.new(:text => 'Foo')
t2 = Oga::XML::Text.new(:text => 'Bar')
@ -223,16 +223,16 @@ describe Oga::XML::Element do
@n2 = described_class.new(:children => [@n1, t2])
end
example 'return the text of the parent node and its child nodes' do
it 'returns the text of the parent node and its child nodes' do
@n2.text.should == 'FooBar'
end
example 'return the text of the child node' do
it 'returns the text of the child node' do
@n1.text.should == 'Foo'
end
end
context '#inner_text' do
describe '#inner_text' do
before do
t1 = Oga::XML::Text.new(:text => 'Foo')
t2 = Oga::XML::Text.new(:text => 'Bar')
@ -241,26 +241,26 @@ describe Oga::XML::Element do
@n2 = described_class.new(:children => [@n1, t2])
end
example 'return the inner text of the parent node' do
it 'returns the inner text of the parent node' do
@n2.inner_text.should == 'Bar'
end
example 'return the inner text of the child node' do
it 'returns the inner text of the child node' do
@n1.inner_text.should == 'Foo'
end
end
context '#inner_text=' do
describe '#inner_text=' do
before do
@element = described_class.new
end
example 'set the inner text of an element' do
it 'sets the inner text of an element' do
@element.inner_text = 'foo'
@element.inner_text.should == 'foo'
end
example 'remove all existing nodes before inserting a new text node' do
it 'removes all existing nodes before inserting a new text node' do
@element.children << Oga::XML::Text.new(:text => 'foo')
@element.children << Oga::XML::Element.new(:name => 'x')
@ -270,7 +270,7 @@ describe Oga::XML::Element do
end
end
context '#text_nodes' do
describe '#text_nodes' do
before do
@t1 = Oga::XML::Text.new(:text => 'Foo')
@t2 = Oga::XML::Text.new(:text => 'Bar')
@ -278,17 +278,17 @@ describe Oga::XML::Element do
@element = described_class.new(:children => [@t1, @t2])
end
example 'return a node set containing the text nodes' do
it 'returns a node set containing the text nodes' do
@element.text_nodes.should == node_set(@t1, @t2)
end
end
context '#to_xml' do
example 'generate the corresponding XML' do
describe '#to_xml' do
it 'generates the corresponding XML' do
described_class.new(:name => 'p').to_xml.should == '<p />'
end
example 'include the namespace if present' do
it 'includes the namespace if present' do
instance = described_class.new(
:name => 'p',
:namespace_name => 'foo',
@ -299,7 +299,7 @@ describe Oga::XML::Element do
instance.to_xml.should == '<foo:p>Foo</foo:p>'
end
example 'include a single attribute if present' do
it 'includes a single attribute if present' do
instance = described_class.new(
:name => 'p',
:attributes => [
@ -310,7 +310,7 @@ describe Oga::XML::Element do
instance.to_xml.should == '<p key="value" />'
end
example 'include multiple attributes if present' do
it 'includes multiple attributes if present' do
instance = described_class.new(
:name => 'p',
:attributes => [
@ -322,7 +322,7 @@ describe Oga::XML::Element do
instance.to_xml.should == '<p key1="value1" key2="value2" />'
end
example 'include the child nodes if present' do
it 'includes the child nodes if present' do
instance = described_class.new(
:name => 'p',
:children => [Oga::XML::Comment.new(:text => 'foo')]
@ -331,7 +331,7 @@ describe Oga::XML::Element do
instance.to_xml.should == '<p><!--foo--></p>'
end
example 'generate the corresponding XML when using a default namespace' do
it 'generates the corresponding XML when using a default namespace' do
namespace = Oga::XML::Namespace.new(:name => 'xmlns', :uri => 'foo')
instance = described_class.new(
:name => 'foo',
@ -341,14 +341,14 @@ describe Oga::XML::Element do
instance.to_xml.should == '<foo />'
end
example 'generate the XML for the HTML <script> element' do
it 'generates the XML for the HTML <script> element' do
element = described_class.new(:name => 'script')
document = Oga::XML::Document.new(:type => :html, :children => [element])
element.to_xml.should == '<script></script>'
end
example 'generate the XML for the HTML <link> element' do
it 'generates the XML for the HTML <link> element' do
element = described_class.new(:name => 'link')
document = Oga::XML::Document.new(:type => :html, :children => [element])
@ -356,14 +356,14 @@ describe Oga::XML::Element do
end
end
context '#inspect' do
example 'inspect a node with a name' do
describe '#inspect' do
it 'inspects a node with a name' do
node = described_class.new(:name => 'a')
node.inspect.should == 'Element(name: "a")'
end
example 'inspect a node with attributes and children' do
it 'inspects a node with attributes and children' do
node = described_class.new(
:name => 'p',
:children => [Oga::XML::Comment.new(:text => 'foo')],
@ -374,7 +374,7 @@ describe Oga::XML::Element do
'[Attribute(name: "x" value: "y")] children: NodeSet(Comment("foo")))'
end
example 'inspect a node with a namespace' do
it 'inspects a node with a namespace' do
node = described_class.new(
:name => 'p',
:namespace_name => 'x',
@ -386,33 +386,33 @@ describe Oga::XML::Element do
end
end
context '#register_namespace' do
describe '#register_namespace' do
before do
@element = described_class.new
@element.register_namespace('foo', 'http://example.com')
end
example 'return a Namespace instance' do
it 'returns a Namespace instance' do
@element.namespaces['foo'].is_a?(Oga::XML::Namespace).should == true
end
example 'set the name of the namespace' do
it 'sets the name of the namespace' do
@element.namespaces['foo'].name.should == 'foo'
end
example 'set the URI of the namespace' do
it 'sets the URI of the namespace' do
@element.namespaces['foo'].uri.should == 'http://example.com'
end
example 'raise ArgumentError if the namespace already exists' do
it 'raises ArgumentError if the namespace already exists' do
block = lambda { @element.register_namespace('foo', 'bar') }
block.should raise_error(ArgumentError)
end
end
context '#available_namespaces' do
describe '#available_namespaces' do
before do
@parent = described_class.new
@child = described_class.new
@ -428,47 +428,47 @@ describe Oga::XML::Element do
@child_ns = @child.available_namespaces
end
example 'inherit the "foo" namespace from the parent' do
it 'inherits the "foo" namespace from the parent' do
@child_ns['foo'].uri.should == 'bar'
end
example 'overwrite the "baz" namespace in the child' do
it 'overwrites the "baz" namespace in the child' do
@child_ns['baz'].uri.should == 'xxx'
end
example 'return the "foo" namespace for the parent' do
it 'returns the "foo" namespace for the parent' do
@parent_ns['foo'].uri.should == 'bar'
end
example 'return the "baz" namespace for the parent' do
it 'returns the "baz" namespace for the parent' do
@parent_ns['baz'].uri.should == 'yyy'
end
example 'do not modify the list of direct namespaces' do
it 'does not modify the list of direct namespaces' do
@child.namespaces.key?('foo').should == false
end
end
context '#self_closing?' do
example 'return true for an empty XML element' do
describe '#self_closing?' do
it 'returns true for an empty XML element' do
described_class.new(:name => 'foo').should be_self_closing
end
example 'return false for a non empty XML element' do
it 'returns false for a non empty XML element' do
text = Oga::XML::Text.new(:text => 'bar')
node = described_class.new(:name => 'foo', :children => [text])
node.should_not be_self_closing
end
example 'return true for an HTML void element' do
it 'returns true for an HTML void element' do
element = described_class.new(:name => 'link')
document = Oga::XML::Document.new(:type => :html, :children => [element])
element.should be_self_closing
end
example 'return false for a non empty HTML element' do
it 'returns false for a non empty HTML element' do
text = Oga::XML::Text.new(:text => 'alert()')
element = described_class.new(:name => 'script', :children => [text])
document = Oga::XML::Document.new(:type => :html, :children => [element])

View File

@ -1,98 +1,98 @@
require 'spec_helper'
describe Oga::XML::Entities do
context 'decode' do
example 'decode &lt; into <' do
describe 'decode' do
it 'decodes &lt; into <' do
described_class.decode('&lt;').should == '<'
end
example 'decode &gt; into >' do
it 'decodes &gt; into >' do
described_class.decode('&gt;').should == '>'
end
example "decode &apos; into '" do
it "decodes &apos; into '" do
described_class.decode('&apos;').should == "'"
end
example 'decode &quot; into "' do
it 'decodes &quot; into "' do
described_class.decode('&quot;').should == '"'
end
example 'decode &amp; into &' do
it 'decodes &amp; into &' do
described_class.decode('&amp;').should == '&'
end
example 'decode &#60; into <' do
it 'decodes &#60; into <' do
described_class.decode('&#60;').should == '<'
end
example 'decode &#62; into >' do
it 'decodes &#62; into >' do
described_class.decode('&#62;').should == '>'
end
example "decode &#39; into '" do
it "decodes &#39; into '" do
described_class.decode('&#39;').should == "'"
end
example 'decode &#34; into "' do
it 'decodes &#34; into "' do
described_class.decode('&#34;').should == '"'
end
example 'decode &#38; into &' do
it 'decodes &#38; into &' do
described_class.decode('&#38;').should == '&'
end
example 'decode &#38;#60; into &#60;' do
it 'decodes &#38;#60; into &#60;' do
described_class.decode('&#38;#60;').should == '&#60;'
end
example 'decode &#38;#38; into &#38;' do
it 'decodes &#38;#38; into &#38;' do
described_class.decode('&#38;#38;').should == '&#38;'
end
example 'decode &amp;gt; into &gt;' do
it 'decodes &amp;gt; into &gt;' do
described_class.decode('&amp;gt;').should == '&gt;'
end
example 'decode &amp;&amp;gt; into &>' do
it 'decodes &amp;&amp;gt; into &>' do
described_class.decode('&amp;&amp;gt;').should == '&&gt;'
end
example 'decode &amp;lt; into <' do
it 'decodes &amp;lt; into <' do
described_class.decode('&amp;lt;').should == '&lt;'
end
example 'decode &amp;&amp;lt; into &<' do
it 'decodes &amp;&amp;lt; into &<' do
described_class.decode('&amp;&amp;lt;').should == '&&lt;'
end
end
context 'encode' do
example 'encode & as &amp;' do
describe 'encode' do
it 'encodes & as &amp;' do
described_class.encode('&').should == '&amp;'
end
example 'encode " as &quot;' do
it 'encodes " as &quot;' do
described_class.encode('"').should == '&quot;'
end
example "encode ' as &apos;" do
it "encodes ' as &apos;" do
described_class.encode("'").should == '&apos;'
end
example 'encode < as &lt;' do
it 'encodes < as &lt;' do
described_class.encode('<').should == '&lt;'
end
example 'encode > as &gt;' do
it 'encodes > as &gt;' do
described_class.encode('>').should == '&gt;'
end
example 'encode &gt; as &amp;gt;' do
it 'encodes &gt; as &amp;gt;' do
described_class.encode('&gt;').should == '&amp;gt;'
end
example 'encode &lt; as &amp;lt;' do
it 'encodes &lt; as &amp;lt;' do
described_class.encode('&lt;').should == '&amp;lt;'
end
end

View File

@ -1,20 +1,20 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'cdata tags' do
example 'lex a cdata tag' do
describe 'cdata tags' do
it 'lexes a cdata tag' do
lex('<![CDATA[foo]]>').should == [[:T_CDATA, 'foo', 1]]
end
example 'lex tags inside CDATA tags as regular text' do
it 'lexes tags inside CDATA tags as regular text' do
lex('<![CDATA[<p>Foo</p>]]>').should == [[:T_CDATA, '<p>Foo</p>', 1]]
end
example 'lex double brackets inside a CDATA tag' do
it 'lexes double brackets inside a CDATA tag' do
lex('<![CDATA[]]]]>').should == [[:T_CDATA, ']]', 1]]
end
example 'lex two CDATA tags following each other' do
it 'lexes two CDATA tags following each other' do
lex('<a><![CDATA[foo]]><b><![CDATA[bar]]></b></a>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'a', 1],

View File

@ -1,34 +1,34 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'comments' do
example 'lex a comment' do
describe 'comments' do
it 'lexes a comment' do
lex('<!-- foo -->').should == [[:T_COMMENT, ' foo ', 1]]
end
example 'lex a comment containing --' do
it 'lexes a comment containing --' do
lex('<!-- -- -->').should == [[:T_COMMENT, ' -- ', 1]]
end
example 'lex a comment containing ->' do
it 'lexes a comment containing ->' do
lex('<!-- -> -->').should == [[:T_COMMENT, ' -> ', 1]]
end
example 'lex a comment followed by text' do
it 'lexes a comment followed by text' do
lex('<!---->foo').should == [
[:T_COMMENT, '', 1],
[:T_TEXT, 'foo', 1]
]
end
example 'lex text followed by a comment' do
it 'lexes text followed by a comment' do
lex('foo<!---->').should == [
[:T_TEXT, 'foo', 1],
[:T_COMMENT, '', 1]
]
end
example 'lex an element followed by a comment' do
it 'lexes an element followed by a comment' do
lex('<p></p><!---->').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -37,7 +37,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex two comments following each other' do
it 'lexes two comments following each other' do
lex('<a><!--foo--><b><!--bar--></b></a>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'a', 1],

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'doctypes' do
example 'lex the HTML5 doctype' do
describe 'doctypes' do
it 'lexes the HTML5 doctype' do
lex('<!DOCTYPE html>').should == [
[:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1],
@ -10,7 +10,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a doctype with a public and system ID' do
it 'lexes a doctype with a public and system ID' do
lex('<!DOCTYPE HTML PUBLIC "foobar" "baz">').should == [
[:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'HTML', 1],
@ -25,7 +25,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a doctype with a public and system ID using single quotes' do
it 'lexes a doctype with a public and system ID using single quotes' do
lex("<!DOCTYPE HTML PUBLIC 'foobar' 'baz'>").should == [
[:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'HTML', 1],
@ -40,7 +40,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an inline doctype' do
it 'lexes an inline doctype' do
lex('<!DOCTYPE html [<!ELEMENT foo>]>').should == [
[:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1],
@ -49,7 +49,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an empty inline doctype' do
it 'lexes an empty inline doctype' do
lex('<!DOCTYPE html []>').should == [
[:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1],
@ -57,7 +57,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an inline doctype containing a newline' do
it 'lexes an inline doctype containing a newline' do
lex("<!DOCTYPE html [foo\n]>").should == [
[:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1],
@ -66,7 +66,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an inline doctype containing a trailing newline using an IO' do
it 'lexes an inline doctype containing a trailing newline using an IO' do
input = StringIO.new("<!DOCTYPE html [foo\n]>")
lex(input).should == [
@ -77,7 +77,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an inline doctype containing a leading newline using an IO' do
it 'lexes an inline doctype containing a leading newline using an IO' do
input = StringIO.new("<!DOCTYPE html [\nfoo]>")
lex(input).should == [
@ -91,7 +91,7 @@ describe Oga::XML::Lexer do
# Technically not valid, put in place to make sure that the Ragel rules are
# not too greedy.
example 'lex an inline doftype followed by a system ID' do
it 'lexes an inline doftype followed by a system ID' do
lex('<!DOCTYPE html [<!ELEMENT foo>] "foo">').should == [
[:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1],

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'HTML documents' do
example 'lex a basic HTML document' do
describe 'HTML documents' do
it 'lexes a basic HTML document' do
html = <<-EOF
<!DOCTYPE html>
<html>

View File

@ -1,15 +1,15 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'elements' do
example 'lex an opening element' do
describe 'elements' do
it 'lexes an opening element' do
lex('<p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1]
]
end
example 'lex an opening an closing element' do
it 'lexes an opening an closing element' do
lex('<p></p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -17,7 +17,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a paragraph element with text inside it' do
it 'lexes a paragraph element with text inside it' do
lex('<p>Hello</p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -26,7 +26,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex text followed by a paragraph element' do
it 'lexes text followed by a paragraph element' do
lex('Foo<p>').should == [
[:T_TEXT, 'Foo', 1],
[:T_ELEM_START, nil, 1],
@ -34,7 +34,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an element with a newline in the open tag' do
it 'lexes an element with a newline in the open tag' do
lex("<p\n></p>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -43,8 +43,8 @@ describe Oga::XML::Lexer do
end
end
context 'elements with attributes' do
example 'lex an element with an attribute without a value' do
describe 'elements with attributes' do
it 'lexes an element with an attribute without a value' do
lex('<p foo></p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -53,7 +53,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an element with an attribute with an empty value' do
it 'lexes an element with an attribute with an empty value' do
lex('<p foo=""></p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -64,7 +64,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a paragraph element with attributes' do
it 'lexes a paragraph element with attributes' do
lex('<p class="foo">Hello</p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -77,7 +77,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a paragraph element with a newline in an attribute' do
it 'lexes a paragraph element with a newline in an attribute' do
lex("<p class=\"\nfoo\">Hello</p>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -90,7 +90,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a paragraph element with single quoted attributes' do
it 'lexes a paragraph element with single quoted attributes' do
lex("<p class='foo'></p>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -102,7 +102,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a paragraph element with a namespaced attribute' do
it 'lexes a paragraph element with a namespaced attribute' do
lex('<p foo:bar="baz"></p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -116,8 +116,8 @@ describe Oga::XML::Lexer do
end
end
context 'nested elements' do
example 'lex a nested element' do
describe 'nested elements' do
it 'lexes a nested element' do
lex('<p><a></a></p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -128,7 +128,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex nested elements and text nodes' do
it 'lexes nested elements and text nodes' do
lex('<p>Foo<a>bar</a>baz</p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -143,8 +143,8 @@ describe Oga::XML::Lexer do
end
end
context 'void elements' do
example 'lex a void element' do
describe 'void elements' do
it 'lexes a void element' do
lex('<br />').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'br', 1],
@ -152,7 +152,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a void element with an attribute' do
it 'lexes a void element with an attribute' do
lex('<br class="foo" />').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'br', 1],
@ -165,8 +165,8 @@ describe Oga::XML::Lexer do
end
end
context 'elements with namespaces' do
example 'lex an element with namespaces' do
describe 'elements with namespaces' do
it 'lexes an element with namespaces' do
lex('<foo:p></p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NS, 'foo', 1],
@ -175,7 +175,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an element with a start and end namespace' do
it 'lexes an element with a start and end namespace' do
lex('<foo:p></foo:p>').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NS, 'foo', 1],

View File

@ -1,22 +1,22 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'converting XML entities in text tokens' do
example 'convert &amp; into &' do
describe 'converting XML entities in text tokens' do
it 'converts &amp; into &' do
lex('&amp;').should == [[:T_TEXT, '&', 1]]
end
example 'convert &lt; into <' do
it 'converts &lt; into <' do
lex('&lt;').should == [[:T_TEXT, '<', 1]]
end
example 'convert &gt; into >' do
it 'converts &gt; into >' do
lex('&gt;').should == [[:T_TEXT, '>', 1]]
end
end
context 'converting XML entities in string tokens' do
example 'convert &amp; into &' do
describe 'converting XML entities in string tokens' do
it 'converts &amp; into &' do
lex('<foo class="&amp;" />').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'foo', 1],
@ -28,7 +28,7 @@ describe Oga::XML::Lexer do
]
end
example 'convert &lt; into <' do
it 'converts &lt; into <' do
lex('<foo class="&lt;" />').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'foo', 1],
@ -40,7 +40,7 @@ describe Oga::XML::Lexer do
]
end
example 'convert &gt; into >' do
it 'converts &gt; into >' do
lex('<foo class="&gt;" />').should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'foo', 1],

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'Enumerator as input' do
describe 'Enumerator as input' do
before do
@enum = Enumerator.new do |yielder|
yielder << '<p>foo'
@ -9,7 +9,7 @@ describe Oga::XML::Lexer do
end
end
example 'lex a paragraph element' do
it 'lexes a paragraph element' do
lex(@enum).should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'p', 1],
@ -18,7 +18,7 @@ describe Oga::XML::Lexer do
]
end
example 'rewind input when resetting the lexer' do
it 'rewinds input when resetting the lexer' do
lexer = described_class.new(@enum)
lexer.lex.empty?.should == false

View File

@ -1,36 +1,36 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'regular text' do
example 'lex regular text' do
describe 'regular text' do
it 'lexes regular text' do
lex('hello').should == [[:T_TEXT, 'hello', 1]]
end
example 'lex regular whitespace' do
it 'lexes regular whitespace' do
lex(' ').should == [[:T_TEXT, ' ', 1]]
end
example 'lex a newline' do
it 'lexes a newline' do
lex("\n").should == [[:T_TEXT, "\n", 1]]
end
example 'lex text followed by a newline' do
it 'lexes text followed by a newline' do
lex("foo\n").should == [[:T_TEXT, "foo\n", 1]]
end
example 'lex a > as regular text' do
it 'lexes a > as regular text' do
lex('>').should == [[:T_TEXT, '>', 1]]
end
example 'lex </ as regular text' do
it 'lexes </ as regular text' do
lex('</').should == [[:T_TEXT, '</', 1]]
end
example 'lex <! as regular text' do
it 'lexes <! as regular text' do
lex('<!').should == [[:T_TEXT, '<!', 1]]
end
example 'lex <? as regular text' do
it 'lexes <? as regular text' do
lex('<?').should == [[:T_TEXT, '<?', 1]]
end
end

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'HTML void elements' do
example 'lex a void element that omits the closing /' do
describe 'HTML void elements' do
it 'lexes a void element that omits the closing /' do
lex('<link>', :html => true).should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'link', 1],
@ -10,7 +10,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a upper case void element' do
it 'lexes a upper case void element' do
lex('<BR>', :html => true).should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, "BR", 1],
@ -18,7 +18,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex text after a void element' do
it 'lexes text after a void element' do
lex('<link>foo', :html => true).should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'link', 1],
@ -27,7 +27,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a void element inside another element' do
it 'lexes a void element inside another element' do
lex('<head><link></head>', :html => true).should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'head', 1],
@ -38,7 +38,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a void element inside another element with whitespace' do
it 'lexes a void element inside another element with whitespace' do
lex("<head><link>\n</head>", :html => true).should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'head', 1],

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'lexing inline Javascript' do
describe 'lexing inline Javascript' do
before do
@javascript = 'if ( number < 10 ) { }'
end
example 'lex inline Javascript' do
it 'lexes inline Javascript' do
lex("<script>#{@javascript}</script>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'script', 1],
@ -15,7 +15,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex inline Javascript containing an XML comment' do
it 'lexes inline Javascript containing an XML comment' do
lex("<script>#{@javascript}<!--foo--></script>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'script', 1],
@ -25,7 +25,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex inline Javascript containing a CDATA tag' do
it 'lexes inline Javascript containing a CDATA tag' do
lex("<script>#{@javascript}<![CDATA[foo]]></script>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'script', 1],
@ -35,7 +35,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex inline Javascript containing a processing instruction' do
it 'lexes inline Javascript containing a processing instruction' do
lex("<script>#{@javascript}<?foo?></script>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'script', 1],
@ -47,7 +47,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex inline Javascript containing another element' do
it 'lexes inline Javascript containing another element' do
lex("<script>#{@javascript}<p></p></script>").should == [
[:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'script', 1],

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'IO as input' do
example 'lex a paragraph element with attributes' do
describe 'IO as input' do
it 'lexes a paragraph element with attributes' do
io = StringIO.new("<p class='foo'>\nHello</p>")
lex(io).should == [
@ -18,7 +18,7 @@ describe Oga::XML::Lexer do
]
end
example 'rewind input when resetting the lexer' do
it 'rewinds input when resetting the lexer' do
io = StringIO.new("<p class='foo'>\nHello</p>")
lexer = described_class.new(io)
@ -26,7 +26,7 @@ describe Oga::XML::Lexer do
lexer.lex.empty?.should == false
end
example 'lex an attribute value starting with a newline' do
it 'lexes an attribute value starting with a newline' do
io = StringIO.new("<foo bar='\n10'></foo>")
lexer = described_class.new(io)
@ -42,7 +42,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex an attribute value split in two by a newline' do
it 'lexes an attribute value split in two by a newline' do
io = StringIO.new("<foo bar='foo\nbar'></foo>")
lexer = described_class.new(io)

View File

@ -3,8 +3,8 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'multibyte text nodes' do
example 'lex a multibyte text node' do
describe 'multibyte text nodes' do
it 'lexes a multibyte text node' do
lex('쿠키').should == [[:T_TEXT, '쿠키', 1]]
end
end

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'processing instructions' do
example 'lex a processing instruction' do
describe 'processing instructions' do
it 'lexes a processing instruction' do
lex('<?foo?>').should == [
[:T_PROC_INS_START, nil, 1],
[:T_PROC_INS_NAME, 'foo', 1],
@ -10,7 +10,7 @@ describe Oga::XML::Lexer do
]
end
example 'lex a processing instruction containing text' do
it 'lexes a processing instruction containing text' do
lex('<?foo bar ?>').should == [
[:T_PROC_INS_START, nil, 1],
[:T_PROC_INS_NAME, 'foo', 1],

View File

@ -1,19 +1,19 @@
require 'spec_helper'
describe Oga::XML::Lexer do
context 'XML declaration tags' do
example 'lex a start tag' do
describe 'XML declaration tags' do
it 'lexes a start tag' do
lex('<?xml').should == [[:T_XML_DECL_START, nil, 1]]
end
example 'lex a start and end tag' do
it 'lexes a start and end tag' do
lex('<?xml?>').should == [
[:T_XML_DECL_START, nil, 1],
[:T_XML_DECL_END, nil, 1]
]
end
example 'lex a tag with text inside it' do
it 'lexes a tag with text inside it' do
lex('<?xml version="1.0" ?>').should == [
[:T_XML_DECL_START, nil, 1],
[:T_ATTR, 'version', 1],

View File

@ -1,20 +1,20 @@
require 'spec_helper'
describe Oga::XML::Namespace do
context '#initialize' do
example 'set the name' do
describe '#initialize' do
it 'sets the name' do
described_class.new(:name => 'a').name.should == 'a'
end
end
context '#to_s' do
example 'convert the Namespace to a String' do
describe '#to_s' do
it 'converts the Namespace to a String' do
described_class.new(:name => 'x').to_s.should == 'x'
end
end
context '#inspect' do
example 'return the inspect value' do
describe '#inspect' do
it 'returns the inspect value' do
ns = described_class.new(:name => 'x', :uri => 'y')
ns.inspect.should == 'Namespace(name: "x" uri: "y")'

View File

@ -1,32 +1,32 @@
require 'spec_helper'
describe Oga::XML::NodeSet do
context '#initialize' do
example 'create an empty node set' do
describe '#initialize' do
it 'creates an empty node set' do
described_class.new.length.should == 0
end
example 'create a node set with a single node' do
it 'creates a node set with a single node' do
node = Oga::XML::Element.new(:name => 'p')
described_class.new([node]).length.should == 1
end
example 'set the owner of a set' do
it 'sets the owner of a set' do
node = Oga::XML::Element.new
set = described_class.new([], node)
set.owner.should == node
end
example 'take ownership of the nodes when the set has an owner' do
it 'takes ownership of the nodes when the set has an owner' do
node = Oga::XML::Element.new
set = described_class.new([node], node)
node.node_set.should == set
end
example 'only store unique nodes' do
it 'onlies store unique nodes' do
n1 = Oga::XML::Element.new(:name => 'a')
set = described_class.new([n1, n1])
@ -34,8 +34,8 @@ describe Oga::XML::NodeSet do
end
end
context '#each' do
example 'yield the block for every node' do
describe '#each' do
it 'yields the block for every node' do
n1 = Oga::XML::Element.new(:name => 'a')
n2 = Oga::XML::Element.new(:name => 'b')
@ -48,60 +48,60 @@ describe Oga::XML::NodeSet do
end
end
context 'Enumerable behaviour' do
describe 'Enumerable behaviour' do
before do
@n1 = Oga::XML::Element.new(:name => 'a')
@n2 = Oga::XML::Element.new(:name => 'b')
@set = described_class.new([@n1, @n2])
end
example 'return the first node' do
it 'returns the first node' do
@set.first.should == @n1
end
example 'return the last node' do
it 'returns the last node' do
@set.last.should == @n2
end
example 'return the amount of nodes' do
it 'returns the amount of nodes' do
@set.count.should == 2
@set.length.should == 2
@set.size.should == 2
end
example 'return a boolean that indicates if a set is empty or not' do
it 'returns a boolean that indicates if a set is empty or not' do
@set.empty?.should == false
end
end
context '#index' do
describe '#index' do
before do
@n1 = Oga::XML::Element.new(:name => 'a')
@n2 = Oga::XML::Element.new(:name => 'b')
@set = described_class.new([@n1, @n2])
end
example 'return the index of the first node' do
it 'returns the index of the first node' do
@set.index(@n1).should == 0
end
example 'return the index of the last node' do
it 'returns the index of the last node' do
@set.index(@n2).should == 1
end
end
context '#push' do
describe '#push' do
before do
@set = described_class.new
end
example 'push a node into the set' do
it 'pushes a node into the set' do
@set.push(Oga::XML::Element.new(:name => 'a'))
@set.length.should == 1
end
example 'do not push a node that is already part of the set' do
it 'does not push a node that is already part of the set' do
element = Oga::XML::Element.new(:name => 'a')
@set.push(element)
@ -110,7 +110,7 @@ describe Oga::XML::NodeSet do
@set.length.should == 1
end
example 'take ownership of a node if the set has an owner' do
it 'takes ownership of a node if the set has an owner' do
child = Oga::XML::Element.new
@set.owner = Oga::XML::Element.new
@ -120,13 +120,13 @@ describe Oga::XML::NodeSet do
end
end
context '#unshift' do
describe '#unshift' do
before do
@n1 = Oga::XML::Element.new(:name => 'a')
@set = described_class.new([@n1])
end
example 'push a node at the beginning of the set' do
it 'pushes a node at the beginning of the set' do
n2 = Oga::XML::Element.new(:name => 'b')
@set.unshift(n2)
@ -134,13 +134,13 @@ describe Oga::XML::NodeSet do
@set.first.should == n2
end
example 'do not push a node if it is already part of the set' do
it 'does not push a node if it is already part of the set' do
@set.unshift(@n1)
@set.length.should == 1
end
example 'take ownership of a node if the set has an owner' do
it 'takes ownership of a node if the set has an owner' do
child = Oga::XML::Element.new
@set.owner = Oga::XML::Element.new
@ -150,59 +150,59 @@ describe Oga::XML::NodeSet do
end
end
context '#shift' do
describe '#shift' do
before do
owner = Oga::XML::Element.new
@n1 = Oga::XML::Element.new
@set = described_class.new([@n1], owner)
end
example 'remove the node from the set' do
it 'removes the node from the set' do
@set.shift
@set.empty?.should == true
end
example 'return the node when shifting it' do
it 'returns the node when shifting it' do
@set.shift.should == @n1
end
example 'remove ownership if the node belongs to a node set' do
it 'removes ownership if the node belongs to a node set' do
@set.shift
@n1.node_set.nil?.should == true
end
end
context '#pop' do
describe '#pop' do
before do
owner = Oga::XML::Element.new
@n1 = Oga::XML::Element.new
@set = described_class.new([@n1], owner)
end
example 'remove the node from the set' do
it 'removes the node from the set' do
@set.pop
@set.empty?.should == true
end
example 'return the node when popping it' do
it 'returns the node when popping it' do
@set.pop.should == @n1
end
example 'remove ownership if the node belongs to a node set' do
it 'removes ownership if the node belongs to a node set' do
@set.pop
@n1.node_set.nil?.should == true
end
end
context '#insert' do
describe '#insert' do
before do
@set = described_class.new
@owned_set = described_class.new([], Oga::XML::Node.new)
end
example 'insert a node into an empty node set' do
it 'inserts a node into an empty node set' do
node = Oga::XML::Node.new
@set.insert(0, node)
@ -210,7 +210,7 @@ describe Oga::XML::NodeSet do
@set[0].should == node
end
example 'do not insert a node that is already in the set' do
it 'does not insert a node that is already in the set' do
node = Oga::XML::Node.new
@set.insert(0, node)
@ -219,7 +219,7 @@ describe Oga::XML::NodeSet do
@set.length.should == 1
end
example 'insert a node before another node' do
it 'inserts a node before another node' do
node1 = Oga::XML::Node.new
node2 = Oga::XML::Node.new
@ -230,7 +230,7 @@ describe Oga::XML::NodeSet do
@set[1].should == node1
end
example 'take ownership of a node when inserting into an owned set' do
it 'takes ownership of a node when inserting into an owned set' do
node = Oga::XML::Node.new
@owned_set.insert(0, node)
@ -239,29 +239,29 @@ describe Oga::XML::NodeSet do
end
end
context '#[]' do
describe '#[]' do
before do
@n1 = Oga::XML::Element.new(:name => 'a')
@set = described_class.new([@n1])
end
example 'return a node from a given index' do
it 'returns a node from a given index' do
@set[0].should == @n1
end
end
context '#to_a' do
describe '#to_a' do
before do
@n1 = Oga::XML::Element.new(:name => 'a')
@set = described_class.new([@n1])
end
example 'convert a set to an Array' do
it 'converts a set to an Array' do
@set.to_a.should == [@n1]
end
end
context '#+' do
describe '#+' do
before do
@n1 = Oga::XML::Element.new(:name => 'a')
@n2 = Oga::XML::Element.new(:name => 'b')
@ -269,16 +269,16 @@ describe Oga::XML::NodeSet do
@set2 = described_class.new([@n2])
end
example 'merge two sets together' do
it 'merges two sets together' do
(@set1 + @set2).to_a.should == [@n1, @n2]
end
example 'ignore duplicate nodes' do
it 'ignores duplicate nodes' do
(@set1 + described_class.new([@n1])).length.should == 1
end
end
context '#==' do
describe '#==' do
before do
node = Oga::XML::Node.new
@set1 = described_class.new([node])
@ -286,16 +286,16 @@ describe Oga::XML::NodeSet do
@set3 = described_class.new
end
example 'return true if two node sets are equal' do
it 'returns true if two node sets are equal' do
@set1.should == @set2
end
example 'return false if two node sets are not equal' do
it 'returns false if two node sets are not equal' do
@set1.should_not == @set3
end
end
context '#concat' do
describe '#concat' do
before do
n1 = Oga::XML::Element.new(:name => 'a')
n2 = Oga::XML::Element.new(:name => 'b')
@ -304,14 +304,14 @@ describe Oga::XML::NodeSet do
@set2 = described_class.new([n2])
end
example 'concatenate two node sets' do
it 'concatenates two node sets' do
@set1.concat(@set2)
@set1.length.should == 2
end
end
context '#remove' do
describe '#remove' do
before do
owner = Oga::XML::Element.new
@n1 = Oga::XML::Element.new
@ -321,57 +321,57 @@ describe Oga::XML::NodeSet do
@query_set = described_class.new([@n1, @n2])
end
example 'do not remove the nodes from the current set' do
it 'does not remove the nodes from the current set' do
@query_set.remove
@query_set.empty?.should == false
end
example 'remove the nodes from the owning set' do
it 'removes the nodes from the owning set' do
@query_set.remove
@doc_set.empty?.should == true
end
example 'unlink the nodes from the sets they belong to' do
it 'unlinks the nodes from the sets they belong to' do
@query_set.remove
@n1.node_set.nil?.should == true
@n2.node_set.nil?.should == true
end
example 'remove all nodes from the owned set' do
it 'removes all nodes from the owned set' do
@doc_set.remove
@doc_set.empty?.should == true
end
end
context '#delete' do
describe '#delete' do
before do
owner = Oga::XML::Element.new
@n1 = Oga::XML::Element.new
@set = described_class.new([@n1], owner)
end
example 'return the node when deleting it' do
it 'returns the node when deleting it' do
@set.delete(@n1).should == @n1
end
example 'remove the node from the set' do
it 'removes the node from the set' do
@set.delete(@n1)
@set.empty?.should == true
end
example 'remove ownership of the removed node' do
it 'removes ownership of the removed node' do
@set.delete(@n1)
@n1.node_set.nil?.should == true
end
end
context '#attribute' do
describe '#attribute' do
before do
@attr = Oga::XML::Attribute.new(:name => 'a', :value => '1')
@el = Oga::XML::Element.new(:name => 'a', :attributes => [@attr])
@ -379,12 +379,12 @@ describe Oga::XML::NodeSet do
@set = described_class.new([@el, @txt])
end
example 'return the values of an attribute' do
it 'returns the values of an attribute' do
@set.attribute('a').should == [@attr]
end
end
context '#text' do
describe '#text' do
before do
child = Oga::XML::Text.new(:text => 'foo')
comment = Oga::XML::Comment.new(:text => 'bar')
@ -399,7 +399,7 @@ describe Oga::XML::NodeSet do
@set = described_class.new([@el, text])
end
example 'return the text of all nodes' do
it 'returns the text of all nodes' do
@set.text.should == "foobaz\nbar"
end
end

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe Oga::XML::Node do
context '#initialize' do
example 'set the node set' do
describe '#initialize' do
it 'sets the node set' do
set = Oga::XML::NodeSet.new
node = described_class.new(:node_set => set)
@ -10,12 +10,12 @@ describe Oga::XML::Node do
end
end
context '#children' do
example 'return an empty set by default' do
describe '#children' do
it 'returns an empty set by default' do
described_class.new.children.empty?.should == true
end
example 'return a set that was created manually' do
it 'returns a set that was created manually' do
set = Oga::XML::NodeSet.new([described_class.new])
node = described_class.new(:children => set)
@ -23,8 +23,8 @@ describe Oga::XML::Node do
end
end
context '#children=' do
example 'set the child nodes using an Array' do
describe '#children=' do
it 'sets the child nodes using an Array' do
child = described_class.new
node = described_class.new
@ -33,7 +33,7 @@ describe Oga::XML::Node do
node.children[0].should == child
end
example 'set the child nodes using a NodeSet' do
it 'sets the child nodes using a NodeSet' do
child = described_class.new
node = described_class.new
@ -43,8 +43,8 @@ describe Oga::XML::Node do
end
end
context '#parent' do
example 'return the parent of the node' do
describe '#parent' do
it 'returns the parent of the node' do
owner = described_class.new
set = Oga::XML::NodeSet.new([], owner)
node = described_class.new(:node_set => set)
@ -52,12 +52,12 @@ describe Oga::XML::Node do
node.parent.should == owner
end
example 'return nil if there is no parent node' do
it 'returns nil if there is no parent node' do
described_class.new.parent.nil?.should == true
end
end
context '#previous' do
describe '#previous' do
before do
owner = described_class.new
@n1 = described_class.new
@ -65,16 +65,16 @@ describe Oga::XML::Node do
@set = Oga::XML::NodeSet.new([@n1, @n2], owner)
end
example 'return the previous node' do
it 'returns the previous node' do
@n2.previous.should == @n1
end
example 'return nil if there is no previous node' do
it 'returns nil if there is no previous node' do
@n1.previous.nil?.should == true
end
end
context '#next' do
describe '#next' do
before do
owner = described_class.new
@n1 = described_class.new
@ -82,16 +82,16 @@ describe Oga::XML::Node do
@set = Oga::XML::NodeSet.new([@n1, @n2], owner)
end
example 'return the next node' do
it 'returns the next node' do
@n1.next.should == @n2
end
example 'return nil if there is no previous node' do
it 'returns nil if there is no previous node' do
@n2.next.nil?.should == true
end
end
context '#previous_element' do
describe '#previous_element' do
before do
owner = described_class.new
@n1 = Oga::XML::Element.new
@ -100,20 +100,20 @@ describe Oga::XML::Node do
@set = Oga::XML::NodeSet.new([@n1, @n2, @n3], owner)
end
example 'return the previous element of a generic node' do
it 'returns the previous element of a generic node' do
@n3.previous_element.should == @n1
end
example 'return the previous element of a text node' do
it 'returns the previous element of a text node' do
@n2.previous_element.should == @n1
end
example 'return nil if there is no previous element' do
it 'returns nil if there is no previous element' do
@n1.previous_element.nil?.should == true
end
end
context '#next_element' do
describe '#next_element' do
before do
owner = described_class.new
@n1 = described_class.new
@ -122,20 +122,20 @@ describe Oga::XML::Node do
@set = Oga::XML::NodeSet.new([@n1, @n2, @n3], owner)
end
example 'return the next element of a generic node' do
it 'returns the next element of a generic node' do
@n1.next_element.should == @n3
end
example 'return the next element of a text node' do
it 'returns the next element of a text node' do
@n2.next_element.should == @n3
end
example 'return nil if there is no next element' do
it 'returns nil if there is no next element' do
@n3.next_element.nil?.should == true
end
end
context '#root_node' do
describe '#root_node' do
before do
@n4 = described_class.new
@n3 = described_class.new(:children => [@n4])
@ -144,42 +144,42 @@ describe Oga::XML::Node do
@doc = Oga::XML::Document.new(:children => [@n1])
end
example 'return the root document of an element' do
it 'returns the root document of an element' do
@n2.root_node.should == @doc
end
example 'return the root element of another element' do
it 'returns the root element of another element' do
@n4.root_node.should == @n3
end
end
context '#remove' do
describe '#remove' do
before do
owner = described_class.new
@n1 = described_class.new
@set = Oga::XML::NodeSet.new([@n1], owner)
end
example 'return a node from the node set' do
it 'returns a node from the node set' do
@n1.remove
@set.empty?.should == true
end
example 'remove the reference to the set' do
it 'removes the reference to the set' do
@n1.remove
@n1.node_set.nil?.should == true
end
end
context '#before' do
describe '#before' do
before do
@node = described_class.new
@container = described_class.new(:children => [@node])
end
example 'insert a node before another node' do
it 'inserts a node before another node' do
other = described_class.new
@node.before(other)
@ -189,13 +189,13 @@ describe Oga::XML::Node do
end
end
context '#after' do
describe '#after' do
before do
@node = described_class.new
@container = described_class.new(:children => [@node])
end
example 'insert a node after another node' do
it 'inserts a node after another node' do
other = described_class.new
@node.after(other)

View File

@ -1,36 +1,36 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'empty cdata tags' do
describe 'empty cdata tags' do
before :all do
@node = parse('<![CDATA[]]>').children[0]
end
example 'return a Cdata instance' do
it 'returns a Cdata instance' do
@node.is_a?(Oga::XML::Cdata).should == true
end
end
context 'cdata tags with text' do
describe 'cdata tags with text' do
before :all do
@node = parse('<![CDATA[foo]]>').children[0]
end
example 'return a Cdata instance' do
it 'returns a Cdata instance' do
@node.is_a?(Oga::XML::Cdata).should == true
end
example 'set the text of the tag' do
it 'sets the text of the tag' do
@node.text.should == 'foo'
end
end
context 'cdata tags with nested elements' do
describe 'cdata tags with nested elements' do
before :all do
@node = parse('<![CDATA[<p>foo</p>]]>').children[0]
end
example 'set the HTML as raw text' do
it 'sets the HTML as raw text' do
@node.text.should == '<p>foo</p>'
end
end

View File

@ -1,26 +1,26 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'empty comments' do
describe 'empty comments' do
before :all do
@node = parse('<!---->').children[0]
end
example 'return a Comment instance' do
it 'returns a Comment instance' do
@node.is_a?(Oga::XML::Comment).should == true
end
end
context 'comments with text' do
describe 'comments with text' do
before :all do
@node = parse('<!--foo-->').children[0]
end
example 'return a Comment instance' do
it 'returns a Comment instance' do
@node.is_a?(Oga::XML::Comment).should == true
end
example 'set the text of the comment' do
it 'sets the text of the comment' do
@node.text.should == 'foo'
end
end

View File

@ -1,106 +1,106 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'basic doctypes' do
describe 'basic doctypes' do
before :all do
@document = parse('<!DOCTYPE html>')
end
example 'return a Doctype instance' do
it 'returns a Doctype instance' do
@document.doctype.is_a?(Oga::XML::Doctype).should == true
end
example 'set the name of the doctype' do
it 'sets the name of the doctype' do
@document.doctype.name.should == 'html'
end
end
context 'doctypes with a type' do
describe 'doctypes with a type' do
before :all do
@document = parse('<!DOCTYPE html PUBLIC>')
end
example 'return a Doctype instance' do
it 'returns a Doctype instance' do
@document.doctype.is_a?(Oga::XML::Doctype).should == true
end
example 'set the name of the doctype' do
it 'sets the name of the doctype' do
@document.doctype.name.should == 'html'
end
example 'set the type of the doctype' do
it 'sets the type of the doctype' do
@document.doctype.type.should == 'PUBLIC'
end
end
context 'doctypes with a public ID' do
describe 'doctypes with a public ID' do
before :all do
@document = parse('<!DOCTYPE html PUBLIC "foo">')
end
example 'return a Doctype instance' do
it 'returns a Doctype instance' do
@document.doctype.is_a?(Oga::XML::Doctype).should == true
end
example 'set the name of the doctype' do
it 'sets the name of the doctype' do
@document.doctype.name.should == 'html'
end
example 'set the type of the doctype' do
it 'sets the type of the doctype' do
@document.doctype.type.should == 'PUBLIC'
end
example 'set the public ID of the doctype' do
it 'sets the public ID of the doctype' do
@document.doctype.public_id.should == 'foo'
end
end
context 'doctypes with a system ID' do
describe 'doctypes with a system ID' do
before :all do
@document = parse('<!DOCTYPE html PUBLIC "foo" "bar">')
end
example 'return a Doctype instance' do
it 'returns a Doctype instance' do
@document.doctype.is_a?(Oga::XML::Doctype).should == true
end
example 'set the name of the doctype' do
it 'sets the name of the doctype' do
@document.doctype.name.should == 'html'
end
example 'set the type of the doctype' do
it 'sets the type of the doctype' do
@document.doctype.type.should == 'PUBLIC'
end
example 'set the public ID of the doctype' do
it 'sets the public ID of the doctype' do
@document.doctype.public_id.should == 'foo'
end
example 'set the system ID of the doctype' do
it 'sets the system ID of the doctype' do
@document.doctype.system_id.should == 'bar'
end
end
context 'doctypes with inline rules' do
describe 'doctypes with inline rules' do
before :all do
@document = parse('<!DOCTYPE html [<!ELEMENT foo>]>')
end
example 'return a Doctype instance' do
it 'returns a Doctype instance' do
@document.doctype.is_a?(Oga::XML::Doctype).should == true
end
example 'set the inline doctype rules' do
it 'sets the inline doctype rules' do
@document.doctype.inline_rules.should == '<!ELEMENT foo>'
end
end
context 'doctypes with inline rules and newlines using a StringIO' do
describe 'doctypes with inline rules and newlines using a StringIO' do
before :all do
@document = parse(StringIO.new("<!DOCTYPE html [\nfoo]>"))
end
example 'set the inline doctype rules' do
it 'sets the inline doctype rules' do
@document.doctype.inline_rules.should == "\nfoo"
end
end

View File

@ -1,31 +1,31 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'empty documents' do
describe 'empty documents' do
before :all do
@document = parse('')
end
example 'return a Document instance' do
it 'returns a Document instance' do
@document.is_a?(Oga::XML::Document).should == true
end
end
context 'XML documents' do
describe 'XML documents' do
before :all do
@document = parse('<foo></foo>')
end
example 'return a Document instance' do
it 'returns a Document instance' do
@document.is_a?(Oga::XML::Document).should == true
end
example 'set the document type' do
it 'sets the document type' do
@document.type.should == :xml
end
end
context 'HTML documents' do
describe 'HTML documents' do
before :all do
html = <<-EOF.strip
<?xml version="1.5" ?>
@ -41,23 +41,23 @@ describe Oga::XML::Parser do
@document = parse(html, :html => true)
end
example 'return a Document instance' do
it 'returns a Document instance' do
@document.is_a?(Oga::XML::Document).should == true
end
example 'set the document type' do
it 'sets the document type' do
@document.type.should == :html
end
example 'set the doctype of the document' do
it 'sets the doctype of the document' do
@document.doctype.is_a?(Oga::XML::Doctype).should == true
end
example 'set the XML declaration of the document' do
it 'sets the XML declaration of the document' do
@document.xml_declaration.is_a?(Oga::XML::XmlDeclaration).should == true
end
example 'set the children of the document' do
it 'sets the children of the document' do
@document.children.empty?.should == false
end
end

View File

@ -1,43 +1,43 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'empty elements' do
describe 'empty elements' do
before :all do
@element = parse('<p></p>').children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'set the name of the element' do
it 'sets the name of the element' do
@element.name.should == 'p'
end
example 'do not set a namespace' do
it 'does not set a namespace' do
@element.namespace.should be_nil
end
end
context 'elements with namespaces' do
describe 'elements with namespaces' do
before :all do
@element = parse('<foo:p xmlns:foo="bar"></foo:p>').children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'set the name of the element' do
it 'sets the name of the element' do
@element.name.should == 'p'
end
example 'set the namespace of the element' do
it 'sets the namespace of the element' do
@element.namespace.name.should == 'foo'
end
end
context 'elements with default namespaces' do
describe 'elements with default namespaces' do
before :all do
@document = parse('<foo xmlns="bar"><bar></bar></foo>')
@ -45,124 +45,124 @@ describe Oga::XML::Parser do
@bar = @foo.children[0]
end
example 'set the namespace name of the <foo> element' do
it 'sets the namespace name of the <foo> element' do
@foo.namespace.name.should == 'xmlns'
end
example 'set the namespace URI of the <foo> element' do
it 'sets the namespace URI of the <foo> element' do
@foo.namespace.uri.should == 'bar'
end
example 'set the namespace name of the <bar> element' do
it 'sets the namespace name of the <bar> element' do
@bar.namespace.name.should == 'xmlns'
end
example 'set the namespace URI of the <bar> element' do
it 'sets the namespace URI of the <bar> element' do
@bar.namespace.uri.should == 'bar'
end
end
context 'elements with attributes' do
describe 'elements with attributes' do
before :all do
@element = parse('<foo bar="baz"></foo>').children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'set the bar attribute' do
it 'sets the bar attribute' do
@element.attribute('bar').value.should == 'baz'
end
example 'do not set the attribute namespace' do
it 'does not set the attribute namespace' do
@element.attribute('bar').namespace.should be_nil
end
end
context 'elements with attributes without values' do
describe 'elements with attributes without values' do
before :all do
@element = parse('<foo bar></foo>').children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'set the bar attribute' do
it 'sets the bar attribute' do
@element.attribute('bar').value.should be_nil
end
end
context 'elements with attributes with empty values' do
describe 'elements with attributes with empty values' do
before :all do
@element = parse('<foo bar=""></foo>').children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'set the bar attribute' do
it 'sets the bar attribute' do
@element.attribute('bar').value.should == ''
end
end
context 'elements with namespaced attributes' do
describe 'elements with namespaced attributes' do
before :all do
@element = parse('<foo xmlns:x="x" x:bar="baz"></foo>').children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@element.is_a?(Oga::XML::Element).should == true
end
example 'include the namespace of the attribute' do
it 'includes the namespace of the attribute' do
@element.attribute('x:bar').namespace.name.should == 'x'
end
example 'include the name of the attribute' do
it 'includes the name of the attribute' do
@element.attribute('x:bar').name.should == 'bar'
end
example 'include the value of the attribute' do
it 'includes the value of the attribute' do
@element.attribute('x:bar').value.should == 'baz'
end
end
context 'elements with child elements' do
describe 'elements with child elements' do
before :all do
@element = parse('<a><b></b></a>').children[0]
end
example 'set the name of the outer element' do
it 'sets the name of the outer element' do
@element.name.should == 'a'
end
example 'set the child elements' do
it 'sets the child elements' do
@element.children[0].is_a?(Oga::XML::Element).should == true
end
example 'set the name of the child element' do
it 'sets the name of the child element' do
@element.children[0].name.should == 'b'
end
end
context 'elements with child elements and text' do
describe 'elements with child elements and text' do
before :all do
@element = parse('<a>Foo<b>bar</b></a>').children[0]
end
example 'include the text node of the outer element' do
it 'includes the text node of the outer element' do
@element.children[0].is_a?(Oga::XML::Text).should == true
end
example 'include the text node of the inner element' do
it 'includes the text node of the inner element' do
@element.children[1].children[0].is_a?(Oga::XML::Text).should == true
end
end
context 'elements with namespace registrations' do
describe 'elements with namespace registrations' do
before :all do
document = parse('<root xmlns:a="1"><foo xmlns:b="2"></foo></root>')
@ -170,21 +170,21 @@ describe Oga::XML::Parser do
@foo = @root.children[0]
end
example 'return the namespaces of the <root> node' do
it 'returns the namespaces of the <root> node' do
@root.namespaces['a'].name.should == 'a'
@root.namespaces['a'].uri.should == '1'
end
example 'return the namespaces of the <foo> node' do
it 'returns the namespaces of the <foo> node' do
@foo.namespaces['b'].name.should == 'b'
@foo.namespaces['b'].uri.should == '2'
end
example 'return the available namespaces of the <root> node' do
it 'returns the available namespaces of the <root> node' do
@root.available_namespaces['a'].name.should == 'a'
end
example 'return the available namespaces of the <foo> node' do
it 'returns the available namespaces of the <foo> node' do
@foo.available_namespaces['a'].name.should == 'a'
@foo.available_namespaces['b'].name.should == 'b'
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'raising syntax errors' do
describe 'raising syntax errors' do
before do
@invalid_xml = <<-EOF.strip
<person>
@ -12,19 +12,19 @@ describe Oga::XML::Parser do
EOF
end
example 'raise a Racc::ParseError' do
it 'raises a Racc::ParseError' do
expect { parse(@invalid_xml) }.to raise_error(Racc::ParseError)
end
example 'include the line number when using a String as input' do
it 'includes the line number when using a String as input' do
parse_error(@invalid_xml).should =~ /on line 5/
end
example 'include the line number when using an IO as input' do
it 'includes the line number when using an IO as input' do
parse_error(StringIO.new(@invalid_xml)).should =~ /on line 5/
end
example 'use more friendly error messages when available' do
it 'uses more friendly error messages when available' do
parse_error('</foo>').should =~ /Unexpected element closing tag/
end
end

View File

@ -1,52 +1,52 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'elements with parents' do
describe 'elements with parents' do
before :all do
@parent = parse('<a><b></b></a>').children[0]
end
example 'return an Element instance for the parent' do
it 'returns an Element instance for the parent' do
@parent.children[0].parent.is_a?(Oga::XML::Element).should == true
end
example 'set the correct parent' do
it 'sets the correct parent' do
@parent.children[0].parent.should == @parent
end
end
context 'text nodes with parents' do
describe 'text nodes with parents' do
before :all do
@parent = parse('<a>foo</a>').children[0]
end
example 'return an Element instance for the parent' do
it 'returns an Element instance for the parent' do
@parent.children[0].parent.is_a?(Oga::XML::Element).should == true
end
example 'set the correct parent' do
it 'sets the correct parent' do
@parent.children[0].parent.should == @parent
end
end
context 'elements with adjacent elements' do
describe 'elements with adjacent elements' do
before :all do
@document = parse('<a></a><b></b>')
end
example 'return an Element instance for the next element' do
it 'returns an Element instance for the next element' do
@document.children[0].next.is_a?(Oga::XML::Element).should == true
end
example 'set the correct next element' do
it 'sets the correct next element' do
@document.children[0].next.should == @document.children[1]
end
example 'return an Element instance for the previous element' do
it 'returns an Element instance for the previous element' do
@document.children[1].previous.is_a?(Oga::XML::Element).should == true
end
example 'set the correct previous element' do
it 'sets the correct previous element' do
@document.children[1].previous.should == @document.children[0]
end
end

View File

@ -1,58 +1,58 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'void elements' do
describe 'void elements' do
before :all do
@node = parse('<link>', :html => true).children[0]
end
example 'return an Element instance' do
it 'returns an Element instance' do
@node.is_a?(Oga::XML::Element).should == true
end
example 'set the name of the element' do
it 'sets the name of the element' do
@node.name.should == 'link'
end
end
context 'nested void elements' do
describe 'nested void elements' do
before :all do
@node = parse('<head><link></head>', :html => true).children[0]
end
example 'set the name of the outer element' do
it 'sets the name of the outer element' do
@node.name.should == 'head'
end
example 'set the name of the inner element' do
it 'sets the name of the inner element' do
@node.children[0].name.should == 'link'
end
end
context 'void elements with different casing' do
describe 'void elements with different casing' do
before :all do
@node_uc = parse_html('<BR>').children[0]
end
example 'parse void elements with different casing' do
it 'parses void elements with different casing' do
@node_uc.is_a?(Oga::XML::Element).should == true
end
example 'set the name of the void element to match casing' do
it 'sets the name of the void element to match casing' do
@node_uc.name.should == 'BR'
end
end
context 'void elements with attributes' do
describe 'void elements with attributes' do
before :all do
@node = parse('<link href="foo">', :html => true).children[0]
end
example 'set the name of the element' do
it 'sets the name of the element' do
@node.name.should == 'link'
end
example 'set the attributes' do
it 'sets the attributes' do
@node.attribute('href').value.should == 'foo'
end
end

View File

@ -1,15 +1,15 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'IO as input' do
example 'parse an attribute starting with a newline' do
describe 'IO as input' do
it 'parses an attribute starting with a newline' do
io = StringIO.new("<foo bar='\n10'></foo>")
doc = parse(io)
doc.children[0].attributes[0].value.should == "\n10"
end
example 'parse an attribute value split in two by a newline' do
it 'parses an attribute value split in two by a newline' do
io = StringIO.new("<foo bar='foo\nbar'></foo>")
doc = parse(io)

View File

@ -1,34 +1,34 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'empty processing instructions' do
describe 'empty processing instructions' do
before :all do
@node = parse('<?foo?>').children[0]
end
example 'return a ProcessingInstruction instance' do
it 'returns a ProcessingInstruction instance' do
@node.is_a?(Oga::XML::ProcessingInstruction).should == true
end
example 'set the name of the instruction' do
it 'sets the name of the instruction' do
@node.name.should == 'foo'
end
end
context 'processing instructions with text' do
describe 'processing instructions with text' do
before :all do
@node = parse('<?foo bar ?>').children[0]
end
example 'return a ProcessingInstruction instance' do
it 'returns a ProcessingInstruction instance' do
@node.is_a?(Oga::XML::ProcessingInstruction).should == true
end
example 'set the name of the instruction' do
it 'sets the name of the instruction' do
@node.name.should == 'foo'
end
example 'set the text of the instruction' do
it 'sets the text of the instruction' do
@node.text.should == ' bar '
end
end

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'plain text' do
describe 'plain text' do
before :all do
@node = parse('foo').children[0]
end
example 'return a Text instance' do
it 'returns a Text instance' do
@node.is_a?(Oga::XML::Text).should == true
end
example 'set the text' do
it 'sets the text' do
@node.text.should == 'foo'
end
end

View File

@ -1,38 +1,38 @@
require 'spec_helper'
describe Oga::XML::Parser do
context 'empty XML declaration tags' do
describe 'empty XML declaration tags' do
before :all do
@node = parse('<?xml?>').xml_declaration
end
example 'return an XmlDeclaration instance' do
it 'returns an XmlDeclaration instance' do
@node.is_a?(Oga::XML::XmlDeclaration).should == true
end
example 'set the default XML version' do
it 'sets the default XML version' do
@node.version.should == '1.0'
end
example 'set the default encoding' do
it 'sets the default encoding' do
@node.encoding.should == 'UTF-8'
end
end
context 'XML declaration tags with custom attributes' do
describe 'XML declaration tags with custom attributes' do
before :all do
@node = parse('<?xml version="1.5" encoding="foo" ?>').xml_declaration
end
example 'return an XmlDeclaration instance' do
it 'returns an XmlDeclaration instance' do
@node.is_a?(Oga::XML::XmlDeclaration).should == true
end
example 'set the XML version' do
it 'sets the XML version' do
@node.version.should == '1.5'
end
example 'set the encoding' do
it 'sets the encoding' do
@node.encoding.should == 'foo'
end
end

View File

@ -1,26 +1,26 @@
require 'spec_helper'
describe Oga::XML::ProcessingInstruction do
context '#initialize' do
example 'set the name of the node' do
describe '#initialize' do
it 'sets the name of the node' do
described_class.new(:name => 'foo').name.should == 'foo'
end
example 'set the text of the node' do
it 'sets the text of the node' do
described_class.new(:text => 'foo').text.should == 'foo'
end
end
context '#to_xml' do
example 'conver the node into XML' do
describe '#to_xml' do
it 'convers the node into XML' do
node = described_class.new(:name => 'foo', :text => ' bar ')
node.to_xml.should == '<?foo bar ?>'
end
end
context '#inspect' do
example 'return the inspect value of the node' do
describe '#inspect' do
it 'returns the inspect value of the node' do
node = described_class.new(:name => 'foo', :text => ' bar ')
node.inspect.should == 'ProcessingInstruction(name: "foo" text: " bar ")'

View File

@ -1,26 +1,26 @@
require 'spec_helper'
describe Oga::XML::PullParser do
context '#on' do
describe '#on' do
before do
@parser = Oga::XML::PullParser.new('<a><b></b></a>')
@parser.stub(:node).and_return(Oga::XML::Text.new)
end
example 'do not yield if the node types do not match' do
it 'does not yield if the node types do not match' do
expect { |b| @parser.on(:element, &b) }.to_not yield_control
end
example 'yield if the node type matches and the nesting is empty' do
it 'yields if the node type matches and the nesting is empty' do
expect { |b| @parser.on(:text, &b) }.to yield_control
end
example 'do not yield if the node type matches but the nesting does not' do
it 'does not yield if the node type matches but the nesting does not' do
expect { |b| @parser.on(:text, %w{foo}, &b) }.to_not yield_control
end
example 'yield if the node type and the nesting matches' do
it 'yields if the node type and the nesting matches' do
@parser.stub(:nesting).and_return(%w{a b})
expect { |b| @parser.on(:text, %w{a b}, &b) }.to yield_control

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::PullParser do
context 'doctypes' do
describe 'doctypes' do
before :all do
@parser = described_class.new('<!DOCTYPE html>')
end
example 'ignore doctypes' do
it 'ignores doctypes' do
amount = 0
@parser.parse do

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::PullParser do
context 'tracking element nesting' do
describe 'tracking element nesting' do
before do
@parser = described_class.new('<a><b></b></a>')
end
example 'set the nesting for the outer element' do
it 'sets the nesting for the outer element' do
@parser.parse do |node|
@parser.nesting.should == %w{a} if node.name == 'a'
@ -14,7 +14,7 @@ describe Oga::XML::PullParser do
end
end
example 'pop element names after leaving an element' do
it 'pops element names after leaving an element' do
@parser.nesting.should_receive(:pop).twice
@parser.parse { |node| }

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::PullParser do
context 'elements' do
describe 'elements' do
before :all do
@parser = described_class.new('<person>Alice</person>')
end
example 'parse an element' do
it 'parses an element' do
name = nil
@parser.parse do |node|
@ -16,7 +16,7 @@ describe Oga::XML::PullParser do
name.should == 'person'
end
example 'parse the text of an element' do
it 'parses the text of an element' do
text = nil
@parser.parse do |node|

View File

@ -1,18 +1,18 @@
require 'spec_helper'
describe Oga::XML::PullParser do
context 'tracking nodes' do
describe 'tracking nodes' do
before :all do
@parser = described_class.new('<a></a>')
end
example 'track the current node' do
it 'tracks the current node' do
@parser.parse do
@parser.node.is_a?(Oga::XML::Element).should == true
end
end
example 'reset the current node after parsing' do
it 'resets the current node after parsing' do
@parser.parse { }
@parser.node.nil?.should == true

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XML::PullParser do
context 'processing instructions' do
describe 'processing instructions' do
before :all do
@parser = described_class.new('<?foo bar ?>')
@ -10,15 +10,15 @@ describe Oga::XML::PullParser do
@parser.parse { |node| @node = node }
end
example 'return a ProcessingInstruction node' do
it 'returns a ProcessingInstruction node' do
@node.is_a?(Oga::XML::ProcessingInstruction).should == true
end
example 'set the name of the node' do
it 'sets the name of the node' do
@node.name.should == 'foo'
end
example 'set the text of the node' do
it 'sets the text of the node' do
@node.text.should == ' bar '
end
end

View File

@ -5,42 +5,42 @@ describe Oga::XML::Querying do
@document = parse('<a>foo</a>')
end
context '#xpath' do
example 'query a document' do
describe '#xpath' do
it 'queries a document' do
@document.xpath('a')[0].name.should == 'a'
end
example 'query an element' do
it 'queries an element' do
@document.children[0].xpath('text()')[0].text.should == 'foo'
end
example 'evaluate an expression using a variable' do
it 'evaluates an expression using a variable' do
@document.xpath('$number', 'number' => 10).should == 10
end
end
context '#at_xpath' do
example 'query a document' do
describe '#at_xpath' do
it 'queries a document' do
@document.at_xpath('a').name.should == 'a'
end
example 'query an element' do
it 'queries an element' do
@document.children[0].at_xpath('text()').text.should == 'foo'
end
example 'evaluate an expression using a variable' do
it 'evaluates an expression using a variable' do
@document.at_xpath('$number', 'number' => 10).should == 10
end
end
context '#css' do
example 'query a document' do
describe '#css' do
it 'queries a document' do
@document.css('a').should == @document.children
end
end
context '#at_css' do
example 'query a document' do
describe '#at_css' do
it 'queries a document' do
@document.at_css('a').should == @document.children[0]
end
end

View File

@ -16,13 +16,13 @@ describe Oga::XML::SaxParser do
end
end
example 'ignore return values of callback methods' do
it 'ignores return values of callback methods' do
parser = described_class.new(@handler.new, 'foo')
parser.parse.should be_nil
end
example 'use custom callback methods if defined' do
it 'uses custom callback methods if defined' do
handler = @handler.new
parser = described_class.new(handler, '<foo />')
@ -31,7 +31,7 @@ describe Oga::XML::SaxParser do
handler.name.should == 'foo'
end
example 'always pass element names to after_element' do
it 'always passes element names to after_element' do
handler = @handler.new
parser = described_class.new(handler, '<namespace:foo />')
@ -41,7 +41,7 @@ describe Oga::XML::SaxParser do
handler.after_namespace.should == 'namespace'
end
example 'ignore callbacks that are not defined in the handler' do
it 'ignores callbacks that are not defined in the handler' do
parser = described_class.new(@handler.new, '<!--foo-->')
# This would raise if undefined callbacks were _not_ ignored.

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::Text do
context 'setting attributes' do
example 'set the text via the constructor' do
describe 'setting attributes' do
it 'sets the text via the constructor' do
described_class.new(:text => 'foo').text.should == 'foo'
end
example 'set the text via a setter' do
it 'sets the text via a setter' do
instance = described_class.new
instance.text = 'foo'
@ -14,26 +14,26 @@ describe Oga::XML::Text do
end
end
context '#to_xml' do
example 'generate the corresponding XML' do
describe '#to_xml' do
it 'generates the corresponding XML' do
node = described_class.new(:text => 'foo')
node.to_xml.should == 'foo'
end
example 'encode special characters as XML entities' do
it 'encodes special characters as XML entities' do
node = described_class.new(:text => '&<>')
node.to_xml.should == '&amp;&lt;&gt;'
end
end
context '#inspect' do
describe '#inspect' do
before do
@instance = described_class.new(:text => 'foo')
end
example 'return the inspect value' do
it 'returns the inspect value' do
@instance.inspect.should == 'Text("foo")'
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XML::Traversal do
context '#each_node' do
describe '#each_node' do
before do
@document = parse(<<-EOF.strip.gsub(/\s+/m, ''))
<books>
@ -15,7 +15,7 @@ describe Oga::XML::Traversal do
EOF
end
example 'yield the nodes in document order' do
it 'yields the nodes in document order' do
names = []
@document.each_node do |node|
@ -25,7 +25,7 @@ describe Oga::XML::Traversal do
names.should == %w{books book1 title1 Foo book2 title2 Bar}
end
example 'skip child nodes when skip_children is thrown' do
it 'skips child nodes when skip_children is thrown' do
names = []
@document.each_node do |node|

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe Oga::XML::XmlDeclaration do
context 'setting attributes' do
example 'set the version via the constructor' do
describe 'setting attributes' do
it 'sets the version via the constructor' do
described_class.new(:version => '1.0').version.should == '1.0'
end
example 'set the version via a setter' do
it 'sets the version via a setter' do
instance = described_class.new
instance.version = '1.0'
@ -14,21 +14,21 @@ describe Oga::XML::XmlDeclaration do
end
end
context 'default attribute values' do
describe 'default attribute values' do
before do
@instance = described_class.new
end
example 'set the default version' do
it 'sets the default version' do
@instance.version.should == '1.0'
end
example 'set the default encoding' do
it 'sets the default encoding' do
@instance.encoding.should == 'UTF-8'
end
end
context '#to_xml' do
describe '#to_xml' do
before do
@instance = described_class.new(
:version => '1.0',
@ -37,18 +37,18 @@ describe Oga::XML::XmlDeclaration do
)
end
example 'generate the corresponding XML' do
it 'generates the corresponding XML' do
@instance.to_xml
.should == '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'
end
end
context '#inspect' do
describe '#inspect' do
before do
@instance = described_class.new(:version => '1.0')
end
example 'pretty-print the node' do
it 'pretty-prints the node' do
@instance.inspect.should == <<-EOF.strip
XmlDeclaration(version: "1.0" encoding: "UTF-8")
EOF

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'ancestor-or-self axis' do
describe 'ancestor-or-self axis' do
before do
@document = parse('<a><b><c></c></b></a>')
@ -10,23 +10,23 @@ describe Oga::XPath::Evaluator do
@c1 = @b1.children[0]
end
example 'return a node set containing the direct ancestor' do
it 'returns a node set containing the direct ancestor' do
evaluate_xpath(@c1, 'ancestor-or-self::b').should == node_set(@b1)
end
example 'return a node set containing a higher ancestor' do
it 'returns a node set containing a higher ancestor' do
evaluate_xpath(@c1, 'ancestor-or-self::a').should == node_set(@a1)
end
example 'return a node set containing the context node itself' do
it 'returns a node set containing the context node itself' do
evaluate_xpath(@c1, 'ancestor-or-self::c').should == node_set(@c1)
end
example 'return a node set containing the first ancestor' do
it 'returns a node set containing the first ancestor' do
evaluate_xpath(@c1, 'ancestor-or-self::*[1]').should == node_set(@c1)
end
example 'return an empty node set for non existing ancestors' do
it 'returns an empty node set for non existing ancestors' do
evaluate_xpath(@c1, 'ancestor-or-self::foo').should == node_set
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'ancestor axis' do
describe 'ancestor axis' do
before do
@document = parse('<a><b><c></c></b></a>')
@ -10,19 +10,19 @@ describe Oga::XPath::Evaluator do
@c1 = @b1.children[0]
end
example 'return a node set containing a direct ancestor' do
it 'returns a node set containing a direct ancestor' do
evaluate_xpath(@c1, 'ancestor::b').should == node_set(@b1)
end
example 'return a node set containing a higher ancestor' do
it 'returns a node set containing a higher ancestor' do
evaluate_xpath(@c1, 'ancestor::a').should == node_set(@a1)
end
example 'return a node set containing the first ancestor' do
it 'returns a node set containing the first ancestor' do
evaluate_xpath(@c1, 'ancestor::*[1]').should == node_set(@b1)
end
example 'return an empty node set for non existing ancestors' do
it 'returns an empty node set for non existing ancestors' do
evaluate_xpath(@c1, 'ancestor::c').should == node_set
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'attribute axis' do
describe 'attribute axis' do
before do
@document = parse('<a foo="bar"></a>')
@ -9,15 +9,15 @@ describe Oga::XPath::Evaluator do
@attr = @a1.attribute('foo')
end
example 'return a node set containing an attribute' do
it 'returns a node set containing an attribute' do
evaluate_xpath(@a1, 'attribute::foo').should == node_set(@attr)
end
example 'return a node set containing an attribute using the short form' do
it 'returns a node set containing an attribute using the short form' do
evaluate_xpath(@a1, '@foo').should == node_set(@attr)
end
example 'return an empty node set for non existing attributes' do
it 'returns an empty node set for non existing attributes' do
evaluate_xpath(@a1, 'attribute::bar').should == node_set
end
end

View File

@ -1,7 +1,7 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'child axis' do
describe 'child axis' do
before do
@document = parse('<a><b></b></a>')
@ -9,15 +9,15 @@ describe Oga::XPath::Evaluator do
@b1 = @a1.children[0]
end
example 'return a node set containing a direct child node' do
it 'returns a node set containing a direct child node' do
evaluate_xpath(@document, 'child::a').should == node_set(@a1)
end
example 'return a node set containing a nested child node' do
it 'returns a node set containing a nested child node' do
evaluate_xpath(@document, 'child::a/child::b').should == node_set(@b1)
end
example 'return an empty node set for non existing child nodes' do
it 'returns an empty node set for non existing child nodes' do
evaluate_xpath(@document, 'child::x').should == node_set
end
end

Some files were not shown because too many files have changed in this diff Show More