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' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context 'axes' do describe 'axes' do
context '> axis' do describe '> axis' do
before do before do
@document = parse('<root><a><a /></a></root>') @document = parse('<root><a><a /></a></root>')
@a1 = @document.children[0].children[0] @a1 = @document.children[0].children[0]
end 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) evaluate_css(@document, 'root > a').should == node_set(@a1)
end 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 evaluate_css(@a1, '> a').should == @a1.children
end 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 evaluate_css(@document, '> a').should == node_set
end end
end end
context '+ axis' do describe '+ axis' do
before do before do
@document = parse('<root><a /><b /><b /></root>') @document = parse('<root><a /><b /><b /></root>')
@ -30,20 +30,20 @@ describe 'CSS selector evaluation' do
@b2 = @document.children[0].children[2] @b2 = @document.children[0].children[2]
end 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) evaluate_css(@document, 'root a + b').should == node_set(@b1)
end 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) evaluate_css(@b1, '+ b').should == node_set(@b2)
end 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 evaluate_css(@document, 'root a + c').should == node_set
end end
end end
context '~ axis' do describe '~ axis' do
before do before do
@document = parse('<root><a /><b /><b /></root>') @document = parse('<root><a /><b /><b /></root>')
@ -51,15 +51,15 @@ describe 'CSS selector evaluation' do
@b2 = @document.children[0].children[2] @b2 = @document.children[0].children[2]
end 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) evaluate_css(@document, 'root a ~ b').should == node_set(@b1, @b2)
end 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) evaluate_css(@b1, '~ b').should == node_set(@b2)
end 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 evaluate_css(@document, 'root a ~ c').should == node_set
end end
end end

View File

@ -1,26 +1,26 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context 'classes' do describe 'classes' do
example 'return a node set containing a node with a single class' do it 'returns a node set containing a node with a single class' do
document = parse('<x class="foo" />') document = parse('<x class="foo" />')
evaluate_css(document, '.foo').should == document.children evaluate_css(document, '.foo').should == document.children
end 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" />') document = parse('<x class="foo bar" />')
evaluate_css(document, '.foo').should == document.children evaluate_css(document, '.foo').should == document.children
end 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" />') document = parse('<x class="foo bar" />')
evaluate_css(document, '.foo.bar').should == document.children evaluate_css(document, '.foo.bar').should == document.children
end 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" />') document = parse('<x class="bar" />')
evaluate_css(document, '.foo').should == node_set evaluate_css(document, '.foo').should == node_set

View File

@ -1,16 +1,16 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context 'IDs' do describe 'IDs' do
before do before do
@document = parse('<x id="foo" />') @document = parse('<x id="foo" />')
end 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 evaluate_css(@document, '#foo').should == @document.children
end 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 evaluate_css(@document, '#bar').should == node_set
end end
end end

View File

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

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context 'paths' do describe 'paths' do
before do before do
@document = parse('<a xmlns:ns1="x"><b></b><b></b><ns1:c></ns1:c></a>') @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] @c1 = @a1.children[2]
end 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) evaluate_css(@document, 'a').should == node_set(@a1)
end 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) evaluate_css(@document, 'a b').should == node_set(@b1, @b2)
end 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) evaluate_css(@document, 'a ns1|c').should == node_set(@c1)
end 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) evaluate_css(@document, 'a *').should == node_set(@b1, @b2, @c1)
end 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') evaluate_css(@document, 'a *|c')
end 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) evaluate_css(@document, 'a ns1|*').should == node_set(@c1)
end 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) evaluate_css(@document, 'a *|*').should == node_set(@b1, @b2, @c1)
end end
end end

View File

@ -1,18 +1,18 @@
require 'spec_helper' require 'spec_helper'
context 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context 'predicates' do describe 'predicates' do
before do before do
@document = parse('<root><a class="foo" /></root>') @document = parse('<root><a class="foo" /></root>')
@a1 = @document.children[0].children[0] @a1 = @document.children[0].children[0]
end 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) evaluate_css(@document, 'root a[class]').should == node_set(@a1)
end 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) evaluate_css(@document, 'root a[class="foo"]').should == node_set(@a1)
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':empty pseudo class' do describe ':empty pseudo class' do
before do before do
@document = parse('<root><a></a><b>foo</b></root>') @document = parse('<root><a></a><b>foo</b></root>')
@ -9,15 +9,15 @@ describe 'CSS selector evaluation' do
@b1 = @document.children[0].children[1] @b1 = @document.children[0].children[1]
end 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) evaluate_css(@document, 'root :empty').should == node_set(@a1)
end 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) evaluate_css(@document, 'root a:empty').should == node_set(@a1)
end 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 evaluate_css(@document, 'root b:empty').should == node_set
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':first-child pseudo class' do describe ':first-child pseudo class' do
before do before do
@document = parse('<root><a /><b /></root>') @document = parse('<root><a /><b /></root>')
@ -9,15 +9,15 @@ describe 'CSS selector evaluation' do
@b1 = @document.children[0].children[1] @b1 = @document.children[0].children[1]
end 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) evaluate_css(@document, 'root :first-child').should == node_set(@a1)
end 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) evaluate_css(@document, 'root a:first-child').should == node_set(@a1)
end 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 evaluate_css(@document, 'root b:first-child').should == node_set
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':first-of-type pseudo class' do describe ':first-of-type pseudo class' do
before do before do
@document = parse(<<-EOF) @document = parse(<<-EOF)
<root> <root>
@ -17,7 +17,7 @@ describe 'CSS selector evaluation' do
@a3 = @document.at_xpath('root/a[2]/a[1]') @a3 = @document.at_xpath('root/a[2]/a[1]')
end 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') evaluate_css(@document, 'root a:first-of-type')
.should == node_set(@a1, @a3) .should == node_set(@a1, @a3)
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':last-child pseudo class' do describe ':last-child pseudo class' do
before do before do
@document = parse('<root><a /><b /></root>') @document = parse('<root><a /><b /></root>')
@ -9,15 +9,15 @@ describe 'CSS selector evaluation' do
@b1 = @document.children[0].children[1] @b1 = @document.children[0].children[1]
end 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) evaluate_css(@document, 'root :last-child').should == node_set(@b1)
end 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) evaluate_css(@document, 'root b:last-child').should == node_set(@b1)
end 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 evaluate_css(@document, 'root a:last-child').should == node_set
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':last-of-type pseudo class' do describe ':last-of-type pseudo class' do
before do before do
@document = parse(<<-EOF) @document = parse(<<-EOF)
<root> <root>
@ -17,7 +17,7 @@ describe 'CSS selector evaluation' do
@a4 = @document.at_xpath('root/a[2]/a[2]') @a4 = @document.at_xpath('root/a[2]/a[2]')
end 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') evaluate_css(@document, 'root a:last-of-type')
.should == node_set(@a2, @a4) .should == node_set(@a2, @a4)
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':nth-child pseudo class' do describe ':nth-child pseudo class' do
before do before do
@document = parse('<root><a1 /><a2 /><a3 /><a4 /></root>') @document = parse('<root><a1 /><a2 /><a3 /><a4 /></root>')
@ -12,35 +12,35 @@ describe 'CSS selector evaluation' do
@a4 = @root.children[3] @a4 = @root.children[3]
end 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) evaluate_css(@document, 'root :nth-child(1)').should == node_set(@a1)
end 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)') evaluate_css(@document, 'root :nth-child(even)')
.should == node_set(@a2, @a4) .should == node_set(@a2, @a4)
end 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)') evaluate_css(@document, 'root :nth-child(odd)')
.should == node_set(@a1, @a3) .should == node_set(@a1, @a3)
end 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)') evaluate_css(@document, 'root :nth-child(2n+2)')
.should == node_set(@a2, @a4) .should == node_set(@a2, @a4)
end 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 evaluate_css(@document, 'root :nth-child(n)').should == @root.children
end 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)') evaluate_css(@document, 'root :nth-child(-n+2)')
.should == node_set(@a1, @a2) .should == node_set(@a1, @a2)
end 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)') evaluate_css(@document, 'root :nth-child(n+2)')
.should == node_set(@a2, @a3, @a4) .should == node_set(@a2, @a3, @a4)
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':nth-last-child pseudo class' do describe ':nth-last-child pseudo class' do
before do before do
@document = parse('<root><a1 /><a2 /><a3 /><a4 /></root>') @document = parse('<root><a1 /><a2 /><a3 /><a4 /></root>')
@ -12,36 +12,36 @@ describe 'CSS selector evaluation' do
@a4 = @root.children[3] @a4 = @root.children[3]
end 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) evaluate_css(@document, 'root :nth-last-child(1)').should == node_set(@a4)
end 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)') evaluate_css(@document, 'root :nth-last-child(even)')
.should == node_set(@a1, @a3) .should == node_set(@a1, @a3)
end 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)') evaluate_css(@document, 'root :nth-last-child(odd)')
.should == node_set(@a2, @a4) .should == node_set(@a2, @a4)
end 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)') evaluate_css(@document, 'root :nth-last-child(2n+2)')
.should == node_set(@a1, @a3) .should == node_set(@a1, @a3)
end 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)') evaluate_css(@document, 'root :nth-last-child(n)')
.should == @root.children .should == @root.children
end 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)') evaluate_css(@document, 'root :nth-last-child(-n+2)')
.should == node_set(@a3, @a4) .should == node_set(@a3, @a4)
end 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)') evaluate_css(@document, 'root :nth-last-child(n+2)')
.should == node_set(@a1, @a2, @a3) .should == node_set(@a1, @a2, @a3)
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':nth-last-of-type pseudo class' do describe ':nth-last-of-type pseudo class' do
before do before do
@document = parse(<<-EOF.strip) @document = parse(<<-EOF.strip)
<root> <root>
@ -21,37 +21,37 @@ describe 'CSS selector evaluation' do
@a4 = @root.at_xpath('b/a') @a4 = @root.at_xpath('b/a')
end 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)') evaluate_css(@document, 'root a:nth-last-of-type(1)')
.should == node_set(@a3, @a4) .should == node_set(@a3, @a4)
end 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)') evaluate_css(@document, 'root a:nth-last-of-type(even)')
.should == node_set(@a2) .should == node_set(@a2)
end 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)') evaluate_css(@document, 'root a:nth-last-of-type(odd)')
.should == node_set(@a1, @a3, @a4) .should == node_set(@a1, @a3, @a4)
end 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)') evaluate_css(@document, 'root a:nth-last-of-type(2n+2)')
.should == node_set(@a2) .should == node_set(@a2)
end 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)') evaluate_css(@document, 'root a:nth-last-of-type(n)')
.should == node_set(@a1, @a2, @a3, @a4) .should == node_set(@a1, @a2, @a3, @a4)
end 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)') evaluate_css(@document, 'root a:nth-last-of-type(-n+2)')
.should == node_set(@a2, @a3, @a4) .should == node_set(@a2, @a3, @a4)
end 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)') evaluate_css(@document, 'root a:nth-last-of-type(n+2)')
.should == node_set(@a1, @a2) .should == node_set(@a1, @a2)
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':nth-of-type pseudo class' do describe ':nth-of-type pseudo class' do
before do before do
@document = parse(<<-EOF.strip) @document = parse(<<-EOF.strip)
<root> <root>
@ -21,37 +21,37 @@ describe 'CSS selector evaluation' do
@a4 = @root.at_xpath('b/a') @a4 = @root.at_xpath('b/a')
end 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)') evaluate_css(@document, 'root a:nth-of-type(1)')
.should == node_set(@a1, @a4) .should == node_set(@a1, @a4)
end 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)') evaluate_css(@document, 'root a:nth-of-type(even)')
.should == node_set(@a2) .should == node_set(@a2)
end 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)') evaluate_css(@document, 'root a:nth-of-type(odd)')
.should == node_set(@a1, @a3, @a4) .should == node_set(@a1, @a3, @a4)
end 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)') evaluate_css(@document, 'root a:nth-of-type(2n+2)')
.should == node_set(@a2) .should == node_set(@a2)
end 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)') evaluate_css(@document, 'root a:nth-of-type(n)')
.should == node_set(@a1, @a2, @a3, @a4) .should == node_set(@a1, @a2, @a3, @a4)
end 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)') evaluate_css(@document, 'root a:nth-of-type(-n+2)')
.should == node_set(@a1, @a2, @a4) .should == node_set(@a1, @a2, @a4)
end 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)') evaluate_css(@document, 'root a:nth-of-type(n+2)')
.should == node_set(@a2, @a3) .should == node_set(@a2, @a3)
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':only-child pseudo class' do describe ':only-child pseudo class' do
before do before do
@document = parse('<root><a><c /></a><b><c /></b></root>') @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] @c2 = @root.children[1].children[0]
end 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) evaluate_css(@document, 'root :only-child').should == node_set(@c1, @c2)
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':only-of-type pseudo class' do describe ':only-of-type pseudo class' do
before do before do
@document = parse('<root><a><c /></a><b><c /></b></root>') @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] @c2 = @root.children[1].children[0]
end 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) evaluate_css(@document, 'root a :only-of-type').should == node_set(@c1)
end end
end end

View File

@ -1,12 +1,12 @@
require 'spec_helper' require 'spec_helper'
describe 'CSS selector evaluation' do describe 'CSS selector evaluation' do
context ':root pseudo class' do describe ':root pseudo class' do
before do before do
@document = parse('<root><a /></root>') @document = parse('<root><a /></root>')
end 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 evaluate_css(@document, ':root').should == @document.children
end end
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,53 +1,53 @@
require 'spec_helper' require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
context 'axes' do describe 'axes' do
example 'parse the > axis' do it 'parses the > axis' do
parse_css('x > y').should == parse_xpath('descendant::x/y') parse_css('x > y').should == parse_xpath('descendant::x/y')
end 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') parse_css('a > b > c').should == parse_xpath('descendant::a/b/c')
end 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( parse_css('x > foo#bar').should == parse_xpath(
'descendant::x/foo[@id="bar"]' 'descendant::x/foo[@id="bar"]'
) )
end 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( parse_css('x > foo.bar').should == parse_xpath(
'descendant::x/foo[contains(concat(" ", @class, " "), " bar ")]' 'descendant::x/foo[contains(concat(" ", @class, " "), " bar ")]'
) )
end end
example 'parse the + axis' do it 'parses the + axis' do
parse_css('x + y').should == parse_xpath( parse_css('x + y').should == parse_xpath(
'descendant::x/following-sibling::*[1]/self::y' 'descendant::x/following-sibling::*[1]/self::y'
) )
end 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( parse_css('a + b + c').should == parse_xpath(
'descendant::a/following-sibling::*[1]/self::b/' \ 'descendant::a/following-sibling::*[1]/self::b/' \
'following-sibling::*[1]/self::c' 'following-sibling::*[1]/self::c'
) )
end end
example 'parse the ~ axis' do it 'parses the ~ axis' do
parse_css('x ~ y').should == parse_xpath( parse_css('x ~ y').should == parse_xpath(
'descendant::x/following-sibling::y' 'descendant::x/following-sibling::y'
) )
end 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( parse_css('x ~ y z').should == parse_xpath(
'descendant::x/following-sibling::y/descendant::z' 'descendant::x/following-sibling::y/descendant::z'
) )
end 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( parse_css('a ~ b ~ c').should == parse_xpath(
'descendant::a/following-sibling::b/following-sibling::c' 'descendant::a/following-sibling::b/following-sibling::c'
) )

View File

@ -1,27 +1,27 @@
require 'spec_helper' require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
context 'classes' do describe 'classes' do
example 'parse a class selector' do it 'parses a class selector' do
parse_css('.foo').should == parse_xpath( parse_css('.foo').should == parse_xpath(
'descendant::*[contains(concat(" ", @class, " "), " foo ")]' 'descendant::*[contains(concat(" ", @class, " "), " foo ")]'
) )
end 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( parse_css('foo.bar').should == parse_xpath(
'descendant::foo[contains(concat(" ", @class, " "), " bar ")]' 'descendant::foo[contains(concat(" ", @class, " "), " bar ")]'
) )
end end
example 'parse a selector using multiple classes' do it 'parses a selector using multiple classes' do
parse_css('.foo.bar').should == parse_xpath( parse_css('.foo.bar').should == parse_xpath(
'descendant::*[contains(concat(" ", @class, " "), " foo ") ' \ 'descendant::*[contains(concat(" ", @class, " "), " foo ") ' \
'and contains(concat(" ", @class, " "), " bar ")]' 'and contains(concat(" ", @class, " "), " bar ")]'
) )
end 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( parse_css('#foo.bar').should == parse_xpath(
'descendant::*[@id="foo" and ' \ 'descendant::*[@id="foo" and ' \
'contains(concat(" ", @class, " "), " bar ")]' 'contains(concat(" ", @class, " "), " bar ")]'

View File

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

View File

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

View File

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

View File

@ -1,18 +1,18 @@
require 'spec_helper' require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
context 'predicates' do describe 'predicates' do
example 'parse a predicate' do it 'parses a predicate' do
parse_css('foo[bar]').should == parse_xpath('descendant::foo[@bar]') parse_css('foo[bar]').should == parse_xpath('descendant::foo[@bar]')
end 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( parse_css('foo bar[baz]').should == parse_xpath(
'descendant::foo/descendant::bar[@baz]' 'descendant::foo/descendant::bar[@baz]'
) )
end 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( parse_css('foo[bar="baz"]').should == parse_xpath(
'descendant::foo[@bar="baz"]' 'descendant::foo[@bar="baz"]'
) )

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,20 +1,20 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
context 'cdata tags' do describe 'cdata tags' do
example 'lex a cdata tag' do it 'lexes a cdata tag' do
lex('<![CDATA[foo]]>').should == [[:T_CDATA, 'foo', 1]] lex('<![CDATA[foo]]>').should == [[:T_CDATA, 'foo', 1]]
end 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]] lex('<![CDATA[<p>Foo</p>]]>').should == [[:T_CDATA, '<p>Foo</p>', 1]]
end 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]] lex('<![CDATA[]]]]>').should == [[:T_CDATA, ']]', 1]]
end 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 == [ lex('<a><![CDATA[foo]]><b><![CDATA[bar]]></b></a>').should == [
[:T_ELEM_START, nil, 1], [:T_ELEM_START, nil, 1],
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],

View File

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

View File

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
context 'doctypes' do describe 'doctypes' do
example 'lex the HTML5 doctype' do it 'lexes the HTML5 doctype' do
lex('<!DOCTYPE html>').should == [ lex('<!DOCTYPE html>').should == [
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
@ -10,7 +10,7 @@ describe Oga::XML::Lexer do
] ]
end 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 == [ lex('<!DOCTYPE HTML PUBLIC "foobar" "baz">').should == [
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'HTML', 1], [:T_DOCTYPE_NAME, 'HTML', 1],
@ -25,7 +25,7 @@ describe Oga::XML::Lexer do
] ]
end 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 == [ lex("<!DOCTYPE HTML PUBLIC 'foobar' 'baz'>").should == [
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'HTML', 1], [:T_DOCTYPE_NAME, 'HTML', 1],
@ -40,7 +40,7 @@ describe Oga::XML::Lexer do
] ]
end end
example 'lex an inline doctype' do it 'lexes an inline doctype' do
lex('<!DOCTYPE html [<!ELEMENT foo>]>').should == [ lex('<!DOCTYPE html [<!ELEMENT foo>]>').should == [
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
@ -49,7 +49,7 @@ describe Oga::XML::Lexer do
] ]
end end
example 'lex an empty inline doctype' do it 'lexes an empty inline doctype' do
lex('<!DOCTYPE html []>').should == [ lex('<!DOCTYPE html []>').should == [
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
@ -57,7 +57,7 @@ describe Oga::XML::Lexer do
] ]
end 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 == [ lex("<!DOCTYPE html [foo\n]>").should == [
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
@ -66,7 +66,7 @@ describe Oga::XML::Lexer do
] ]
end 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]>") input = StringIO.new("<!DOCTYPE html [foo\n]>")
lex(input).should == [ lex(input).should == [
@ -77,7 +77,7 @@ describe Oga::XML::Lexer do
] ]
end 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]>") input = StringIO.new("<!DOCTYPE html [\nfoo]>")
lex(input).should == [ 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 # Technically not valid, put in place to make sure that the Ragel rules are
# not too greedy. # 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 == [ lex('<!DOCTYPE html [<!ELEMENT foo>] "foo">').should == [
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
context 'IO as input' do describe 'IO as input' do
example 'lex a paragraph element with attributes' do it 'lexes a paragraph element with attributes' do
io = StringIO.new("<p class='foo'>\nHello</p>") io = StringIO.new("<p class='foo'>\nHello</p>")
lex(io).should == [ lex(io).should == [
@ -18,7 +18,7 @@ describe Oga::XML::Lexer do
] ]
end 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>") io = StringIO.new("<p class='foo'>\nHello</p>")
lexer = described_class.new(io) lexer = described_class.new(io)
@ -26,7 +26,7 @@ describe Oga::XML::Lexer do
lexer.lex.empty?.should == false lexer.lex.empty?.should == false
end 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>") io = StringIO.new("<foo bar='\n10'></foo>")
lexer = described_class.new(io) lexer = described_class.new(io)
@ -42,7 +42,7 @@ describe Oga::XML::Lexer do
] ]
end 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>") io = StringIO.new("<foo bar='foo\nbar'></foo>")
lexer = described_class.new(io) lexer = described_class.new(io)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XML::Parser do describe Oga::XML::Parser do
context 'raising syntax errors' do describe 'raising syntax errors' do
before do before do
@invalid_xml = <<-EOF.strip @invalid_xml = <<-EOF.strip
<person> <person>
@ -12,19 +12,19 @@ describe Oga::XML::Parser do
EOF EOF
end end
example 'raise a Racc::ParseError' do it 'raises a Racc::ParseError' do
expect { parse(@invalid_xml) }.to raise_error(Racc::ParseError) expect { parse(@invalid_xml) }.to raise_error(Racc::ParseError)
end 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/ parse_error(@invalid_xml).should =~ /on line 5/
end 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/ parse_error(StringIO.new(@invalid_xml)).should =~ /on line 5/
end 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/ parse_error('</foo>').should =~ /Unexpected element closing tag/
end end
end end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,26 +1,26 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XML::PullParser do describe Oga::XML::PullParser do
context '#on' do describe '#on' do
before do before do
@parser = Oga::XML::PullParser.new('<a><b></b></a>') @parser = Oga::XML::PullParser.new('<a><b></b></a>')
@parser.stub(:node).and_return(Oga::XML::Text.new) @parser.stub(:node).and_return(Oga::XML::Text.new)
end 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 expect { |b| @parser.on(:element, &b) }.to_not yield_control
end 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 expect { |b| @parser.on(:text, &b) }.to yield_control
end 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 expect { |b| @parser.on(:text, %w{foo}, &b) }.to_not yield_control
end 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}) @parser.stub(:nesting).and_return(%w{a b})
expect { |b| @parser.on(:text, %w{a b}, &b) }.to yield_control expect { |b| @parser.on(:text, %w{a b}, &b) }.to yield_control

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'ancestor-or-self axis' do describe 'ancestor-or-self axis' do
before do before do
@document = parse('<a><b><c></c></b></a>') @document = parse('<a><b><c></c></b></a>')
@ -10,23 +10,23 @@ describe Oga::XPath::Evaluator do
@c1 = @b1.children[0] @c1 = @b1.children[0]
end 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) evaluate_xpath(@c1, 'ancestor-or-self::b').should == node_set(@b1)
end 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) evaluate_xpath(@c1, 'ancestor-or-self::a').should == node_set(@a1)
end 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) evaluate_xpath(@c1, 'ancestor-or-self::c').should == node_set(@c1)
end 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) evaluate_xpath(@c1, 'ancestor-or-self::*[1]').should == node_set(@c1)
end 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 evaluate_xpath(@c1, 'ancestor-or-self::foo').should == node_set
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'ancestor axis' do describe 'ancestor axis' do
before do before do
@document = parse('<a><b><c></c></b></a>') @document = parse('<a><b><c></c></b></a>')
@ -10,19 +10,19 @@ describe Oga::XPath::Evaluator do
@c1 = @b1.children[0] @c1 = @b1.children[0]
end 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) evaluate_xpath(@c1, 'ancestor::b').should == node_set(@b1)
end 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) evaluate_xpath(@c1, 'ancestor::a').should == node_set(@a1)
end 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) evaluate_xpath(@c1, 'ancestor::*[1]').should == node_set(@b1)
end 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 evaluate_xpath(@c1, 'ancestor::c').should == node_set
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'attribute axis' do describe 'attribute axis' do
before do before do
@document = parse('<a foo="bar"></a>') @document = parse('<a foo="bar"></a>')
@ -9,15 +9,15 @@ describe Oga::XPath::Evaluator do
@attr = @a1.attribute('foo') @attr = @a1.attribute('foo')
end 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) evaluate_xpath(@a1, 'attribute::foo').should == node_set(@attr)
end 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) evaluate_xpath(@a1, '@foo').should == node_set(@attr)
end 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 evaluate_xpath(@a1, 'attribute::bar').should == node_set
end end
end end

View File

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'child axis' do describe 'child axis' do
before do before do
@document = parse('<a><b></b></a>') @document = parse('<a><b></b></a>')
@ -9,15 +9,15 @@ describe Oga::XPath::Evaluator do
@b1 = @a1.children[0] @b1 = @a1.children[0]
end 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) evaluate_xpath(@document, 'child::a').should == node_set(@a1)
end 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) evaluate_xpath(@document, 'child::a/child::b').should == node_set(@b1)
end 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 evaluate_xpath(@document, 'child::x').should == node_set
end end
end end

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