Use RSpec 3 expect syntax for tests

This should make it a little bit easier for others to contribute.
This commit is contained in:
Yorick Peterse 2017-06-17 13:52:43 +02:00
parent 8282325569
commit 6f747656b6
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
227 changed files with 2202 additions and 2201 deletions

View File

@ -14,15 +14,15 @@ describe Oga::Blacklist do
it 'returns true for a name not in the list' do it 'returns true for a name not in the list' do
list = described_class.new(%w{foo}) list = described_class.new(%w{foo})
list.allow?('bar').should == true expect(list.allow?('bar')).to eq(true)
list.allow?('BAR').should == true expect(list.allow?('BAR')).to eq(true)
end end
it 'returns false for a name in the list' do it 'returns false for a name in the list' do
list = described_class.new(%w{foo}) list = described_class.new(%w{foo})
list.allow?('foo').should == false expect(list.allow?('foo')).to eq(false)
list.allow?('FOO').should == false expect(list.allow?('FOO')).to eq(false)
end end
end end
@ -32,8 +32,8 @@ describe Oga::Blacklist do
list2 = described_class.new(%w{bar}) list2 = described_class.new(%w{bar})
list3 = list1 + list2 list3 = list1 + list2
list3.should be_an_instance_of(described_class) expect(list3).to be_an_instance_of(described_class)
list3.names.to_a.should == %w{foo FOO bar BAR} expect(list3.names.to_a).to eq(%w{foo FOO bar BAR})
end end
end end
end end

View File

@ -10,15 +10,15 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root > a')).to eq(node_set(@a1))
end end
it 'returns 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 expect(evaluate_css(@a1, '> a')).to eq(@a1.children)
end end
it 'returns 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 expect(evaluate_css(@document, '> a')).to eq(node_set)
end end
end end
@ -31,15 +31,15 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root a + b')).to eq(node_set(@b1))
end end
it 'returns 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) expect(evaluate_css(@b1, '+ b')).to eq(node_set(@b2))
end end
it 'returns 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 expect(evaluate_css(@document, 'root a + c')).to eq(node_set)
end end
end end
@ -52,15 +52,15 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root a ~ b')).to eq(node_set(@b1, @b2))
end end
it 'returns 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) expect(evaluate_css(@b1, '~ b')).to eq(node_set(@b2))
end end
it 'returns 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 expect(evaluate_css(@document, 'root a ~ c')).to eq(node_set)
end end
end end
end end

View File

@ -5,25 +5,25 @@ describe 'CSS selector evaluation' do
it 'returns 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 expect(evaluate_css(document, '.foo')).to eq(document.children)
end end
it 'returns 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 expect(evaluate_css(document, '.foo')).to eq(document.children)
end end
it 'returns 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 expect(evaluate_css(document, '.foo.bar')).to eq(document.children)
end end
it 'returns 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 expect(evaluate_css(document, '.foo')).to eq(node_set)
end end
end end
end end

View File

@ -7,11 +7,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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 expect(evaluate_css(@document, '#foo')).to eq(@document.children)
end end
it 'returns 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 expect(evaluate_css(@document, '#bar')).to eq(node_set)
end end
end end
end end

View File

@ -8,11 +8,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a = "b"]')).to eq(@document.children)
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a = "c"]')).to eq(node_set)
end end
end end
@ -20,19 +20,19 @@ describe 'CSS selector evaluation' do
it 'returns 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 expect(evaluate_css(document, 'x[a ~= "2"]')).to eq(document.children)
end end
it 'returns 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 expect(evaluate_css(document, 'x[a ~= "1"]')).to eq(document.children)
end end
it 'returns 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 expect(evaluate_css(document, 'x[a ~= "4"]')).to eq(node_set)
end end
end end
@ -42,11 +42,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a ^= "fo"]')).to eq(@document.children)
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a ^= "bar"]')).to eq(node_set)
end end
end end
@ -56,11 +56,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a $= "oo"]')).to eq(@document.children)
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a $= "x"]')).to eq(node_set)
end end
end end
@ -70,11 +70,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a *= "o"]')).to eq(@document.children)
end end
it 'returns 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 expect(evaluate_css(@document, 'x[a *= "x"]')).to eq(node_set)
end end
end end
@ -82,19 +82,19 @@ describe 'CSS selector evaluation' do
it 'returns 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 expect(evaluate_css(document, 'x[a |= "foo"]')).to eq(document.children)
end end
it 'returns 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 expect(evaluate_css(document, 'x[a |= "foo"]')).to eq(document.children)
end end
it 'returns 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 expect(evaluate_css(document, 'x[a |= "foo"]')).to eq(node_set)
end end
end end
end end

View File

@ -12,23 +12,23 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'a')).to eq(node_set(@a1))
end end
it 'returns 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) expect(evaluate_css(@document, 'a b')).to eq(node_set(@b1, @b2))
end end
it 'returns a node set containing the union of multiple paths' do it 'returns a node set containing the union of multiple paths' do
evaluate_css(@document, 'b, ns1|c').should == node_set(@b1, @b2, @c1) expect(evaluate_css(@document, 'b, ns1|c')).to eq(node_set(@b1, @b2, @c1))
end end
it 'returns 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) expect(evaluate_css(@document, 'a ns1|c')).to eq(node_set(@c1))
end end
it 'returns 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) expect(evaluate_css(@document, 'a *')).to eq(node_set(@b1, @b2, @c1))
end end
it 'returns a node set containing nodes with namespace wildcards' do it 'returns a node set containing nodes with namespace wildcards' do
@ -36,11 +36,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'a ns1|*')).to eq(node_set(@c1))
end end
it 'returns 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) expect(evaluate_css(@document, 'a *|*')).to eq(node_set(@b1, @b2, @c1))
end end
end end
end end

View File

@ -9,11 +9,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root a[class]')).to eq(node_set(@a1))
end end
it 'returns 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) expect(evaluate_css(@document, 'root a[class="foo"]')).to eq(node_set(@a1))
end end
end end
end end

View File

@ -10,15 +10,15 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root :empty')).to eq(node_set(@a1))
end end
it 'returns 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) expect(evaluate_css(@document, 'root a:empty')).to eq(node_set(@a1))
end end
it 'returns 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 expect(evaluate_css(@document, 'root b:empty')).to eq(node_set)
end end
end end
end end

View File

@ -10,15 +10,15 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root :first-child')).to eq(node_set(@a1))
end end
it 'returns 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) expect(evaluate_css(@document, 'root a:first-child')).to eq(node_set(@a1))
end end
it 'returns 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 expect(evaluate_css(@document, 'root b:first-child')).to eq(node_set)
end end
end end
end end

View File

@ -18,8 +18,8 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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') expect(evaluate_css(@document, 'root a:first-of-type'))
.should == node_set(@a1, @a3) .to eq(node_set(@a1, @a3))
end end
end end
end end

View File

@ -10,15 +10,15 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root :last-child')).to eq(node_set(@b1))
end end
it 'returns 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) expect(evaluate_css(@document, 'root b:last-child')).to eq(node_set(@b1))
end end
it 'returns 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 expect(evaluate_css(@document, 'root a:last-child')).to eq(node_set)
end end
end end
end end

View File

@ -18,8 +18,8 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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') expect(evaluate_css(@document, 'root a:last-of-type'))
.should == node_set(@a2, @a4) .to eq(node_set(@a2, @a4))
end end
end end
end end

View File

@ -13,36 +13,36 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root :nth-child(1)')).to eq(node_set(@a1))
end end
it 'returns a node set containing even nodes' do it 'returns a node set containing even nodes' do
evaluate_css(@document, 'root :nth-child(even)') expect(evaluate_css(@document, 'root :nth-child(even)'))
.should == node_set(@a2, @a4) .to eq(node_set(@a2, @a4))
end end
it 'returns a node set containing odd nodes' do it 'returns a node set containing odd nodes' do
evaluate_css(@document, 'root :nth-child(odd)') expect(evaluate_css(@document, 'root :nth-child(odd)'))
.should == node_set(@a1, @a3) .to eq(node_set(@a1, @a3))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root :nth-child(2n+2)'))
.should == node_set(@a2, @a4) .to eq(node_set(@a2, @a4))
end end
it 'returns 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 expect(evaluate_css(@document, 'root :nth-child(n)')).to eq(@root.children)
end end
it 'returns 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)') expect(evaluate_css(@document, 'root :nth-child(-n+2)'))
.should == node_set(@a1, @a2) .to eq(node_set(@a1, @a2))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root :nth-child(n+2)'))
.should == node_set(@a2, @a3, @a4) .to eq(node_set(@a2, @a3, @a4))
end end
end end
end end

View File

@ -13,37 +13,37 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root :nth-last-child(1)')).to eq(node_set(@a4))
end end
it 'returns a node set containing even nodes' do it 'returns a node set containing even nodes' do
evaluate_css(@document, 'root :nth-last-child(even)') expect(evaluate_css(@document, 'root :nth-last-child(even)'))
.should == node_set(@a1, @a3) .to eq(node_set(@a1, @a3))
end end
it 'returns a node set containing odd nodes' do it 'returns a node set containing odd nodes' do
evaluate_css(@document, 'root :nth-last-child(odd)') expect(evaluate_css(@document, 'root :nth-last-child(odd)'))
.should == node_set(@a2, @a4) .to eq(node_set(@a2, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root :nth-last-child(2n+2)'))
.should == node_set(@a1, @a3) .to eq(node_set(@a1, @a3))
end end
it 'returns a node set containing all nodes' do it 'returns a node set containing all nodes' do
evaluate_css(@document, 'root :nth-last-child(n)') expect(evaluate_css(@document, 'root :nth-last-child(n)'))
.should == @root.children .to eq(@root.children)
end end
it 'returns 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)') expect(evaluate_css(@document, 'root :nth-last-child(-n+2)'))
.should == node_set(@a3, @a4) .to eq(node_set(@a3, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root :nth-last-child(n+2)'))
.should == node_set(@a1, @a2, @a3) .to eq(node_set(@a1, @a2, @a3))
end end
end end
end end

View File

@ -22,38 +22,38 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-last-of-type(1)'))
.should == node_set(@a3, @a4) .to eq(node_set(@a3, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-last-of-type(even)'))
.should == node_set(@a2) .to eq(node_set(@a2))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-last-of-type(odd)'))
.should == node_set(@a1, @a3, @a4) .to eq(node_set(@a1, @a3, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-last-of-type(2n+2)'))
.should == node_set(@a2) .to eq(node_set(@a2))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-last-of-type(n)'))
.should == node_set(@a1, @a2, @a3, @a4) .to eq(node_set(@a1, @a2, @a3, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-last-of-type(-n+2)'))
.should == node_set(@a2, @a3, @a4) .to eq(node_set(@a2, @a3, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-last-of-type(n+2)'))
.should == node_set(@a1, @a2) .to eq(node_set(@a1, @a2))
end end
end end
end end

View File

@ -22,38 +22,38 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-of-type(1)'))
.should == node_set(@a1, @a4) .to eq(node_set(@a1, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-of-type(even)'))
.should == node_set(@a2) .to eq(node_set(@a2))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-of-type(odd)'))
.should == node_set(@a1, @a3, @a4) .to eq(node_set(@a1, @a3, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-of-type(2n+2)'))
.should == node_set(@a2) .to eq(node_set(@a2))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-of-type(n)'))
.should == node_set(@a1, @a2, @a3, @a4) .to eq(node_set(@a1, @a2, @a3, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-of-type(-n+2)'))
.should == node_set(@a1, @a2, @a4) .to eq(node_set(@a1, @a2, @a4))
end end
it 'returns 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)') expect(evaluate_css(@document, 'root a:nth-of-type(n+2)'))
.should == node_set(@a2, @a3) .to eq(node_set(@a2, @a3))
end end
end end
end end

View File

@ -11,11 +11,11 @@ describe 'CSS selector evaluation' do
end end
it 'returns a node set containing the first <a> node' do it 'returns a node set containing the first <a> node' do
evaluate_css(@document, 'root a:nth(1)').should == node_set(@a1) expect(evaluate_css(@document, 'root a:nth(1)')).to eq(node_set(@a1))
end end
it 'returns a node set containing the second <a> node' do it 'returns a node set containing the second <a> node' do
evaluate_css(@document, 'root a:nth(2)').should == node_set(@a2) expect(evaluate_css(@document, 'root a:nth(2)')).to eq(node_set(@a2))
end end
end end
end end

View File

@ -11,7 +11,7 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root :only-child')).to eq(node_set(@c1, @c2))
end end
end end
end end

View File

@ -11,7 +11,7 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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) expect(evaluate_css(@document, 'root a :only-of-type')).to eq(node_set(@c1))
end end
end end
end end

View File

@ -7,7 +7,7 @@ describe 'CSS selector evaluation' do
end end
it 'returns 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 expect(evaluate_css(@document, ':root')).to eq(@document.children)
end end
end end
end end

View File

@ -3,63 +3,63 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'axes' do describe 'axes' do
it 'lexes the > axis' do it 'lexes the > axis' do
lex_css('>').should == [[:T_GREATER, nil]] expect(lex_css('>')).to eq([[:T_GREATER, nil]])
end end
it 'lexes the expression "> y"' do it 'lexes the expression "> y"' do
lex_css('> y').should == [[:T_GREATER, nil], [:T_IDENT, 'y']] expect(lex_css('> y')).to eq([[:T_GREATER, nil], [:T_IDENT, 'y']])
end end
it 'lexes the expression "x > y"' do it 'lexes the expression "x > y"' do
lex_css('x > y').should == [ expect(lex_css('x > y')).to eq([
[:T_IDENT, 'x'], [:T_IDENT, 'x'],
[:T_GREATER, nil], [:T_GREATER, nil],
[:T_IDENT, 'y'] [:T_IDENT, 'y']
] ])
end end
it 'lexes the expression "x>y"' do it 'lexes the expression "x>y"' do
lex_css('x>y').should == lex_css('x > y') expect(lex_css('x>y')).to eq(lex_css('x > y'))
end end
it 'lexes the + axis' do it 'lexes the + axis' do
lex_css('+').should == [[:T_PLUS, nil]] expect(lex_css('+')).to eq([[:T_PLUS, nil]])
end end
it 'lexes the expression "+ y"' do it 'lexes the expression "+ y"' do
lex_css('+ y').should == [[:T_PLUS, nil], [:T_IDENT, 'y']] expect(lex_css('+ y')).to eq([[:T_PLUS, nil], [:T_IDENT, 'y']])
end end
it 'lexes the expression "x + y"' do it 'lexes the expression "x + y"' do
lex_css('x + y').should == [ expect(lex_css('x + y')).to eq([
[:T_IDENT, 'x'], [:T_IDENT, 'x'],
[:T_PLUS, nil], [:T_PLUS, nil],
[:T_IDENT, 'y'] [:T_IDENT, 'y']
] ])
end end
it 'lexes the expression "x+y"' do it 'lexes the expression "x+y"' do
lex_css('x+y').should == lex_css('x + y') expect(lex_css('x+y')).to eq(lex_css('x + y'))
end end
it 'lexes the ~ axis' do it 'lexes the ~ axis' do
lex_css('~').should == [[:T_TILDE, nil]] expect(lex_css('~')).to eq([[:T_TILDE, nil]])
end end
it 'lexes the expression "~ y"' do it 'lexes the expression "~ y"' do
lex_css('~ y').should == [[:T_TILDE, nil], [:T_IDENT, 'y']] expect(lex_css('~ y')).to eq([[:T_TILDE, nil], [:T_IDENT, 'y']])
end end
it 'lexes the expression "x ~ y"' do it 'lexes the expression "x ~ y"' do
lex_css('x ~ y').should == [ expect(lex_css('x ~ y')).to eq([
[:T_IDENT, 'x'], [:T_IDENT, 'x'],
[:T_TILDE, nil], [:T_TILDE, nil],
[:T_IDENT, 'y'] [:T_IDENT, 'y']
] ])
end end
it 'lexes the expression "x~y"' do it 'lexes the expression "x~y"' do
lex_css('x~y').should == lex_css('x ~ y') expect(lex_css('x~y')).to eq(lex_css('x ~ y'))
end end
end end
end end

View File

@ -3,19 +3,19 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'namespaces' do describe 'namespaces' do
it 'lexes a path containing a namespace name' do it 'lexes a path containing a namespace name' do
lex_css('foo|bar').should == [ expect(lex_css('foo|bar')).to eq([
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_PIPE, nil], [:T_PIPE, nil],
[:T_IDENT, 'bar'] [:T_IDENT, 'bar']
] ])
end end
it 'lexes a path containing a namespace wildcard' do it 'lexes a path containing a namespace wildcard' do
lex_css('*|foo').should == [ expect(lex_css('*|foo')).to eq([
[:T_IDENT, '*'], [:T_IDENT, '*'],
[:T_PIPE, nil], [:T_PIPE, nil],
[:T_IDENT, 'foo'] [:T_IDENT, 'foo']
] ])
end end
end end
end end

View File

@ -3,87 +3,87 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'operators' do describe 'operators' do
it 'lexes the = operator' do it 'lexes the = operator' do
lex_css('[foo="bar"]').should == [ expect(lex_css('[foo="bar"]')).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_EQ, nil], [:T_EQ, nil],
[:T_STRING, 'bar'], [:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
it 'lexes the ~= operator' do it 'lexes the ~= operator' do
lex_css('[foo~="bar"]').should == [ expect(lex_css('[foo~="bar"]')).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_SPACE_IN, nil], [:T_SPACE_IN, nil],
[:T_STRING, 'bar'], [:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
it 'lexes the ^= operator' do it 'lexes the ^= operator' do
lex_css('[foo^="bar"]').should == [ expect(lex_css('[foo^="bar"]')).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_STARTS_WITH, nil], [:T_STARTS_WITH, nil],
[:T_STRING, 'bar'], [:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
it 'lexes the $= operator' do it 'lexes the $= operator' do
lex_css('[foo$="bar"]').should == [ expect(lex_css('[foo$="bar"]')).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_ENDS_WITH, nil], [:T_ENDS_WITH, nil],
[:T_STRING, 'bar'], [:T_STRING, 'bar'],
[:T_RBRACK, nil], [:T_RBRACK, nil],
] ])
end end
it 'lexes the *= operator' do it 'lexes the *= operator' do
lex_css('[foo*="bar"]').should == [ expect(lex_css('[foo*="bar"]')).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_IN, nil], [:T_IN, nil],
[:T_STRING, 'bar'], [:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
it 'lexes the |= operator' do it 'lexes the |= operator' do
lex_css('[foo|="bar"]').should == [ expect(lex_css('[foo|="bar"]')).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_HYPHEN_IN, nil], [:T_HYPHEN_IN, nil],
[:T_STRING, 'bar'], [:T_STRING, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
it 'lexes the = operator surrounded by whitespace' do it 'lexes the = operator surrounded by whitespace' do
lex_css('[foo = "bar"]').should == lex_css('[foo="bar"]') expect(lex_css('[foo = "bar"]')).to eq(lex_css('[foo="bar"]'))
end end
it 'lexes the ~= operator surrounded by whitespace' do it 'lexes the ~= operator surrounded by whitespace' do
lex_css('[foo ~= "bar"]').should == lex_css('[foo~="bar"]') expect(lex_css('[foo ~= "bar"]')).to eq(lex_css('[foo~="bar"]'))
end end
it 'lexes the ^= operator surrounded by whitespace' do it 'lexes the ^= operator surrounded by whitespace' do
lex_css('[foo ^= "bar"]').should == lex_css('[foo^="bar"]') expect(lex_css('[foo ^= "bar"]')).to eq(lex_css('[foo^="bar"]'))
end end
it 'lexes the $= operator surrounded by whitespace' do it 'lexes the $= operator surrounded by whitespace' do
lex_css('[foo $= "bar"]').should == lex_css('[foo$="bar"]') expect(lex_css('[foo $= "bar"]')).to eq(lex_css('[foo$="bar"]'))
end end
it 'lexes the *= operator surrounded by whitespace' do it 'lexes the *= operator surrounded by whitespace' do
lex_css('[foo *= "bar"]').should == lex_css('[foo*="bar"]') expect(lex_css('[foo *= "bar"]')).to eq(lex_css('[foo*="bar"]'))
end end
it 'lexes the |= operator surrounded by whitespace' do it 'lexes the |= operator surrounded by whitespace' do
lex_css('[foo |= "bar"]').should == lex_css('[foo|="bar"]') expect(lex_css('[foo |= "bar"]')).to eq(lex_css('[foo|="bar"]'))
end end
end end
end end

View File

@ -5,73 +5,73 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'paths' do describe 'paths' do
it 'lexes a simple path' do it 'lexes a simple path' do
lex_css('h3').should == [[:T_IDENT, 'h3']] expect(lex_css('h3')).to eq([[:T_IDENT, 'h3']])
end end
it 'lexes a path with Unicode characters' do it 'lexes a path with Unicode characters' do
lex_css('áâã').should == [[:T_IDENT, 'áâã']] expect(lex_css('áâã')).to eq([[:T_IDENT, 'áâã']])
end end
it 'lexes a path with Unicode and ASCII characters' do it 'lexes a path with Unicode and ASCII characters' do
lex_css('áâãfoo').should == [[:T_IDENT, 'áâãfoo']] expect(lex_css('áâãfoo')).to eq([[:T_IDENT, 'áâãfoo']])
end end
it 'lexes 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']] expect(lex_css('_h3')).to eq([[:T_IDENT, '_h3']])
end end
it 'lexes a path with an escaped identifier' do it 'lexes a path with an escaped identifier' do
lex_css('foo\.bar\.baz').should == [[:T_IDENT, 'foo.bar.baz']] expect(lex_css('foo\.bar\.baz')).to eq([[:T_IDENT, 'foo.bar.baz']])
end end
it 'lexes a path with an escaped identifier followed by another identifier' do it 'lexes a path with an escaped identifier followed by another identifier' do
lex_css('foo\.bar baz').should == [ expect(lex_css('foo\.bar baz')).to eq([
[:T_IDENT, 'foo.bar'], [:T_IDENT, 'foo.bar'],
[:T_SPACE, nil], [:T_SPACE, nil],
[:T_IDENT, 'baz'] [:T_IDENT, 'baz']
] ])
end end
it 'lexes a path with two members' do it 'lexes a path with two members' do
lex_css('div h3').should == [ expect(lex_css('div h3')).to eq([
[:T_IDENT, 'div'], [:T_IDENT, 'div'],
[:T_SPACE, nil], [:T_SPACE, nil],
[:T_IDENT, 'h3'] [:T_IDENT, 'h3']
] ])
end end
it 'lexes 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 == [ expect(lex_css('div h3')).to eq([
[:T_IDENT, 'div'], [:T_IDENT, 'div'],
[:T_SPACE, nil], [:T_SPACE, nil],
[:T_IDENT, 'h3'] [:T_IDENT, 'h3']
] ])
end end
it 'lexes two paths' do it 'lexes two paths' do
lex_css('foo, bar').should == [ expect(lex_css('foo, bar')).to eq([
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_COMMA, nil], [:T_COMMA, nil],
[:T_IDENT, 'bar'] [:T_IDENT, 'bar']
] ])
end end
it 'lexes a path selecting an ID' do it 'lexes a path selecting an ID' do
lex_css('#foo').should == [ expect(lex_css('#foo')).to eq([
[:T_HASH, nil], [:T_HASH, nil],
[:T_IDENT, 'foo'] [:T_IDENT, 'foo']
] ])
end end
it 'lexes a path selecting a class' do it 'lexes a path selecting a class' do
lex_css('.foo').should == [ expect(lex_css('.foo')).to eq([
[:T_DOT, nil], [:T_DOT, nil],
[:T_IDENT, 'foo'] [:T_IDENT, 'foo']
] ])
end end
it 'lexes a wildcard path' do it 'lexes a wildcard path' do
lex_css('*').should == [[:T_IDENT, '*']] expect(lex_css('*')).to eq([[:T_IDENT, '*']])
end end
end end
end end

View File

@ -3,12 +3,12 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'predicates' do describe 'predicates' do
it 'lexes a path containing a simple predicate' do it 'lexes a path containing a simple predicate' do
lex_css('foo[bar]').should == [ expect(lex_css('foo[bar]')).to eq([
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_IDENT, 'bar'], [:T_IDENT, 'bar'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
end end
end end

View File

@ -3,86 +3,86 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'pseudo classes' do describe 'pseudo classes' do
it 'lexes the :root pseudo class' do it 'lexes the :root pseudo class' do
lex_css(':root').should == [ expect(lex_css(':root')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'root'] [:T_IDENT, 'root']
] ])
end end
it 'lexes the :nth-child pseudo class' do it 'lexes the :nth-child pseudo class' do
lex_css(':nth-child(1)').should == [ expect(lex_css(':nth-child(1)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_INT, 1], [:T_INT, 1],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes 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 == [ expect(lex_css(':nth-child( 1)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_INT, 1], [:T_INT, 1],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes the :nth-child(odd) pseudo class' do it 'lexes the :nth-child(odd) pseudo class' do
lex_css(':nth-child(odd)').should == [ expect(lex_css(':nth-child(odd)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_ODD, nil], [:T_ODD, nil],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes the :nth-child(even) pseudo class' do it 'lexes the :nth-child(even) pseudo class' do
lex_css(':nth-child(even)').should == [ expect(lex_css(':nth-child(even)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_EVEN, nil], [:T_EVEN, nil],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes the :nth-child(n) pseudo class' do it 'lexes the :nth-child(n) pseudo class' do
lex_css(':nth-child(n)').should == [ expect(lex_css(':nth-child(n)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_NTH, nil], [:T_NTH, nil],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes the :nth-child(-n) pseudo class' do it 'lexes the :nth-child(-n) pseudo class' do
lex_css(':nth-child(-n)').should == [ expect(lex_css(':nth-child(-n)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_MINUS, nil], [:T_MINUS, nil],
[:T_NTH, nil], [:T_NTH, nil],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes the :nth-child(2n) pseudo class' do it 'lexes the :nth-child(2n) pseudo class' do
lex_css(':nth-child(2n)').should == [ expect(lex_css(':nth-child(2n)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_INT, 2], [:T_INT, 2],
[:T_NTH, nil], [:T_NTH, nil],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes 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 == [ expect(lex_css(':nth-child(2n+1)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
@ -90,11 +90,11 @@ describe Oga::CSS::Lexer do
[:T_NTH, nil], [:T_NTH, nil],
[:T_INT, 1], [:T_INT, 1],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes 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 == [ expect(lex_css(':nth-child(2n-1)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
@ -102,11 +102,11 @@ describe Oga::CSS::Lexer do
[:T_NTH, nil], [:T_NTH, nil],
[:T_INT, -1], [:T_INT, -1],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes 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 == [ expect(lex_css(':nth-child(-2n-1)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'nth-child'], [:T_IDENT, 'nth-child'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
@ -114,28 +114,28 @@ describe Oga::CSS::Lexer do
[:T_NTH, nil], [:T_NTH, nil],
[:T_INT, -1], [:T_INT, -1],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes the :lang(fr) pseudo class' do it 'lexes the :lang(fr) pseudo class' do
lex_css(':lang(fr)').should == [ expect(lex_css(':lang(fr)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'lang'], [:T_IDENT, 'lang'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_IDENT, 'fr'], [:T_IDENT, 'fr'],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
it 'lexes the :not(#foo) pseudo class' do it 'lexes the :not(#foo) pseudo class' do
lex_css(':not(#foo)').should == [ expect(lex_css(':not(#foo)')).to eq([
[:T_COLON, nil], [:T_COLON, nil],
[:T_IDENT, 'not'], [:T_IDENT, 'not'],
[:T_LPAREN, nil], [:T_LPAREN, nil],
[:T_HASH, nil], [:T_HASH, nil],
[:T_IDENT, 'foo'], [:T_IDENT, 'foo'],
[:T_RPAREN, nil] [:T_RPAREN, nil]
] ])
end end
end end
end end

View File

@ -3,19 +3,19 @@ require 'spec_helper'
describe Oga::CSS::Lexer do describe Oga::CSS::Lexer do
describe 'strings' do describe 'strings' do
it 'lexes a single quoted string' do it 'lexes a single quoted string' do
lex_css("['foo']").should == [ expect(lex_css("['foo']")).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_STRING, 'foo'], [:T_STRING, 'foo'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
it 'lexes a double quoted string' do it 'lexes a double quoted string' do
lex_css('["foo"]').should == [ expect(lex_css('["foo"]')).to eq([
[:T_LBRACK, nil], [:T_LBRACK, nil],
[:T_STRING, 'foo'], [:T_STRING, 'foo'],
[:T_RBRACK, nil] [:T_RBRACK, nil]
] ])
end end
end end
end end

View File

@ -3,72 +3,72 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe 'axes' do describe 'axes' do
it 'parses the > axis' do it 'parses the > axis' do
parse_css('x > y').should == parse_xpath('descendant::x/y') expect(parse_css('x > y')).to eq(parse_xpath('descendant::x/y'))
end end
it 'parses the > axis without whitespace' do it 'parses the > axis without whitespace' do
parse_css('x>y').should == parse_css('x > y') expect(parse_css('x>y')).to eq(parse_css('x > y'))
end end
it 'parses 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') expect(parse_css('a > b > c')).to eq(parse_xpath('descendant::a/b/c'))
end end
it 'parses 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( expect(parse_css('x > foo#bar')).to eq(parse_xpath(
'descendant::x/foo[@id="bar"]' 'descendant::x/foo[@id="bar"]'
) ))
end end
it 'parses 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( expect(parse_css('x > foo.bar')).to eq(parse_xpath(
'descendant::x/foo[contains(concat(" ", @class, " "), " bar ")]' 'descendant::x/foo[contains(concat(" ", @class, " "), " bar ")]'
) ))
end end
it 'parses the + axis' do it 'parses the + axis' do
parse_css('x + y').should == parse_xpath( expect(parse_css('x + y')).to eq(parse_xpath(
'descendant::x/following-sibling::*[1]/self::y' 'descendant::x/following-sibling::*[1]/self::y'
) ))
end end
it 'parses the + axis without whitespace' do it 'parses the + axis without whitespace' do
parse_css('x+y').should == parse_css('x + y') expect(parse_css('x+y')).to eq(parse_css('x + y'))
end end
it 'parses the + axis with an identifier only at the right-hand side' do it 'parses the + axis with an identifier only at the right-hand side' do
parse_css('+ y').should == parse_xpath( expect(parse_css('+ y')).to eq(parse_xpath(
'following-sibling::*[1]/self::y' 'following-sibling::*[1]/self::y'
) ))
end end
it 'parses the + axis called on another + axis' do it 'parses the + axis called on another + axis' do
parse_css('a + b + c').should == parse_xpath( expect(parse_css('a + b + c')).to eq(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
it 'parses the ~ axis' do it 'parses the ~ axis' do
parse_css('x ~ y').should == parse_xpath( expect(parse_css('x ~ y')).to eq(parse_xpath(
'descendant::x/following-sibling::y' 'descendant::x/following-sibling::y'
) ))
end end
it 'parses the ~ axis without whitespace' do it 'parses the ~ axis without whitespace' do
parse_css('x~y').should == parse_css('x ~ y') expect(parse_css('x~y')).to eq(parse_css('x ~ y'))
end end
it 'parses 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( expect(parse_css('x ~ y z')).to eq(parse_xpath(
'descendant::x/following-sibling::y/descendant::z' 'descendant::x/following-sibling::y/descendant::z'
) ))
end end
it 'parses the ~ axis called on another ~ axis' do it 'parses the ~ axis called on another ~ axis' do
parse_css('a ~ b ~ c').should == parse_xpath( expect(parse_css('a ~ b ~ c')).to eq(parse_xpath(
'descendant::a/following-sibling::b/following-sibling::c' 'descendant::a/following-sibling::b/following-sibling::c'
) ))
end end
end end
end end

View File

@ -7,21 +7,21 @@ describe Oga::CSS::Parser do
end end
it 'parses an expression' do it 'parses an expression' do
described_class.parse_with_cache('foo') expect(described_class.parse_with_cache('foo'))
.should == s(:axis, 'descendant', s(:test, nil, 'foo')) .to eq(s(:axis, 'descendant', s(:test, nil, 'foo')))
end end
it 'caches an expression after parsing it' do it 'caches an expression after parsing it' do
described_class.any_instance expect_any_instance_of(described_class)
.should_receive(:parse) .to receive(:parse)
.once .once
.and_call_original .and_call_original
described_class.parse_with_cache('foo') expect(described_class.parse_with_cache('foo'))
.should == s(:axis, 'descendant', s(:test, nil, 'foo')) .to eq(s(:axis, 'descendant', s(:test, nil, 'foo')))
described_class.parse_with_cache('foo') expect(described_class.parse_with_cache('foo'))
.should == s(:axis, 'descendant', s(:test, nil, 'foo')) .to eq(s(:axis, 'descendant', s(:test, nil, 'foo')))
end end
end end
end end

View File

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

View File

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

View File

@ -3,39 +3,39 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe 'operators' do describe 'operators' do
it 'parses the = operator' do it 'parses the = operator' do
parse_css('x[a="b"]').should == parse_xpath('descendant::x[@a="b"]') expect(parse_css('x[a="b"]')).to eq(parse_xpath('descendant::x[@a="b"]'))
end end
it 'parses the ~= operator' do it 'parses the ~= operator' do
parse_css('x[a~="b"]').should == parse_xpath( expect(parse_css('x[a~="b"]')).to eq(parse_xpath(
'descendant::x[contains(concat(" ", @a, " "), ' \ 'descendant::x[contains(concat(" ", @a, " "), ' \
'concat(" ", "b", " "))]' 'concat(" ", "b", " "))]'
) ))
end end
it 'parses the ^= operator' do it 'parses the ^= operator' do
parse_css('x[a^="b"]').should == parse_xpath( expect(parse_css('x[a^="b"]')).to eq(parse_xpath(
'descendant::x[starts-with(@a, "b")]' 'descendant::x[starts-with(@a, "b")]'
) ))
end end
it 'parses the $= operator' do it 'parses the $= operator' do
parse_css('x[a$="b"]').should == parse_xpath( expect(parse_css('x[a$="b"]')).to eq(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
it 'parses the *= operator' do it 'parses the *= operator' do
parse_css('x[a*="b"]').should == parse_xpath( expect(parse_css('x[a*="b"]')).to eq(parse_xpath(
'descendant::x[contains(@a, "b")]' 'descendant::x[contains(@a, "b")]'
) ))
end end
it 'parses the |= operator' do it 'parses the |= operator' do
parse_css('x[a|="b"]').should == parse_xpath( expect(parse_css('x[a|="b"]')).to eq(parse_xpath(
'descendant::x[@a = "b" or starts-with(@a, concat("b", "-"))]' 'descendant::x[@a = "b" or starts-with(@a, concat("b", "-"))]'
) ))
end end
end end
end end

View File

@ -3,26 +3,29 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe 'paths' do describe 'paths' do
it 'parses a single path' do it 'parses a single path' do
parse_css('foo').should == parse_xpath('descendant::foo') expect(parse_css('foo')).to eq(parse_xpath('descendant::foo'))
end end
it 'parses a path using a namespace' do it 'parses a path using a namespace' do
parse_css('ns|foo').should == parse_xpath('descendant::ns:foo') expect(parse_css('ns|foo')).to eq(parse_xpath('descendant::ns:foo'))
end end
it 'parses a path using two selectors' do it 'parses a path using two selectors' do
parse_css('foo bar').should == expect(parse_css('foo bar')).to eq(
parse_xpath('descendant::foo/descendant::bar') parse_xpath('descendant::foo/descendant::bar')
)
end end
it 'parses two paths separated by a comma' do it 'parses two paths separated by a comma' do
parse_css('foo, bar').should == expect(parse_css('foo, bar')).to eq(
parse_xpath('descendant::foo | descendant::bar') parse_xpath('descendant::foo | descendant::bar')
)
end end
it 'parses three paths separated by a comma' do it 'parses three paths separated by a comma' do
parse_css('foo, bar, baz').should == expect(parse_css('foo, bar, baz')).to eq(
parse_xpath('descendant::foo | descendant::bar | descendant::baz') parse_xpath('descendant::foo | descendant::bar | descendant::baz')
)
end end
end end
end end

View File

@ -3,19 +3,19 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe 'predicates' do describe 'predicates' do
it 'parses a predicate' do it 'parses a predicate' do
parse_css('foo[bar]').should == parse_xpath('descendant::foo[@bar]') expect(parse_css('foo[bar]')).to eq(parse_xpath('descendant::foo[@bar]'))
end end
it 'parses 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( expect(parse_css('foo bar[baz]')).to eq(parse_xpath(
'descendant::foo/descendant::bar[@baz]' 'descendant::foo/descendant::bar[@baz]'
) ))
end end
it 'parses a predicate testing an attribute value' do it 'parses a predicate testing an attribute value' do
parse_css('foo[bar="baz"]').should == parse_xpath( expect(parse_css('foo[bar="baz"]')).to eq(parse_xpath(
'descendant::foo[@bar="baz"]' 'descendant::foo[@bar="baz"]'
) ))
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':empty pseudo class' do describe ':empty pseudo class' do
it 'parses the :empty pseudo class' do it 'parses the :empty pseudo class' do
parse_css(':empty').should == parse_xpath('descendant::*[not(node())]') expect(parse_css(':empty')).to eq(parse_xpath('descendant::*[not(node())]'))
end end
end end
end end

View File

@ -3,9 +3,9 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':first-child pseudo class' do describe ':first-child pseudo class' do
it 'parses the :first-child pseudo class' do it 'parses the :first-child pseudo class' do
parse_css(':first-child').should == parse_xpath( expect(parse_css(':first-child')).to eq(parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0]' 'descendant::*[count(preceding-sibling::*) = 0]'
) ))
end end
end end
end end

View File

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

View File

@ -3,9 +3,9 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':last-child pseudo class' do describe ':last-child pseudo class' do
it 'parses the :last-child pseudo class' do it 'parses the :last-child pseudo class' do
parse_css(':last-child').should == parse_xpath( expect(parse_css(':last-child')).to eq(parse_xpath(
'descendant::*[count(following-sibling::*) = 0]' 'descendant::*[count(following-sibling::*) = 0]'
) ))
end end
end end
end end

View File

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

View File

@ -3,16 +3,17 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':not pseudo class' do describe ':not pseudo class' do
it 'parses the :not(x) pseudo class' do it 'parses the :not(x) pseudo class' do
parse_css(':not(x)').should == parse_xpath('descendant::*[not(self::x)]') expect(parse_css(':not(x)')).to eq(parse_xpath('descendant::*[not(self::x)]'))
end end
it 'parses the x:not(y) pseudo class' do it 'parses the x:not(y) pseudo class' do
parse_css('x:not(y)').should == parse_xpath('descendant::x[not(self::y)]') expect(parse_css('x:not(y)')).to eq(parse_xpath('descendant::x[not(self::y)]'))
end end
it 'parses the x:not(#foo) pseudo class' do it 'parses the x:not(#foo) pseudo class' do
parse_css('x:not(#foo)').should == expect(parse_css('x:not(#foo)')).to eq(
parse_xpath('descendant::x[not(@id="foo")]') parse_xpath('descendant::x[not(@id="foo")]')
)
end end
end end
end end

View File

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

View File

@ -3,87 +3,87 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':nth-last-child pseudo class' do describe ':nth-last-child pseudo class' do
it 'parses 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( expect(parse_css('x:nth-last-child(1)')).to eq(parse_xpath(
'descendant::x[count(following-sibling::*) = 0]' 'descendant::x[count(following-sibling::*) = 0]'
) ))
end end
it 'parses 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( expect(parse_css(':nth-last-child(1)')).to eq(parse_xpath(
'descendant::*[count(following-sibling::*) = 0]' 'descendant::*[count(following-sibling::*) = 0]'
) ))
end end
it 'parses 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( expect(parse_css(':nth-last-child(2)')).to eq(parse_xpath(
'descendant::*[count(following-sibling::*) = 1]' 'descendant::*[count(following-sibling::*) = 1]'
) ))
end end
it 'parses 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( expect(parse_css('x:nth-last-child(even)')).to eq(parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) mod 2) = 0]' 'descendant::x[((count(following-sibling::*) + 1) mod 2) = 0]'
) ))
end end
it 'parses 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( expect(parse_css('x:nth-last-child(odd)')).to eq(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
it 'parses 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( expect(parse_css('x:nth-last-child(n)')).to eq(parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) mod 1) = 0]' 'descendant::x[((count(following-sibling::*) + 1) mod 1) = 0]'
) ))
end end
it 'parses 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( expect(parse_css('x:nth-last-child(-n)')).to eq(parse_xpath(
'descendant::x[((count(following-sibling::*) + 1) mod 1) = 0]' 'descendant::x[((count(following-sibling::*) + 1) mod 1) = 0]'
) ))
end end
it 'parses 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( expect(parse_css('x:nth-last-child(-n+6)')).to eq(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
it 'parses 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( expect(parse_css('x:nth-last-child(2n)')).to eq(parse_css(
'x:nth-last-child(even)' 'x:nth-last-child(even)'
) ))
end end
it 'parses 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( expect(parse_css('x:nth-last-child(2n+1)')).to eq(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
it 'parses 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( expect(parse_css('x:nth-last-child(2n-6)')).to eq(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
it 'parses 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( expect(parse_css('x:nth-last-child(-2n-6)')).to eq(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
it 'parses 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( expect(parse_css('x:nth-last-child(-2n+6)')).to eq(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]'
) ))
end end
end end
end end

View File

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

View File

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

View File

@ -3,13 +3,13 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':nth pseudo class' do describe ':nth pseudo class' do
it 'parses the :nth(1) pseudo class' do it 'parses the :nth(1) pseudo class' do
parse_css(':nth(1)') expect(parse_css(':nth(1)'))
.should == parse_xpath('descendant::*[position() = 1]') .to eq(parse_xpath('descendant::*[position() = 1]'))
end end
it 'parses the :nth(2) pseudo class' do it 'parses the :nth(2) pseudo class' do
parse_css(':nth(2)') expect(parse_css(':nth(2)'))
.should == parse_xpath('descendant::*[position() = 2]') .to eq(parse_xpath('descendant::*[position() = 2]'))
end end
end end
end end

View File

@ -3,10 +3,10 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':only-child pseudo class' do describe ':only-child pseudo class' do
it 'parses the :only-child pseudo class' do it 'parses the :only-child pseudo class' do
parse_css(':only-child').should == parse_xpath( expect(parse_css(':only-child')).to eq(parse_xpath(
'descendant::*[count(preceding-sibling::*) = 0 ' \ 'descendant::*[count(preceding-sibling::*) = 0 ' \
'and count(following-sibling::*) = 0]' 'and count(following-sibling::*) = 0]'
) ))
end end
end end
end end

View File

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

View File

@ -3,11 +3,11 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe ':root pseudo class' do describe ':root pseudo class' do
it 'parses 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::*)]') expect(parse_css('x:root')).to eq(parse_xpath('descendant::x[not(parent::*)]'))
end end
it 'parses the :root pseudo class' do it 'parses the :root pseudo class' do
parse_css(':root').should == parse_xpath('descendant::*[not(parent::*)]') expect(parse_css(':root')).to eq(parse_xpath('descendant::*[not(parent::*)]'))
end end
end end
end end

View File

@ -3,15 +3,15 @@ require 'spec_helper'
describe Oga::CSS::Parser do describe Oga::CSS::Parser do
describe 'wildcards' do describe 'wildcards' do
it 'parses a wildcard name test' do it 'parses a wildcard name test' do
parse_css('*').should == parse_xpath('descendant::*') expect(parse_css('*')).to eq(parse_xpath('descendant::*'))
end end
it 'parses a wildcard namespace test' do it 'parses a wildcard namespace test' do
parse_css('*|foo').should == parse_xpath('descendant::*:foo') expect(parse_css('*|foo')).to eq(parse_xpath('descendant::*:foo'))
end end
it 'parses a wildcard namespace and name test' do it 'parses a wildcard namespace and name test' do
parse_css('*|*').should == parse_xpath('descendant::*:*') expect(parse_css('*|*')).to eq(parse_xpath('descendant::*:*'))
end end
end end
end end

View File

@ -3,29 +3,29 @@ require 'spec_helper'
describe Oga::EntityDecoder do describe Oga::EntityDecoder do
describe 'try_decode' do describe 'try_decode' do
it 'returns nil if the input is also nil' do it 'returns nil if the input is also nil' do
described_class.try_decode(nil).should be_nil expect(described_class.try_decode(nil)).to be_nil
end end
it 'decodes XML entities' do it 'decodes XML entities' do
described_class.try_decode('&lt;') expect(described_class.try_decode('&lt;'))
.should == Oga::XML::Entities::DECODE_MAPPING['&lt;'] .to eq(Oga::XML::Entities::DECODE_MAPPING['&lt;'])
end end
it 'decodes HTML entities' do it 'decodes HTML entities' do
described_class.try_decode('&copy;', true) expect(described_class.try_decode('&copy;', true))
.should == Oga::HTML::Entities::DECODE_MAPPING['&copy;'] .to eq(Oga::HTML::Entities::DECODE_MAPPING['&copy;'])
end end
end end
describe 'decode' do describe 'decode' do
it 'decodes XML entities' do it 'decodes XML entities' do
described_class.decode('&lt;') expect(described_class.decode('&lt;'))
.should == Oga::XML::Entities::DECODE_MAPPING['&lt;'] .to eq(Oga::XML::Entities::DECODE_MAPPING['&lt;'])
end end
it 'decodes HTML entities' do it 'decodes HTML entities' do
described_class.decode('&copy;', true) expect(described_class.decode('&copy;', true))
.should == Oga::HTML::Entities::DECODE_MAPPING['&copy;'] .to eq(Oga::HTML::Entities::DECODE_MAPPING['&copy;'])
end end
end end
end end

View File

@ -5,15 +5,15 @@ require 'spec_helper'
describe Oga::HTML::Entities do describe Oga::HTML::Entities do
describe 'decode' do describe 'decode' do
it 'decodes &amp; into &' do it 'decodes &amp; into &' do
described_class.decode('&amp;').should == '&' expect(described_class.decode('&amp;')).to eq('&')
end end
it 'decodes &lambda; into λ' do it 'decodes &lambda; into λ' do
described_class.decode('&lambda;').should == 'λ' expect(described_class.decode('&lambda;')).to eq('λ')
end end
it 'decodes &frac12; into ½' do it 'decodes &frac12; into ½' do
described_class.decode('&frac12;').should == '½' expect(described_class.decode('&frac12;')).to eq('½')
end end
end end
end end

View File

@ -3,18 +3,18 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'HTML attributes' do describe 'HTML attributes' do
it 'lexes an attribute with an unquoted value' do it 'lexes an attribute with an unquoted value' do
lex_html('<a href=foo></a>').should == [ expect(lex_html('<a href=foo></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'foo', 1], [:T_STRING_BODY, 'foo', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with an unquoted value containing a space' do it 'lexes an attribute with an unquoted value containing a space' do
lex_html('<a href=foo bar></a>').should == [ expect(lex_html('<a href=foo bar></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
@ -22,55 +22,55 @@ describe Oga::XML::Lexer do
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ATTR, 'bar', 1], [:T_ATTR, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with an unquoted value containing an underscore' do it 'lexes an attribute with an unquoted value containing an underscore' do
lex_html('<a href=foo_bar></a>').should == [ expect(lex_html('<a href=foo_bar></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'foo_bar', 1], [:T_STRING_BODY, 'foo_bar', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with an unquoted value containing a dash' do it 'lexes an attribute with an unquoted value containing a dash' do
lex_html('<a href=foo-bar></a>').should == [ expect(lex_html('<a href=foo-bar></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'foo-bar', 1], [:T_STRING_BODY, 'foo-bar', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with an unquoted value containing a slash' do it 'lexes an attribute with an unquoted value containing a slash' do
lex_html('<a href=foo/></a>').should == [ expect(lex_html('<a href=foo/></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'foo/', 1], [:T_STRING_BODY, 'foo/', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with an unquoted chunk of Javascript' do it 'lexes an attribute with an unquoted chunk of Javascript' do
lex_html('<a href=ijustlovehtml("because","reasons")').should == [ expect(lex_html('<a href=ijustlovehtml("because","reasons")')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'ijustlovehtml("because","reasons")', 1], [:T_STRING_BODY, 'ijustlovehtml("because","reasons")', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with an unquoted chunk of Javascript followed by another attribute' do it 'lexes an attribute with an unquoted chunk of Javascript followed by another attribute' do
lex_html('<a href=ijustlovehtml("because","reasons") foo="bar"').should == [ expect(lex_html('<a href=ijustlovehtml("because","reasons") foo="bar"')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
@ -81,73 +81,73 @@ describe Oga::XML::Lexer do
[:T_STRING_BODY, 'bar', 1], [:T_STRING_BODY, 'bar', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with a value without a starting double quote' do it 'lexes an attribute with a value without a starting double quote' do
lex_html('<a href=foo"></a>').should == [ expect(lex_html('<a href=foo"></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'foo"', 1], [:T_STRING_BODY, 'foo"', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an attribute with a value without a starting single quote' do it 'lexes an attribute with a value without a starting single quote' do
lex_html("<a href=foo'></a>").should == [ expect(lex_html("<a href=foo'></a>")).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_ATTR, 'href', 1], [:T_ATTR, 'href', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, "foo'", 1], [:T_STRING_BODY, "foo'", 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an element with spaces around the attribute equal sign' do it 'lexes an element with spaces around the attribute equal sign' do
lex_html('<p foo = "bar"></p>').should == [ expect(lex_html('<p foo = "bar"></p>')).to eq([
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1], [:T_ATTR, 'foo', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_STRING_BODY, 'bar', 1], [:T_STRING_BODY, 'bar', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an element with a newline following the equals sign' do it 'lexes an element with a newline following the equals sign' do
lex_html(%Q{<p foo =\n"bar"></p>}).should == [ expect(lex_html(%Q{<p foo =\n"bar"></p>})).to eq([
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1], [:T_ATTR, 'foo', 1],
[:T_STRING_DQUOTE, nil, 2], [:T_STRING_DQUOTE, nil, 2],
[:T_STRING_BODY, 'bar', 2], [:T_STRING_BODY, 'bar', 2],
[:T_STRING_DQUOTE, nil, 2], [:T_STRING_DQUOTE, nil, 2],
[:T_ELEM_END, nil, 2] [:T_ELEM_END, nil, 2]
] ])
end end
it 'lexes an element with a newline following the equals sign using an IO as input' do it 'lexes an element with a newline following the equals sign using an IO as input' do
lex_stringio(%Q{<p foo =\n"bar"></p>}, :html => true).should == [ expect(lex_stringio(%Q{<p foo =\n"bar"></p>}, :html => true)).to eq([
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_ATTR, 'foo', 1], [:T_ATTR, 'foo', 1],
[:T_STRING_DQUOTE, nil, 2], [:T_STRING_DQUOTE, nil, 2],
[:T_STRING_BODY, 'bar', 2], [:T_STRING_BODY, 'bar', 2],
[:T_STRING_DQUOTE, nil, 2], [:T_STRING_DQUOTE, nil, 2],
[:T_ELEM_END, nil, 2] [:T_ELEM_END, nil, 2]
] ])
end end
it 'lexes an element containing a namespaced attribute' do it 'lexes an element containing a namespaced attribute' do
lex_html('<foo bar:baz="10" />').should == [ expect(lex_html('<foo bar:baz="10" />')).to eq([
[:T_ELEM_NAME, 'foo', 1], [:T_ELEM_NAME, 'foo', 1],
[:T_ATTR, 'bar:baz', 1], [:T_ATTR, 'bar:baz', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_STRING_BODY, '10', 1], [:T_STRING_BODY, '10', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,22 +3,22 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'closing HTML elements with mismatched closing tags' do describe 'closing HTML elements with mismatched closing tags' do
it 'lexes a <p> element closed using a </div> element' do it 'lexes a <p> element closed using a </div> element' do
lex_html('<p>foo</div>').should == [ expect(lex_html('<p>foo</div>')).to eq([
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <param> element' do it 'lexes a <param> element' do
lex_html('<object><param></param><param></param></object>').should == [ expect(lex_html('<object><param></param><param></param></object>')).to eq([
[:T_ELEM_NAME, 'object', 1], [:T_ELEM_NAME, 'object', 1],
[:T_ELEM_NAME, 'param', 1], [:T_ELEM_NAME, 'param', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'param', 1], [:T_ELEM_NAME, 'param', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,35 +3,35 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <body> elements' do describe 'using HTML <body> elements' do
it 'lexes an unclosed <body> followed by a <head> as separate elements' do it 'lexes an unclosed <body> followed by a <head> as separate elements' do
lex_html('<body>foo<head>bar').should == [ expect(lex_html('<body>foo<head>bar')).to eq([
[:T_ELEM_NAME, 'body', 1], [:T_ELEM_NAME, 'body', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'head', 1], [:T_ELEM_NAME, 'head', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <body> followed by a <body> as separate elements' do it 'lexes an unclosed <body> followed by a <body> as separate elements' do
lex_html('<body>foo<body>bar').should == [ expect(lex_html('<body>foo<body>bar')).to eq([
[:T_ELEM_NAME, 'body', 1], [:T_ELEM_NAME, 'body', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'body', 1], [:T_ELEM_NAME, 'body', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <p> following an unclosed <body> as a child element' do it 'lexes a <p> following an unclosed <body> as a child element' do
lex_html('<body><p>foo</body>').should == [ expect(lex_html('<body><p>foo</body>')).to eq([
[:T_ELEM_NAME, 'body', 1], [:T_ELEM_NAME, 'body', 1],
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,79 +3,79 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <caption> elements' do describe 'using HTML <caption> elements' do
it 'lexes an unclosed <caption> followed by a <thead> as separate elements' do it 'lexes an unclosed <caption> followed by a <thead> as separate elements' do
lex_html('<caption>foo<thead>bar').should == [ expect(lex_html('<caption>foo<thead>bar')).to eq([
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <caption> followed by a <tbody> as separate elements' do it 'lexes an unclosed <caption> followed by a <tbody> as separate elements' do
lex_html('<caption>foo<tbody>bar').should == [ expect(lex_html('<caption>foo<tbody>bar')).to eq([
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <caption> followed by a <tfoot> as separate elements' do it 'lexes an unclosed <caption> followed by a <tfoot> as separate elements' do
lex_html('<caption>foo<tfoot>bar').should == [ expect(lex_html('<caption>foo<tfoot>bar')).to eq([
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <caption> followed by a <tr> as separate elements' do it 'lexes an unclosed <caption> followed by a <tr> as separate elements' do
lex_html('<caption>foo<tr>bar').should == [ expect(lex_html('<caption>foo<tr>bar')).to eq([
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <caption> followed by a <caption> as separate elements' do it 'lexes an unclosed <caption> followed by a <caption> as separate elements' do
lex_html('<caption>foo<caption>bar').should == [ expect(lex_html('<caption>foo<caption>bar')).to eq([
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <caption> followed by a <colgroup> as separate elements' do it 'lexes an unclosed <caption> followed by a <colgroup> as separate elements' do
lex_html('<caption>foo<colgroup>bar').should == [ expect(lex_html('<caption>foo<colgroup>bar')).to eq([
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'colgroup', 1], [:T_ELEM_NAME, 'colgroup', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <caption> followed by a <col> as separate elements' do it 'lexes an unclosed <caption> followed by a <col> as separate elements' do
lex_html('<caption>foo<col>').should == [ expect(lex_html('<caption>foo<col>')).to eq([
[:T_ELEM_NAME, 'caption', 1], [:T_ELEM_NAME, 'caption', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'col', 1], [:T_ELEM_NAME, 'col', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,32 +3,32 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <colgroup> elements' do describe 'using HTML <colgroup> elements' do
it 'lexes two unclosed <colgroup> elements as separate elements' do it 'lexes two unclosed <colgroup> elements as separate elements' do
lex_html('<colgroup>foo<colgroup>bar').should == [ expect(lex_html('<colgroup>foo<colgroup>bar')).to eq([
[:T_ELEM_NAME, 'colgroup', 1], [:T_ELEM_NAME, 'colgroup', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'colgroup', 1], [:T_ELEM_NAME, 'colgroup', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <col> element following a <colgroup> as a child element' do it 'lexes a <col> element following a <colgroup> as a child element' do
lex_html('<colgroup><col>').should == [ expect(lex_html('<colgroup><col>')).to eq([
[:T_ELEM_NAME, 'colgroup', 1], [:T_ELEM_NAME, 'colgroup', 1],
[:T_ELEM_NAME, 'col', 1], [:T_ELEM_NAME, 'col', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <template> element following a <colgroup> as a child element' do it 'lexes a <template> element following a <colgroup> as a child element' do
lex_html('<colgroup><template>').should == [ expect(lex_html('<colgroup><template>')).to eq([
[:T_ELEM_NAME, 'colgroup', 1], [:T_ELEM_NAME, 'colgroup', 1],
[:T_ELEM_NAME, 'template', 1], [:T_ELEM_NAME, 'template', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <dt> elements' do describe 'using HTML <dt> elements' do
it 'lexes two unclosed <dd> elements following each other as separate elements' do it 'lexes two unclosed <dd> elements following each other as separate elements' do
lex_html('<dd>foo<dd>bar').should == [ expect(lex_html('<dd>foo<dd>bar')).to eq([
[:T_ELEM_NAME, 'dd', 1], [:T_ELEM_NAME, 'dd', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'dd', 1], [:T_ELEM_NAME, 'dd', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <dd> followed by a <dt> as separate elements' do it 'lexes an unclosed <dd> followed by a <dt> as separate elements' do
lex_html('<dd>foo<dt>bar').should == [ expect(lex_html('<dd>foo<dt>bar')).to eq([
[:T_ELEM_NAME, 'dd', 1], [:T_ELEM_NAME, 'dd', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'dt', 1], [:T_ELEM_NAME, 'dt', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <dt> elements' do describe 'using HTML <dt> elements' do
it 'lexes two unclosed <dt> elements following each other as separate elements' do it 'lexes two unclosed <dt> elements following each other as separate elements' do
lex_html('<dt>foo<dt>bar').should == [ expect(lex_html('<dt>foo<dt>bar')).to eq([
[:T_ELEM_NAME, 'dt', 1], [:T_ELEM_NAME, 'dt', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'dt', 1], [:T_ELEM_NAME, 'dt', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <dt> followed by a <dd> as separate elements' do it 'lexes an unclosed <dt> followed by a <dd> as separate elements' do
lex_html('<dt>foo<dd>bar').should == [ expect(lex_html('<dt>foo<dd>bar')).to eq([
[:T_ELEM_NAME, 'dt', 1], [:T_ELEM_NAME, 'dt', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'dd', 1], [:T_ELEM_NAME, 'dd', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,35 +3,35 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <head> elements' do describe 'using HTML <head> elements' do
it 'lexes an unclosed <head> followed by a <head> as separate elements' do it 'lexes an unclosed <head> followed by a <head> as separate elements' do
lex_html('<head>foo<head>bar').should == [ expect(lex_html('<head>foo<head>bar')).to eq([
[:T_ELEM_NAME, 'head', 1], [:T_ELEM_NAME, 'head', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'head', 1], [:T_ELEM_NAME, 'head', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <head> followed by a <body> as separate elements' do it 'lexes an unclosed <head> followed by a <body> as separate elements' do
lex_html('<head>foo<body>bar').should == [ expect(lex_html('<head>foo<body>bar')).to eq([
[:T_ELEM_NAME, 'head', 1], [:T_ELEM_NAME, 'head', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'body', 1], [:T_ELEM_NAME, 'body', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <title> following an unclosed <head> as a child element' do it 'lexes a <title> following an unclosed <head> as a child element' do
lex_html('<head><title>foo</title>').should == [ expect(lex_html('<head><title>foo</title>')).to eq([
[:T_ELEM_NAME, 'head', 1], [:T_ELEM_NAME, 'head', 1],
[:T_ELEM_NAME, 'title', 1], [:T_ELEM_NAME, 'title', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,14 +3,14 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <li> elements' do describe 'using HTML <li> elements' do
it 'lexes two unclosed <li> elements following each other as separate elements' do it 'lexes two unclosed <li> elements following each other as separate elements' do
lex_html('<li>foo<li>bar').should == [ expect(lex_html('<li>foo<li>bar')).to eq([
[:T_ELEM_NAME, 'li', 1], [:T_ELEM_NAME, 'li', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'li', 1], [:T_ELEM_NAME, 'li', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -4,7 +4,7 @@ describe Oga::XML::Lexer do
describe 'HTML optgroup elements' do describe 'HTML optgroup elements' do
describe 'with unclosed <optgroup> tags' do describe 'with unclosed <optgroup> tags' do
it 'lexes an <option> tag followed by a <optgroup> tag' do it 'lexes an <option> tag followed by a <optgroup> tag' do
lex_html('<optgroup><option>foo<optgroup><option>bar').should == [ expect(lex_html('<optgroup><option>foo<optgroup><option>bar')).to eq([
[:T_ELEM_NAME, 'optgroup', 1], [:T_ELEM_NAME, 'optgroup', 1],
[:T_ELEM_NAME, 'option', 1], [:T_ELEM_NAME, 'option', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
@ -15,7 +15,7 @@ describe Oga::XML::Lexer do
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <option> elements' do describe 'using HTML <option> elements' do
it 'lexes two unclosed <option> elements following each other as separate elements' do it 'lexes two unclosed <option> elements following each other as separate elements' do
lex_html('<option>foo<option>bar').should == [ expect(lex_html('<option>foo<option>bar')).to eq([
[:T_ELEM_NAME, 'option', 1], [:T_ELEM_NAME, 'option', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'option', 1], [:T_ELEM_NAME, 'option', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <option> followed by a <optgroup> as separate elements' do it 'lexes an unclosed <option> followed by a <optgroup> as separate elements' do
lex_html('<option>foo<optgroup>bar').should == [ expect(lex_html('<option>foo<optgroup>bar')).to eq([
[:T_ELEM_NAME, 'option', 1], [:T_ELEM_NAME, 'option', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'optgroup', 1], [:T_ELEM_NAME, 'optgroup', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <p> elements' do describe 'using HTML <p> elements' do
it 'lexes two unclosed <p> elements following each other as separate elements' do it 'lexes two unclosed <p> elements following each other as separate elements' do
lex_html('<p>foo<p>bar').should == [ expect(lex_html('<p>foo<p>bar')).to eq([
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <p> followed by a <address> as separate elements' do it 'lexes an unclosed <p> followed by a <address> as separate elements' do
lex_html('<p>foo<address>bar').should == [ expect(lex_html('<p>foo<address>bar')).to eq([
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'address', 1], [:T_ELEM_NAME, 'address', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <rb> elements' do describe 'using HTML <rb> elements' do
it 'lexes two unclosed <rb> elements following each other as separate elements' do it 'lexes two unclosed <rb> elements following each other as separate elements' do
lex_html('<rb>foo<rb>bar').should == [ expect(lex_html('<rb>foo<rb>bar')).to eq([
[:T_ELEM_NAME, 'rb', 1], [:T_ELEM_NAME, 'rb', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rb', 1], [:T_ELEM_NAME, 'rb', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <rb> followed by a <rt> as separate elements' do it 'lexes an unclosed <rb> followed by a <rt> as separate elements' do
lex_html('<rb>foo<rt>bar').should == [ expect(lex_html('<rb>foo<rt>bar')).to eq([
[:T_ELEM_NAME, 'rb', 1], [:T_ELEM_NAME, 'rb', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rt', 1], [:T_ELEM_NAME, 'rt', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <rp> elements' do describe 'using HTML <rp> elements' do
it 'lexes two unclosed <rp> elements following each other as separate elements' do it 'lexes two unclosed <rp> elements following each other as separate elements' do
lex_html('<rp>foo<rp>bar').should == [ expect(lex_html('<rp>foo<rp>bar')).to eq([
[:T_ELEM_NAME, 'rp', 1], [:T_ELEM_NAME, 'rp', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rp', 1], [:T_ELEM_NAME, 'rp', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <rp> followed by a <rb> as separate elements' do it 'lexes an unclosed <rp> followed by a <rb> as separate elements' do
lex_html('<rp>foo<rb>bar').should == [ expect(lex_html('<rp>foo<rb>bar')).to eq([
[:T_ELEM_NAME, 'rp', 1], [:T_ELEM_NAME, 'rp', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rb', 1], [:T_ELEM_NAME, 'rb', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <rt> elements' do describe 'using HTML <rt> elements' do
it 'lexes two unclosed <rt> elements following each other as separate elements' do it 'lexes two unclosed <rt> elements following each other as separate elements' do
lex_html('<rt>foo<rt>bar').should == [ expect(lex_html('<rt>foo<rt>bar')).to eq([
[:T_ELEM_NAME, 'rt', 1], [:T_ELEM_NAME, 'rt', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rt', 1], [:T_ELEM_NAME, 'rt', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <rt> followed by a <rtc> as separate elements' do it 'lexes an unclosed <rt> followed by a <rtc> as separate elements' do
lex_html('<rt>foo<rtc>bar').should == [ expect(lex_html('<rt>foo<rtc>bar')).to eq([
[:T_ELEM_NAME, 'rt', 1], [:T_ELEM_NAME, 'rt', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rtc', 1], [:T_ELEM_NAME, 'rtc', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,25 +3,25 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <rt> elements' do describe 'using HTML <rt> elements' do
it 'lexes two unclosed <rtc> elements following each other as separate elements' do it 'lexes two unclosed <rtc> elements following each other as separate elements' do
lex_html('<rtc>foo<rtc>bar').should == [ expect(lex_html('<rtc>foo<rtc>bar')).to eq([
[:T_ELEM_NAME, 'rtc', 1], [:T_ELEM_NAME, 'rtc', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rtc', 1], [:T_ELEM_NAME, 'rtc', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <rtc> followed by a <rb> as separate elements' do it 'lexes an unclosed <rtc> followed by a <rb> as separate elements' do
lex_html('<rtc>foo<rb>bar').should == [ expect(lex_html('<rtc>foo<rb>bar')).to eq([
[:T_ELEM_NAME, 'rtc', 1], [:T_ELEM_NAME, 'rtc', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'rb', 1], [:T_ELEM_NAME, 'rb', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,44 +3,44 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <table> elements' do describe 'using HTML <table> elements' do
it 'lexes two unclosed <table> elements following each other as separate elements' do it 'lexes two unclosed <table> elements following each other as separate elements' do
lex_html('<table>foo<table>bar').should == [ expect(lex_html('<table>foo<table>bar')).to eq([
[:T_ELEM_NAME, 'table', 1], [:T_ELEM_NAME, 'table', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'table', 1], [:T_ELEM_NAME, 'table', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <table> element containing a <thead> element' do it 'lexes a <table> element containing a <thead> element' do
lex_html('<table><thead>foo</thead></table>').should == [ expect(lex_html('<table><thead>foo</thead></table>')).to eq([
[:T_ELEM_NAME, 'table', 1], [:T_ELEM_NAME, 'table', 1],
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <table> element containing a <script> element' do it 'lexes a <table> element containing a <script> element' do
lex_html('<table><script>foo</script></table>').should == [ expect(lex_html('<table><script>foo</script></table>')).to eq([
[:T_ELEM_NAME, 'table', 1], [:T_ELEM_NAME, 'table', 1],
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <table> element containing a <template> element' do it 'lexes a <table> element containing a <template> element' do
lex_html('<table><template>foo</template></table>').should == [ expect(lex_html('<table><template>foo</template></table>')).to eq([
[:T_ELEM_NAME, 'table', 1], [:T_ELEM_NAME, 'table', 1],
[:T_ELEM_NAME, 'template', 1], [:T_ELEM_NAME, 'template', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,55 +3,55 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <tbody> elements' do describe 'using HTML <tbody> elements' do
it 'lexes two unclosed <tbody> elements following each other as separate elements' do it 'lexes two unclosed <tbody> elements following each other as separate elements' do
lex_html('<tbody>foo<tbody>bar').should == [ expect(lex_html('<tbody>foo<tbody>bar')).to eq([
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <tbody> followed by a <tfoot> as separate elements' do it 'lexes an unclosed <tbody> followed by a <tfoot> as separate elements' do
lex_html('<tbody>foo<tfoot>bar').should == [ expect(lex_html('<tbody>foo<tfoot>bar')).to eq([
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tr> following an unclosed <tbody> as a child element' do it 'lexes a <tr> following an unclosed <tbody> as a child element' do
lex_html('<tbody><tr>foo').should == [ expect(lex_html('<tbody><tr>foo')).to eq([
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tbody> element containing a <script> element' do it 'lexes a <tbody> element containing a <script> element' do
lex_html('<tbody><script>foo</script></tbody>').should == [ expect(lex_html('<tbody><script>foo</script></tbody>')).to eq([
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tbody> element containing a <template> element' do it 'lexes a <tbody> element containing a <template> element' do
lex_html('<tbody><template>foo</template></tbody>').should == [ expect(lex_html('<tbody><template>foo</template></tbody>')).to eq([
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_ELEM_NAME, 'template', 1], [:T_ELEM_NAME, 'template', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,35 +3,35 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <td> elements' do describe 'using HTML <td> elements' do
it 'lexes two unclosed <td> elements following each other as separate elements' do it 'lexes two unclosed <td> elements following each other as separate elements' do
lex_html('<td>foo<td>bar').should == [ expect(lex_html('<td>foo<td>bar')).to eq([
[:T_ELEM_NAME, 'td', 1], [:T_ELEM_NAME, 'td', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'td', 1], [:T_ELEM_NAME, 'td', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <td> followed by a <thead> as separate elements' do it 'lexes an unclosed <td> followed by a <thead> as separate elements' do
lex_html('<td>foo<thead>bar').should == [ expect(lex_html('<td>foo<thead>bar')).to eq([
[:T_ELEM_NAME, 'td', 1], [:T_ELEM_NAME, 'td', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <p> followed an unclosed <td> as a child element' do it 'lexes a <p> followed an unclosed <td> as a child element' do
lex_html('<td><p>foo').should == [ expect(lex_html('<td><p>foo')).to eq([
[:T_ELEM_NAME, 'td', 1], [:T_ELEM_NAME, 'td', 1],
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,55 +3,55 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <tfoot> elements' do describe 'using HTML <tfoot> elements' do
it 'lexes two unclosed <tfoot> elements following each other as separate elements' do it 'lexes two unclosed <tfoot> elements following each other as separate elements' do
lex_html('<tfoot>foo<tfoot>bar').should == [ expect(lex_html('<tfoot>foo<tfoot>bar')).to eq([
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <tfoot> followed by a <tbody> as separate elements' do it 'lexes an unclosed <tfoot> followed by a <tbody> as separate elements' do
lex_html('<tfoot>foo<tbody>bar').should == [ expect(lex_html('<tfoot>foo<tbody>bar')).to eq([
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tr> following an unclosed <tfoot> as a child element' do it 'lexes a <tr> following an unclosed <tfoot> as a child element' do
lex_html('<tfoot><tr>foo').should == [ expect(lex_html('<tfoot><tr>foo')).to eq([
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tfoot> element containing a <script> element' do it 'lexes a <tfoot> element containing a <script> element' do
lex_html('<tfoot><script>foo</script></tfoot>').should == [ expect(lex_html('<tfoot><script>foo</script></tfoot>')).to eq([
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tfoot> element containing a <template> element' do it 'lexes a <tfoot> element containing a <template> element' do
lex_html('<tfoot><template>foo</template></tfoot>').should == [ expect(lex_html('<tfoot><template>foo</template></tfoot>')).to eq([
[:T_ELEM_NAME, 'tfoot', 1], [:T_ELEM_NAME, 'tfoot', 1],
[:T_ELEM_NAME, 'template', 1], [:T_ELEM_NAME, 'template', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,35 +3,35 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <th> elements' do describe 'using HTML <th> elements' do
it 'lexes two unclosed <th> elements following each other as separate elements' do it 'lexes two unclosed <th> elements following each other as separate elements' do
lex_html('<th>foo<th>bar').should == [ expect(lex_html('<th>foo<th>bar')).to eq([
[:T_ELEM_NAME, 'th', 1], [:T_ELEM_NAME, 'th', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'th', 1], [:T_ELEM_NAME, 'th', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <th> followed by a <thead> as separate elements' do it 'lexes an unclosed <th> followed by a <thead> as separate elements' do
lex_html('<th>foo<thead>bar').should == [ expect(lex_html('<th>foo<thead>bar')).to eq([
[:T_ELEM_NAME, 'th', 1], [:T_ELEM_NAME, 'th', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <p> followed an unclosed <th> as a child element' do it 'lexes a <p> followed an unclosed <th> as a child element' do
lex_html('<th><p>foo').should == [ expect(lex_html('<th><p>foo')).to eq([
[:T_ELEM_NAME, 'th', 1], [:T_ELEM_NAME, 'th', 1],
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,55 +3,55 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <thead> elements' do describe 'using HTML <thead> elements' do
it 'lexes two unclosed <thead> elements following each other as separate elements' do it 'lexes two unclosed <thead> elements following each other as separate elements' do
lex_html('<thead>foo<thead>bar').should == [ expect(lex_html('<thead>foo<thead>bar')).to eq([
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an unclosed <thead> followed by a <tbody> as separate elements' do it 'lexes an unclosed <thead> followed by a <tbody> as separate elements' do
lex_html('<thead>foo<tbody>bar').should == [ expect(lex_html('<thead>foo<tbody>bar')).to eq([
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tbody', 1], [:T_ELEM_NAME, 'tbody', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tr> following an unclosed <thead> as a child element' do it 'lexes a <tr> following an unclosed <thead> as a child element' do
lex_html('<thead><tr>foo').should == [ expect(lex_html('<thead><tr>foo')).to eq([
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <thead> element containing a <script> element' do it 'lexes a <thead> element containing a <script> element' do
lex_html('<thead><script>foo</script></thead>').should == [ expect(lex_html('<thead><script>foo</script></thead>')).to eq([
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <thead> element containing a <template> element' do it 'lexes a <thead> element containing a <template> element' do
lex_html('<thead><template>foo</template></thead>').should == [ expect(lex_html('<thead><template>foo</template></thead>')).to eq([
[:T_ELEM_NAME, 'thead', 1], [:T_ELEM_NAME, 'thead', 1],
[:T_ELEM_NAME, 'template', 1], [:T_ELEM_NAME, 'template', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,54 +3,54 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <tr> elements' do describe 'using HTML <tr> elements' do
it 'lexes two unclosed <tr> elements following each other as separate elements' do it 'lexes two unclosed <tr> elements following each other as separate elements' do
lex_html('<tr>foo<tr>bar').should == [ expect(lex_html('<tr>foo<tr>bar')).to eq([
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <td> followed an unclosed <tr> as a child element' do it 'lexes a <td> followed an unclosed <tr> as a child element' do
lex_html('<tr><td>foo').should == [ expect(lex_html('<tr><td>foo')).to eq([
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_ELEM_NAME, 'td', 1], [:T_ELEM_NAME, 'td', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <th> followed an unclosed <tr> as a child element' do it 'lexes a <th> followed an unclosed <tr> as a child element' do
lex_html('<tr><th>foo').should == [ expect(lex_html('<tr><th>foo')).to eq([
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_ELEM_NAME, 'th', 1], [:T_ELEM_NAME, 'th', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tr> element containing a <script> element' do it 'lexes a <tr> element containing a <script> element' do
lex_html('<tr><script>foo</script></tr>').should == [ expect(lex_html('<tr><script>foo</script></tr>')).to eq([
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a <tr> element containing a <template> element' do it 'lexes a <tr> element containing a <template> element' do
lex_html('<tr><template>foo</template></tr>').should == [ expect(lex_html('<tr><template>foo</template></tr>')).to eq([
[:T_ELEM_NAME, 'tr', 1], [:T_ELEM_NAME, 'tr', 1],
[:T_ELEM_NAME, 'template', 1], [:T_ELEM_NAME, 'template', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'using HTML <ul> elements' do describe 'using HTML <ul> elements' do
it 'lexes an <ul> element containing unclosed <li> elements with text' do it 'lexes an <ul> element containing unclosed <li> elements with text' do
lex_html('<ul><li>foo<li>bar</ul>').should == [ expect(lex_html('<ul><li>foo<li>bar</ul>')).to eq([
[:T_ELEM_NAME, 'ul', 1], [:T_ELEM_NAME, 'ul', 1],
[:T_ELEM_NAME, 'li', 1], [:T_ELEM_NAME, 'li', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
@ -12,11 +12,11 @@ describe Oga::XML::Lexer do
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes an <ul> element followed by text containing unclosed <li> elements with text' do it 'lexes an <ul> element followed by text containing unclosed <li> elements with text' do
lex_html('<ul><li>foo<li>bar</ul>outside ul').should == [ expect(lex_html('<ul><li>foo<li>bar</ul>outside ul')).to eq([
[:T_ELEM_NAME, 'ul', 1], [:T_ELEM_NAME, 'ul', 1],
[:T_ELEM_NAME, 'li', 1], [:T_ELEM_NAME, 'li', 1],
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
@ -26,11 +26,11 @@ describe Oga::XML::Lexer do
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_TEXT, 'outside ul', 1] [:T_TEXT, 'outside ul', 1]
] ])
end end
it 'lexes nested <ul> elements containing unclosed <li> elements' do it 'lexes nested <ul> elements containing unclosed <li> elements' do
lex_html('<ul><li><ul><li>foo</ul><li>bar</ul>').should == [ expect(lex_html('<ul><li><ul><li>foo</ul><li>bar</ul>')).to eq([
[:T_ELEM_NAME, 'ul', 1], [:T_ELEM_NAME, 'ul', 1],
[:T_ELEM_NAME, 'li', 1], [:T_ELEM_NAME, 'li', 1],
[:T_ELEM_NAME, 'ul', 1], [:T_ELEM_NAME, 'ul', 1],
@ -43,7 +43,7 @@ describe Oga::XML::Lexer do
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,10 +3,10 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'HTML elements' do describe 'HTML elements' do
it 'lexes an element containing an element namespace' do it 'lexes an element containing an element namespace' do
lex_html('<foo:bar />').should == [ expect(lex_html('<foo:bar />')).to eq([
[:T_ELEM_NAME, 'bar', 1], [:T_ELEM_NAME, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -7,54 +7,54 @@ describe Oga::XML::Lexer do
end end
it 'lexes inline Javascript' do it 'lexes inline Javascript' do
lex("<script>#{@javascript}</script>").should == [ expect(lex("<script>#{@javascript}</script>")).to eq([
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, @javascript, 1], [:T_TEXT, @javascript, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes inline Javascript containing an XML comment' do it 'lexes inline Javascript containing an XML comment' do
lex("<script>#{@javascript}<!--foo--></script>").should == [ expect(lex("<script>#{@javascript}<!--foo--></script>")).to eq([
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, @javascript, 1], [:T_TEXT, @javascript, 1],
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, 'foo', 1], [:T_COMMENT_BODY, 'foo', 1],
[:T_COMMENT_END, nil, 1], [:T_COMMENT_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes inline Javascript containing a CDATA tag' do it 'lexes inline Javascript containing a CDATA tag' do
lex("<script>#{@javascript}<![CDATA[foo]]></script>").should == [ expect(lex("<script>#{@javascript}<![CDATA[foo]]></script>")).to eq([
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, @javascript, 1], [:T_TEXT, @javascript, 1],
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, 'foo', 1], [:T_CDATA_BODY, 'foo', 1],
[:T_CDATA_END, nil, 1], [:T_CDATA_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes inline Javascript containing a processing instruction' do it 'lexes inline Javascript containing a processing instruction' do
lex("<script>#{@javascript}<?foo?></script>").should == [ expect(lex("<script>#{@javascript}<?foo?></script>")).to eq([
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, @javascript, 1], [:T_TEXT, @javascript, 1],
[:T_PROC_INS_START, nil, 1], [:T_PROC_INS_START, nil, 1],
[:T_PROC_INS_NAME, 'foo', 1], [:T_PROC_INS_NAME, 'foo', 1],
[:T_PROC_INS_END, nil, 1], [:T_PROC_INS_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes inline Javascript containing another element' do it 'lexes inline Javascript containing another element' do
lex("<script>#{@javascript}<p></p></script>").should == [ expect(lex("<script>#{@javascript}<p></p></script>")).to eq([
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, @javascript, 1], [:T_TEXT, @javascript, 1],
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,24 +3,24 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'HTML script elements' do describe 'HTML script elements' do
it 'treats the content of a script tag as plain text' do it 'treats the content of a script tag as plain text' do
lex_html('<script>foo <bar</script>').should == [ expect(lex_html('<script>foo <bar</script>')).to eq([
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, 'foo ', 1], [:T_TEXT, 'foo ', 1],
[:T_TEXT, '<', 1], [:T_TEXT, '<', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'treats style tags inside script tags as text' do it 'treats style tags inside script tags as text' do
lex_html('<script><style></style></script>').should == [ expect(lex_html('<script><style></style></script>')).to eq([
[:T_ELEM_NAME, 'script', 1], [:T_ELEM_NAME, 'script', 1],
[:T_TEXT, '<', 1], [:T_TEXT, '<', 1],
[:T_TEXT, 'style>', 1], [:T_TEXT, 'style>', 1],
[:T_TEXT, '<', 1], [:T_TEXT, '<', 1],
[:T_TEXT, '/style>', 1], [:T_TEXT, '/style>', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -3,48 +3,48 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'HTML style elements' do describe 'HTML style elements' do
it 'lexes an empty <style> tag' do it 'lexes an empty <style> tag' do
lex_html('<style></style>').should == [ expect(lex_html('<style></style>')).to eq([
[:T_ELEM_NAME, 'style', 1], [:T_ELEM_NAME, 'style', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'treats the content of a style tag as plain text' do it 'treats the content of a style tag as plain text' do
lex_html('<style>foo <bar</style>').should == [ expect(lex_html('<style>foo <bar</style>')).to eq([
[:T_ELEM_NAME, 'style', 1], [:T_ELEM_NAME, 'style', 1],
[:T_TEXT, 'foo ', 1], [:T_TEXT, 'foo ', 1],
[:T_TEXT, '<', 1], [:T_TEXT, '<', 1],
[:T_TEXT, 'bar', 1], [:T_TEXT, 'bar', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'treats script tags inside style tags as text' do it 'treats script tags inside style tags as text' do
lex_html('<style><script></script></style>').should == [ expect(lex_html('<style><script></script></style>')).to eq([
[:T_ELEM_NAME, 'style', 1], [:T_ELEM_NAME, 'style', 1],
[:T_TEXT, '<', 1], [:T_TEXT, '<', 1],
[:T_TEXT, 'script>', 1], [:T_TEXT, 'script>', 1],
[:T_TEXT, '<', 1], [:T_TEXT, '<', 1],
[:T_TEXT, '/script>', 1], [:T_TEXT, '/script>', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a multi-line <style> tag using a String as the input' do it 'lexes a multi-line <style> tag using a String as the input' do
lex_html("<style>foo\nbar</style>").should == [ expect(lex_html("<style>foo\nbar</style>")).to eq([
[:T_ELEM_NAME, 'style', 1], [:T_ELEM_NAME, 'style', 1],
[:T_TEXT, "foo\nbar", 1], [:T_TEXT, "foo\nbar", 1],
[:T_ELEM_END, nil, 2] [:T_ELEM_END, nil, 2]
] ])
end end
it 'lexes a multi-line <style> tag using an IO as the input' do it 'lexes a multi-line <style> tag using an IO as the input' do
lex_stringio("<style>foo\nbar</style>", :html => true).should == [ expect(lex_stringio("<style>foo\nbar</style>", :html => true)).to eq([
[:T_ELEM_NAME, 'style', 1], [:T_ELEM_NAME, 'style', 1],
[:T_TEXT, "foo\n", 1], [:T_TEXT, "foo\n", 1],
[:T_TEXT, 'bar', 2], [:T_TEXT, 'bar', 2],
[:T_ELEM_END, nil, 2] [:T_ELEM_END, nil, 2]
] ])
end end
end end
end end

View File

@ -3,85 +3,85 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'HTML void elements' do describe 'HTML void elements' do
it 'lexes a void element that omits the closing /' do it 'lexes a void element that omits the closing /' do
lex_html('<link>').should == [ expect(lex_html('<link>')).to eq([
[:T_ELEM_NAME, 'link', 1], [:T_ELEM_NAME, 'link', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a upper case void element' do it 'lexes a upper case void element' do
lex_html('<BR>').should == [ expect(lex_html('<BR>')).to eq([
[:T_ELEM_NAME, "BR", 1], [:T_ELEM_NAME, "BR", 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes text after a void element' do it 'lexes text after a void element' do
lex_html('<link>foo').should == [ expect(lex_html('<link>foo')).to eq([
[:T_ELEM_NAME, 'link', 1], [:T_ELEM_NAME, 'link', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_TEXT, 'foo', 1] [:T_TEXT, 'foo', 1]
] ])
end end
it 'lexes a void element inside another element' do it 'lexes a void element inside another element' do
lex_html('<head><link></head>').should == [ expect(lex_html('<head><link></head>')).to eq([
[:T_ELEM_NAME, 'head', 1], [:T_ELEM_NAME, 'head', 1],
[:T_ELEM_NAME, 'link', 1], [:T_ELEM_NAME, 'link', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a void element inside another element with whitespace' do it 'lexes a void element inside another element with whitespace' do
lex_html("<head><link>\n</head>").should == [ expect(lex_html("<head><link>\n</head>")).to eq([
[:T_ELEM_NAME, 'head', 1], [:T_ELEM_NAME, 'head', 1],
[:T_ELEM_NAME, 'link', 1], [:T_ELEM_NAME, 'link', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_TEXT, "\n", 1], [:T_TEXT, "\n", 1],
[:T_ELEM_END, nil, 2] [:T_ELEM_END, nil, 2]
] ])
end end
it 'lexes a void element with an unquoted attribute value' do it 'lexes a void element with an unquoted attribute value' do
lex_html('<br class=foo />').should == [ expect(lex_html('<br class=foo />')).to eq([
[:T_ELEM_NAME, 'br', 1], [:T_ELEM_NAME, 'br', 1],
[:T_ATTR, 'class', 1], [:T_ATTR, 'class', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'foo', 1], [:T_STRING_BODY, 'foo', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
describe 'without a space before the closing tag' do describe 'without a space before the closing tag' do
it 'lexes a void element' do it 'lexes a void element' do
lex_html('<br/>').should == [ expect(lex_html('<br/>')).to eq([
[:T_ELEM_NAME, 'br', 1], [:T_ELEM_NAME, 'br', 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a void element with an attribute' do it 'lexes a void element with an attribute' do
lex_html('<br class="foo"/>').should == [ expect(lex_html('<br class="foo"/>')).to eq([
[:T_ELEM_NAME, 'br', 1], [:T_ELEM_NAME, 'br', 1],
[:T_ATTR, 'class', 1], [:T_ATTR, 'class', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_STRING_BODY, 'foo', 1], [:T_STRING_BODY, 'foo', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a void element with an unquoted attribute value' do it 'lexes a void element with an unquoted attribute value' do
lex_html('<br class=foo/>').should == [ expect(lex_html('<br class=foo/>')).to eq([
[:T_ELEM_NAME, 'br', 1], [:T_ELEM_NAME, 'br', 1],
[:T_ATTR, 'class', 1], [:T_ATTR, 'class', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_STRING_BODY, 'foo/', 1], [:T_STRING_BODY, 'foo/', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
end end
end end

View File

@ -7,11 +7,11 @@ describe Oga::HTML::Parser do
end end
it 'returns an Element instance' do it 'returns an Element instance' do
@node.is_a?(Oga::XML::Element).should == true expect(@node.is_a?(Oga::XML::Element)).to eq(true)
end end
it 'sets the name of the element' do it 'sets the name of the element' do
@node.name.should == 'meta' expect(@node.name).to eq('meta')
end end
end end
end end

View File

@ -17,6 +17,6 @@ describe Oga::HTML::SaxParser do
parser.parse parser.parse
handler.name.should == 'link' expect(handler.name).to eq('link')
end end
end end

View File

@ -7,7 +7,7 @@ describe Oga::LRU do
cache.maximum = 20 cache.maximum = 20
cache.maximum.should == 20 expect(cache.maximum).to eq(20)
end end
it 'resizes the cache when needed' do it 'resizes the cache when needed' do
@ -18,20 +18,20 @@ describe Oga::LRU do
cache.maximum = 1 cache.maximum = 1
cache.size.should == 1 expect(cache.size).to eq(1)
cache.keys.should == [:b] expect(cache.keys).to eq([:b])
end end
end end
describe '#maximum' do describe '#maximum' do
it 'returns the maximum amount of keys' do it 'returns the maximum amount of keys' do
described_class.new(5).maximum.should == 5 expect(described_class.new(5).maximum).to eq(5)
end end
end end
describe '#[]' do describe '#[]' do
it 'returns nil for a non existing key' do it 'returns nil for a non existing key' do
described_class.new[:a].should be_nil expect(described_class.new[:a]).to be_nil
end end
it 'returns the value of an existing key' do it 'returns the value of an existing key' do
@ -39,7 +39,7 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache[:a].should == 10 expect(cache[:a]).to eq(10)
end end
end end
@ -49,7 +49,7 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache[:a].should == 10 expect(cache[:a]).to eq(10)
end end
it 'resizes the cache if the new amount of keys exceeds the limit' do it 'resizes the cache if the new amount of keys exceeds the limit' do
@ -58,7 +58,7 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache[:b] = 20 cache[:b] = 20
cache.keys.should == [:b] expect(cache.keys).to eq([:b])
end end
it 'adds duplicate keys at the end of the list of keys' do it 'adds duplicate keys at the end of the list of keys' do
@ -68,7 +68,7 @@ describe Oga::LRU do
cache[:b] = 20 cache[:b] = 20
cache[:a] = 30 cache[:a] = 30
cache.keys.should == [:b, :a] expect(cache.keys).to eq([:b, :a])
end end
describe 'using multiple threads' do describe 'using multiple threads' do
@ -81,7 +81,7 @@ describe Oga::LRU do
end end
numbers.each do |number| numbers.each do |number|
cache[number].should == number expect(cache[number]).to eq(number)
end end
end end
@ -93,7 +93,7 @@ describe Oga::LRU do
cache[number] = number cache[number] = number
end end
cache.size.should == 5 expect(cache.size).to eq(5)
end end
end end
end end
@ -102,7 +102,7 @@ describe Oga::LRU do
it 'sets a non existing key' do it 'sets a non existing key' do
cache = described_class.new cache = described_class.new
cache.get_or_set(:a) { 10 }.should == 10 expect(cache.get_or_set(:a) { 10 }).to eq(10)
end end
it 'returns the value of an existing key' do it 'returns the value of an existing key' do
@ -110,14 +110,14 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache.get_or_set(:a) { 20 }.should == 10 expect(cache.get_or_set(:a) { 20 }).to eq(10)
end end
describe 'using multiple threads' do describe 'using multiple threads' do
it 'only sets a key once' do it 'only sets a key once' do
cache = described_class.new cache = described_class.new
cache.should_receive(:[]=).once.and_call_original expect(cache).to receive(:[]=).once.and_call_original
each_in_parallel([1, 1, 1]) do |number| each_in_parallel([1, 1, 1]) do |number|
cache.get_or_set(number) { number } cache.get_or_set(number) { number }
@ -133,7 +133,7 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache[:b] = 20 cache[:b] = 20
cache.keys.should == [:a, :b] expect(cache.keys).to eq([:a, :b])
end end
it 'returns the keys without any duplicates' do it 'returns the keys without any duplicates' do
@ -142,7 +142,7 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache[:a] = 20 cache[:a] = 20
cache.keys.should == [:a] expect(cache.keys).to eq([:a])
end end
end end
@ -152,13 +152,13 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache.key?(:a).should == true expect(cache.key?(:a)).to eq(true)
end end
it 'returns false for a non existing key' do it 'returns false for a non existing key' do
cache = described_class.new cache = described_class.new
cache.key?(:a).should == false expect(cache.key?(:a)).to eq(false)
end end
end end
@ -170,13 +170,13 @@ describe Oga::LRU do
cache.clear cache.clear
cache.size.should == 0 expect(cache.size).to eq(0)
end end
end end
describe '#size' do describe '#size' do
it 'returns 0 for an empty cache' do it 'returns 0 for an empty cache' do
described_class.new.size.should == 0 expect(described_class.new.size).to eq(0)
end end
it 'returns the number of keys for a non empty cache' do it 'returns the number of keys for a non empty cache' do
@ -184,7 +184,7 @@ describe Oga::LRU do
cache[:a] = 10 cache[:a] = 10
cache.size.should == 1 expect(cache.size).to eq(1)
end end
end end
end end

View File

@ -5,13 +5,13 @@ describe Oga do
it 'parses 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 expect(document.is_a?(Oga::XML::Document)).to eq(true)
end end
it 'raises an error when parsing an invalid document in strict mode' do it 'raises an error when parsing an invalid document in strict mode' do
block = proc { described_class.parse_xml('<root>foo', :strict => true) } block = proc { described_class.parse_xml('<root>foo', :strict => true) }
block.should raise_error(LL::ParserError) expect(block).to raise_error(LL::ParserError)
end end
end end
@ -19,7 +19,7 @@ describe Oga do
it 'parses 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 expect(document.is_a?(Oga::XML::Document)).to eq(true)
end end
end end
@ -39,19 +39,19 @@ describe Oga do
it 'parses an XML document using the SAX parser' do it 'parses an XML document using the SAX parser' do
described_class.sax_parse_xml(@handler, '<foo />') described_class.sax_parse_xml(@handler, '<foo />')
@handler.name.should == 'foo' expect(@handler.name).to eq('foo')
end end
it 'raises an error when parsing an invalid XML document in strict mode' do it 'raises an error when parsing an invalid XML document in strict mode' do
block = proc { Oga.sax_parse_xml(@handler, '<foo>', :strict => true) } block = proc { Oga.sax_parse_xml(@handler, '<foo>', :strict => true) }
block.should raise_error(LL::ParserError) expect(block).to raise_error(LL::ParserError)
end end
it 'parses an HTML document using the SAX parser' do it 'parses an HTML document using the SAX parser' do
described_class.sax_parse_html(@handler, '<link>') described_class.sax_parse_html(@handler, '<link>')
@handler.name.should == 'link' expect(@handler.name).to eq('link')
end end
end end
end end

View File

@ -11,7 +11,7 @@ describe Oga::Ruby::Generator do
node2 = Oga::Ruby::Node.new(:lit, %w{20}) node2 = Oga::Ruby::Node.new(:lit, %w{20})
joined = node1.followed_by(node2) joined = node1.followed_by(node2)
@generator.on_followed_by(joined).should == "10\n\n20" expect(@generator.on_followed_by(joined)).to eq("10\n\n20")
end end
end end
@ -21,7 +21,7 @@ describe Oga::Ruby::Generator do
val = Oga::Ruby::Node.new(:lit, %w{10}) val = Oga::Ruby::Node.new(:lit, %w{10})
assign = var.assign(val) assign = var.assign(val)
@generator.on_assign(assign).should == 'number = 10' expect(@generator.on_assign(assign)).to eq('number = 10')
end end
describe 'using a followed_by node' do describe 'using a followed_by node' do
@ -30,7 +30,7 @@ describe Oga::Ruby::Generator do
val = Oga::Ruby::Node.new(:lit, %w{10}) val = Oga::Ruby::Node.new(:lit, %w{10})
assign = var.assign(val.followed_by(val)) assign = var.assign(val.followed_by(val))
@generator.on_assign(assign).should == <<-EOF expect(@generator.on_assign(assign)).to eq <<-EOF
number = begin number = begin
10 10
@ -49,7 +49,7 @@ EOF
assign = Oga::Ruby::Node.new(:massign, [[var1, var2], val]) assign = Oga::Ruby::Node.new(:massign, [[var1, var2], val])
@generator.on_massign(assign).should == 'foo, bar = 10' expect(@generator.on_massign(assign)).to eq('foo, bar = 10')
end end
end end
@ -58,7 +58,7 @@ EOF
number = Oga::Ruby::Node.new(:lit, %w{10}) number = Oga::Ruby::Node.new(:lit, %w{10})
node = Oga::Ruby::Node.new(:begin, [number]) node = Oga::Ruby::Node.new(:begin, [number])
@generator.on_begin(node).should == <<-EOF expect(@generator.on_begin(node)).to eq <<-EOF
begin begin
10 10
end end
@ -72,7 +72,7 @@ end
val = Oga::Ruby::Node.new(:lit, %w{10}) val = Oga::Ruby::Node.new(:lit, %w{10})
eq = var.eq(val) eq = var.eq(val)
@generator.on_eq(eq).should == 'number == 10' expect(@generator.on_eq(eq)).to eq('number == 10')
end end
end end
@ -82,7 +82,7 @@ end
right = Oga::Ruby::Node.new(:lit, %w{bar}) right = Oga::Ruby::Node.new(:lit, %w{bar})
condition = left.and(right) condition = left.and(right)
@generator.on_and(condition).should == 'foo && bar' expect(@generator.on_and(condition)).to eq('foo && bar')
end end
end end
@ -92,7 +92,7 @@ end
right = Oga::Ruby::Node.new(:lit, %w{bar}) right = Oga::Ruby::Node.new(:lit, %w{bar})
condition = left.or(right) condition = left.or(right)
@generator.on_or(condition).should == '(foo || bar)' expect(@generator.on_or(condition)).to eq('(foo || bar)')
end end
end end
@ -102,7 +102,7 @@ end
Oga::Ruby::Node.new(:lit, %w{bar}) Oga::Ruby::Node.new(:lit, %w{bar})
end end
@generator.on_if(statement).should == <<-EOF expect(@generator.on_if(statement)).to eq <<-EOF
if foo if foo
bar bar
end end
@ -117,7 +117,7 @@ end
statement = foo.if_true { bar }.else { baz } statement = foo.if_true { bar }.else { baz }
@generator.on_if(statement).should == <<-EOF expect(@generator.on_if(statement)).to eq <<-EOF
if foo if foo
bar bar
else else
@ -134,7 +134,7 @@ end
Oga::Ruby::Node.new(:lit, %w{bar}) Oga::Ruby::Node.new(:lit, %w{bar})
end end
@generator.on_while(statement).should == <<-EOF expect(@generator.on_while(statement)).to eq <<-EOF
while foo while foo
bar bar
end end
@ -147,7 +147,7 @@ end
it 'returns a String' do it 'returns a String' do
node = Oga::Ruby::Node.new(:lit, %w{number}).foobar node = Oga::Ruby::Node.new(:lit, %w{number}).foobar
@generator.on_send(node).should == 'number.foobar' expect(@generator.on_send(node)).to eq('number.foobar')
end end
end end
@ -156,7 +156,7 @@ end
arg = Oga::Ruby::Node.new(:lit, %w{10}) arg = Oga::Ruby::Node.new(:lit, %w{10})
node = Oga::Ruby::Node.new(:lit, %w{number}).foobar(arg) node = Oga::Ruby::Node.new(:lit, %w{number}).foobar(arg)
@generator.on_send(node).should == 'number.foobar(10)' expect(@generator.on_send(node)).to eq('number.foobar(10)')
end end
end end
@ -165,7 +165,7 @@ end
arg = Oga::Ruby::Node.new(:lit, %w{10}) arg = Oga::Ruby::Node.new(:lit, %w{10})
node = Oga::Ruby::Node.new(:lit, %w{number})[arg] node = Oga::Ruby::Node.new(:lit, %w{number})[arg]
@generator.on_send(node).should == 'number[10]' expect(@generator.on_send(node)).to eq('number[10]')
end end
end end
end end
@ -177,7 +177,7 @@ end
Oga::Ruby::Node.new(:lit, %w{10}) Oga::Ruby::Node.new(:lit, %w{10})
end end
@generator.on_block(node).should == <<-EOF expect(@generator.on_block(node)).to eq <<-EOF
number do || number do ||
10 10
end end
@ -192,7 +192,7 @@ end
Oga::Ruby::Node.new(:lit, %w{10}) Oga::Ruby::Node.new(:lit, %w{10})
end end
@generator.on_block(node).should == <<-EOF expect(@generator.on_block(node)).to eq <<-EOF
number do |foo| number do |foo|
10 10
end end
@ -207,7 +207,7 @@ end
stop = Oga::Ruby::Node.new(:lit, %w{20}) stop = Oga::Ruby::Node.new(:lit, %w{20})
node = Oga::Ruby::Node.new(:range, [start, stop]) node = Oga::Ruby::Node.new(:range, [start, stop])
@generator.on_range(node).should == '(10..20)' expect(@generator.on_range(node)).to eq('(10..20)')
end end
end end
@ -215,7 +215,7 @@ end
it 'returns a String' do it 'returns a String' do
node = Oga::Ruby::Node.new(:string, %w{foo}) node = Oga::Ruby::Node.new(:string, %w{foo})
@generator.on_string(node).should == '"foo"' expect(@generator.on_string(node)).to eq('"foo"')
end end
end end
@ -223,7 +223,7 @@ end
it 'returns a String' do it 'returns a String' do
node = Oga::Ruby::Node.new(:symbol, [:foo]) node = Oga::Ruby::Node.new(:symbol, [:foo])
@generator.on_symbol(node).should == ':foo' expect(@generator.on_symbol(node)).to eq(':foo')
end end
end end
@ -231,7 +231,7 @@ end
it 'returns a String' do it 'returns a String' do
node = Oga::Ruby::Node.new(:lit, %w{foo}) node = Oga::Ruby::Node.new(:lit, %w{foo})
@generator.on_lit(node).should == 'foo' expect(@generator.on_lit(node)).to eq('foo')
end end
end end
end end

View File

@ -5,7 +5,7 @@ describe Oga::Ruby::Node do
it 'returns the type of the node as a Symbol' do it 'returns the type of the node as a Symbol' do
node = described_class.new('foo') node = described_class.new('foo')
node.type.should == :foo expect(node.type).to eq(:foo)
end end
end end
@ -13,7 +13,7 @@ describe Oga::Ruby::Node do
it 'returns the children of the Node as an Array' do it 'returns the children of the Node as an Array' do
node = described_class.new(:foo, %w{10}) node = described_class.new(:foo, %w{10})
node.to_a.should == %w{10} expect(node.to_a).to eq(%w{10})
end end
end end
@ -22,8 +22,8 @@ describe Oga::Ruby::Node do
number = described_class.new(:lit, %w{10}) number = described_class.new(:lit, %w{10})
node = number.to_array node = number.to_array
node.type.should == :send expect(node.type).to eq(:send)
node.to_a.should == [number, :to_a] expect(node.to_a).to eq([number, :to_a])
end end
end end
@ -33,8 +33,8 @@ describe Oga::Ruby::Node do
right = described_class.new(:lit, %w{10}) right = described_class.new(:lit, %w{10})
node = left.assign(right) node = left.assign(right)
node.type.should == :assign expect(node.type).to eq(:assign)
node.to_a.should == [left, right] expect(node.to_a).to eq([left, right])
end end
end end
@ -44,8 +44,8 @@ describe Oga::Ruby::Node do
right = described_class.new(:lit, %w{10}) right = described_class.new(:lit, %w{10})
node = left.eq(right) node = left.eq(right)
node.type.should == :eq expect(node.type).to eq(:eq)
node.to_a.should == [left, right] expect(node.to_a).to eq([left, right])
end end
end end
@ -55,8 +55,8 @@ describe Oga::Ruby::Node do
right = described_class.new(:lit, %w{10}) right = described_class.new(:lit, %w{10})
node = left.and(right) node = left.and(right)
node.type.should == :and expect(node.type).to eq(:and)
node.to_a.should == [left, right] expect(node.to_a).to eq([left, right])
end end
end end
@ -66,8 +66,8 @@ describe Oga::Ruby::Node do
right = described_class.new(:lit, %w{10}) right = described_class.new(:lit, %w{10})
node = left.or(right) node = left.or(right)
node.type.should == :or expect(node.type).to eq(:or)
node.to_a.should == [left, right] expect(node.to_a).to eq([left, right])
end end
end end
@ -76,8 +76,8 @@ describe Oga::Ruby::Node do
node = described_class.new(:lit, %w{foo}) node = described_class.new(:lit, %w{foo})
inverted = node.not inverted = node.not
inverted.type.should == :send expect(inverted.type).to eq(:send)
inverted.to_a.should == [node, '!'] expect(inverted.to_a).to eq([node, '!'])
end end
end end
@ -86,13 +86,13 @@ describe Oga::Ruby::Node do
left = described_class.new(:lit, %w{number}) left = described_class.new(:lit, %w{number})
node = left.is_a?(String) node = left.is_a?(String)
node.type.should == :send expect(node.type).to eq(:send)
node.to_a[0].should == left expect(node.to_a[0]).to eq(left)
node.to_a[1].should == 'is_a?' expect(node.to_a[1]).to eq('is_a?')
node.to_a[2].type.should == :lit expect(node.to_a[2].type).to eq(:lit)
node.to_a[2].to_a.should == %w{String} expect(node.to_a[2].to_a).to eq(%w{String})
end end
end end
@ -103,8 +103,8 @@ describe Oga::Ruby::Node do
body = described_class.new(:lit, %w{20}) body = described_class.new(:lit, %w{20})
block = left.add_block(arg) { body } block = left.add_block(arg) { body }
block.type.should == :block expect(block.type).to eq(:block)
block.to_a.should == [left, [arg], body] expect(block.to_a).to eq([left, [arg], body])
end end
end end
@ -113,8 +113,8 @@ describe Oga::Ruby::Node do
number = described_class.new(:lit, %w{10}) number = described_class.new(:lit, %w{10})
wrapped = number.wrap wrapped = number.wrap
wrapped.type.should == :begin expect(wrapped.type).to eq(:begin)
wrapped.to_a.should == [number] expect(wrapped.to_a).to eq([number])
end end
end end
@ -124,8 +124,8 @@ describe Oga::Ruby::Node do
body = described_class.new(:lit, %w{10}) body = described_class.new(:lit, %w{10})
statement = condition.if_true { body } statement = condition.if_true { body }
statement.type.should == :if expect(statement.type).to eq(:if)
statement.to_a.should == [condition, body] expect(statement.to_a).to eq([condition, body])
end end
end end
@ -135,12 +135,12 @@ describe Oga::Ruby::Node do
body = described_class.new(:lit, %w{10}) body = described_class.new(:lit, %w{10})
statement = condition.if_false { body } statement = condition.if_false { body }
statement.type.should == :if expect(statement.type).to eq(:if)
statement.to_a[0].type.should == :send expect(statement.to_a[0].type).to eq(:send)
statement.to_a[0].to_a.should == [condition, '!'] expect(statement.to_a[0].to_a).to eq([condition, '!'])
statement.to_a[1].should == body expect(statement.to_a[1]).to eq(body)
end end
end end
@ -150,8 +150,8 @@ describe Oga::Ruby::Node do
body = described_class.new(:lit, %w{10}) body = described_class.new(:lit, %w{10})
statement = condition.while_true { body } statement = condition.while_true { body }
statement.type.should == :while expect(statement.type).to eq(:while)
statement.to_a.should == [condition, body] expect(statement.to_a).to eq([condition, body])
end end
end end
@ -162,8 +162,8 @@ describe Oga::Ruby::Node do
or_else = described_class.new(:lit, %w{20}) or_else = described_class.new(:lit, %w{20})
statement = condition.if_true { body }.else { or_else } statement = condition.if_true { body }.else { or_else }
statement.type.should == :if expect(statement.type).to eq(:if)
statement.to_a.should == [condition, body, or_else] expect(statement.to_a).to eq([condition, body, or_else])
end end
end end
@ -174,8 +174,8 @@ describe Oga::Ruby::Node do
node2 = described_class.new(:lit, %w{B}) node2 = described_class.new(:lit, %w{B})
joined = node1.followed_by(node2) joined = node1.followed_by(node2)
joined.type.should == :followed_by expect(joined.type).to eq(:followed_by)
joined.to_a.should == [node1, node2] expect(joined.to_a).to eq([node1, node2])
end end
end end
@ -185,8 +185,8 @@ describe Oga::Ruby::Node do
node2 = described_class.new(:lit, %w{B}) node2 = described_class.new(:lit, %w{B})
joined = node1.followed_by { node2 } joined = node1.followed_by { node2 }
joined.type.should == :followed_by expect(joined.type).to eq(:followed_by)
joined.to_a.should == [node1, node2] expect(joined.to_a).to eq([node1, node2])
end end
end end
end end
@ -197,8 +197,8 @@ describe Oga::Ruby::Node do
arg = described_class.new(:lit, %w{10}) arg = described_class.new(:lit, %w{10})
call = receiver.foo(arg) call = receiver.foo(arg)
call.type.should == :send expect(call.type).to eq(:send)
call.to_a.should == [receiver, 'foo', arg] expect(call.to_a).to eq([receiver, 'foo', arg])
end end
end end
@ -206,7 +206,7 @@ describe Oga::Ruby::Node do
it 'returns a String' do it 'returns a String' do
node = described_class.new(:lit, %w{10}) node = described_class.new(:lit, %w{10})
node.inspect.should == '(lit "10")' expect(node.inspect).to eq('(lit "10")')
end end
end end
end end

View File

@ -14,15 +14,15 @@ describe Oga::Whitelist do
it 'returns false for a name not in the list' do it 'returns false for a name not in the list' do
list = described_class.new(%w{foo}) list = described_class.new(%w{foo})
list.allow?('bar').should == false expect(list.allow?('bar')).to eq(false)
list.allow?('BAR').should == false expect(list.allow?('BAR')).to eq(false)
end end
it 'returns true for a name in the list' do it 'returns true for a name in the list' do
list = described_class.new(%w{foo}) list = described_class.new(%w{foo})
list.allow?('foo').should == true expect(list.allow?('foo')).to eq(true)
list.allow?('FOO').should == true expect(list.allow?('FOO')).to eq(true)
end end
end end
@ -32,8 +32,8 @@ describe Oga::Whitelist do
list2 = described_class.new(%w{bar}) list2 = described_class.new(%w{bar})
list3 = list1 + list2 list3 = list1 + list2
list3.should be_an_instance_of(described_class) expect(list3).to be_an_instance_of(described_class)
list3.names.to_a.should == %w{foo FOO bar BAR} expect(list3.names.to_a).to eq(%w{foo FOO bar BAR})
end end
end end
@ -42,8 +42,8 @@ describe Oga::Whitelist do
whitelist = described_class.new(%w{foo}) whitelist = described_class.new(%w{foo})
blacklist = whitelist.to_blacklist blacklist = whitelist.to_blacklist
blacklist.should be_an_instance_of(Oga::Blacklist) expect(blacklist).to be_an_instance_of(Oga::Blacklist)
blacklist.names.should == whitelist.names expect(blacklist.names).to eq(whitelist.names)
end end
end end
end end

View File

@ -3,11 +3,11 @@ require 'spec_helper'
describe Oga::XML::Attribute do describe Oga::XML::Attribute do
describe '#initialize' do describe '#initialize' do
it 'sets the name' do it 'sets the name' do
described_class.new(:name => 'a').name.should == 'a' expect(described_class.new(:name => 'a').name).to eq('a')
end end
it 'sets the value' do it 'sets the value' do
described_class.new(:value => 'a').value.should == 'a' expect(described_class.new(:value => 'a').value).to eq('a')
end end
end end
@ -16,7 +16,7 @@ describe Oga::XML::Attribute do
element = Oga::XML::Element.new(:name => 'foo') element = Oga::XML::Element.new(:name => 'foo')
attr = described_class.new(:element => element) attr = described_class.new(:element => element)
attr.parent.should == element expect(attr.parent).to eq(element)
end end
end end
@ -38,11 +38,11 @@ describe Oga::XML::Attribute do
end end
it 'returns a Namespace instance' do it 'returns a Namespace instance' do
@attribute.namespace.should == @namespace expect(@attribute.namespace).to eq(@namespace)
end end
it 'returns 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 expect(@default.namespace).to eq(Oga::XML::Attribute::DEFAULT_NAMESPACE)
end end
end end
@ -52,23 +52,23 @@ describe Oga::XML::Attribute do
attr.value = 'foo' attr.value = 'foo'
attr.value.should == 'foo' expect(attr.value).to eq('foo')
end end
it 'flushes the decoded cache when setting a new value' do it 'flushes the decoded cache when setting a new value' do
attr = described_class.new(:value => '&lt;') attr = described_class.new(:value => '&lt;')
attr.value.should == Oga::XML::Entities::DECODE_MAPPING['&lt;'] expect(attr.value).to eq(Oga::XML::Entities::DECODE_MAPPING['&lt;'])
attr.value = '&gt;' attr.value = '&gt;'
attr.value.should == Oga::XML::Entities::DECODE_MAPPING['&gt;'] expect(attr.value).to eq(Oga::XML::Entities::DECODE_MAPPING['&gt;'])
end end
end end
describe '#value' do describe '#value' do
it 'returns the value of an attribute' do it 'returns the value of an attribute' do
described_class.new(:value => 'foo').value.should == 'foo' expect(described_class.new(:value => 'foo').value).to eq('foo')
end end
describe 'using an XML document' do describe 'using an XML document' do
@ -84,7 +84,7 @@ describe Oga::XML::Attribute do
:element => @el :element => @el
) )
attr.value.should == '<' expect(attr.value).to eq('<')
end end
end end
@ -101,18 +101,18 @@ describe Oga::XML::Attribute do
:element => @el :element => @el
) )
attr.value.should == Oga::HTML::Entities::DECODE_MAPPING['&copy;'] expect(attr.value).to eq(Oga::HTML::Entities::DECODE_MAPPING['&copy;'])
end end
end end
end end
describe '#text' do describe '#text' do
it 'returns 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 == '' expect(described_class.new.text).to eq('')
end end
it 'returns the value if it is present' do it 'returns the value if it is present' do
described_class.new(:value => 'a').text.should == 'a' expect(described_class.new(:value => 'a').text).to eq('a')
end end
end end
@ -120,7 +120,7 @@ describe Oga::XML::Attribute do
it 'converts 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"' expect(attr.to_xml).to eq('foo="bar"')
end end
it 'includes the namespace when converting an attribute to XML' do it 'includes the namespace when converting an attribute to XML' do
@ -135,7 +135,7 @@ describe Oga::XML::Attribute do
:element => element :element => element
) )
attr.to_xml.should == 'foo:class="10"' expect(attr.to_xml).to eq('foo:class="10"')
end end
it 'includes the "xmlns" namespace when present but not registered' do it 'includes the "xmlns" namespace when present but not registered' do
@ -145,13 +145,13 @@ describe Oga::XML::Attribute do
:element => Oga::XML::Element.new :element => Oga::XML::Element.new
) )
attr.to_xml.should == 'xmlns:class=""' expect(attr.to_xml).to eq('xmlns:class=""')
end end
it 'decodes XML entities' do it 'decodes XML entities' do
attr = described_class.new(:name => 'href', :value => %q{&<>'"}) attr = described_class.new(:name => 'href', :value => %q{&<>'"})
attr.to_xml.should == 'href="&amp;&lt;&gt;&apos;&quot;"' expect(attr.to_xml).to eq('href="&amp;&lt;&gt;&apos;&quot;"')
end end
end end
@ -168,7 +168,7 @@ describe Oga::XML::Attribute do
:element => element :element => element
) )
obj.inspect.should == <<-EOF.strip expect(obj.inspect).to eq <<-EOF.strip
Attribute(name: "a" namespace: Namespace(name: "b" uri: nil) value: "c") Attribute(name: "a" namespace: Namespace(name: "b" uri: nil) value: "c")
EOF EOF
end end
@ -179,7 +179,7 @@ EOF
it 'returns a String' do it 'returns a String' do
attr = described_class.new(:namespace_name => 'foo', :name => 'bar') attr = described_class.new(:namespace_name => 'foo', :name => 'bar')
attr.expanded_name.should == 'foo:bar' expect(attr.expanded_name).to eq('foo:bar')
end end
end end
@ -187,7 +187,7 @@ EOF
it 'returns a String' do it 'returns a String' do
attr = described_class.new(:name => 'bar') attr = described_class.new(:name => 'bar')
attr.expanded_name.should == 'bar' expect(attr.expanded_name).to eq('bar')
end end
end end
end end

View File

@ -3,14 +3,14 @@ require 'spec_helper'
describe Oga::XML::Cdata do describe Oga::XML::Cdata do
describe 'setting attributes' do describe 'setting attributes' do
it 'sets the text via the constructor' do it 'sets the text via the constructor' do
described_class.new(:text => 'foo').text.should == 'foo' expect(described_class.new(:text => 'foo').text).to eq('foo')
end end
it 'sets 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'
instance.text.should == 'foo' expect(instance.text).to eq('foo')
end end
end end
@ -20,7 +20,7 @@ describe Oga::XML::Cdata do
end end
it 'generates the corresponding XML' do it 'generates the corresponding XML' do
@instance.to_xml.should == '<![CDATA[foo]]>' expect(@instance.to_xml).to eq('<![CDATA[foo]]>')
end end
end end
@ -30,7 +30,7 @@ describe Oga::XML::Cdata do
end end
it 'returns the inspect value' do it 'returns the inspect value' do
@instance.inspect.should == 'Cdata("foo")' expect(@instance.inspect).to eq('Cdata("foo")')
end end
end end
end end

View File

@ -3,20 +3,20 @@ require 'spec_helper'
describe Oga::XML::CharacterNode do describe Oga::XML::CharacterNode do
describe '#initialize' do describe '#initialize' do
it 'sets the text in the constructor' do it 'sets the text in the constructor' do
described_class.new(:text => 'a').text.should == 'a' expect(described_class.new(:text => 'a').text).to eq('a')
end end
it 'sets 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'
node.text.should == 'a' expect(node.text).to eq('a')
end end
end end
describe '#inspect' do describe '#inspect' do
it 'returns the inspect value' do it 'returns the inspect value' do
described_class.new(:text => 'a').inspect.should == 'CharacterNode("a")' expect(described_class.new(:text => 'a').inspect).to eq('CharacterNode("a")')
end end
end end
end end

View File

@ -3,14 +3,14 @@ require 'spec_helper'
describe Oga::XML::Comment do describe Oga::XML::Comment do
describe 'setting attributes' do describe 'setting attributes' do
it 'sets the text via the constructor' do it 'sets the text via the constructor' do
described_class.new(:text => 'foo').text.should == 'foo' expect(described_class.new(:text => 'foo').text).to eq('foo')
end end
it 'sets 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'
instance.text.should == 'foo' expect(instance.text).to eq('foo')
end end
end end
@ -20,7 +20,7 @@ describe Oga::XML::Comment do
end end
it 'generates the corresponding XML' do it 'generates the corresponding XML' do
@instance.to_xml.should == '<!--foo-->' expect(@instance.to_xml).to eq('<!--foo-->')
end end
end end
@ -30,7 +30,7 @@ describe Oga::XML::Comment do
end end
it 'returns the inspect value' do it 'returns the inspect value' do
@instance.inspect.should == 'Comment("foo")' expect(@instance.inspect).to eq('Comment("foo")')
end end
end end
end end

View File

@ -3,26 +3,26 @@ require 'spec_helper'
describe Oga::XML::Doctype do describe Oga::XML::Doctype do
describe 'setting attributes' do describe 'setting attributes' do
it 'sets the name via the constructor' do it 'sets the name via the constructor' do
described_class.new(:name => 'html').name.should == 'html' expect(described_class.new(:name => 'html').name).to eq('html')
end end
it 'sets 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'
instance.name.should == 'html' expect(instance.name).to eq('html')
end end
end end
describe '#to_xml' do describe '#to_xml' do
it 'generates a bare minimum representation' do it 'generates a bare minimum representation' do
described_class.new(:name => 'html').to_xml.should == '<!DOCTYPE html>' expect(described_class.new(:name => 'html').to_xml).to eq('<!DOCTYPE html>')
end end
it 'includes 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>' expect(instance.to_xml).to eq('<!DOCTYPE html PUBLIC>')
end end
it 'includes the public ID if present' do it 'includes the public ID if present' do
@ -32,7 +32,7 @@ describe Oga::XML::Doctype do
:public_id => 'foo' :public_id => 'foo'
) )
instance.to_xml.should == '<!DOCTYPE html PUBLIC "foo">' expect(instance.to_xml).to eq('<!DOCTYPE html PUBLIC "foo">')
end end
it 'includes the system ID if present' do it 'includes the system ID if present' do
@ -43,7 +43,7 @@ describe Oga::XML::Doctype do
:system_id => 'bar' :system_id => 'bar'
) )
instance.to_xml.should == '<!DOCTYPE html PUBLIC "foo" "bar">' expect(instance.to_xml).to eq('<!DOCTYPE html PUBLIC "foo" "bar">')
end end
it 'includes the inline rules if present' do it 'includes the inline rules if present' do
@ -52,7 +52,7 @@ describe Oga::XML::Doctype do
:inline_rules => '<!ELEMENT foo>' :inline_rules => '<!ELEMENT foo>'
) )
instance.to_xml.should == '<!DOCTYPE html [<!ELEMENT foo>]>' expect(instance.to_xml).to eq('<!DOCTYPE html [<!ELEMENT foo>]>')
end end
end end
@ -66,7 +66,7 @@ describe Oga::XML::Doctype do
end end
it 'pretty-prints the node' do it 'pretty-prints the node' do
@instance.inspect.should == <<-EOF.strip expect(@instance.inspect).to eq <<-EOF.strip
Doctype(name: "html" type: "PUBLIC" inline_rules: "<!ELEMENT foo>") Doctype(name: "html" type: "PUBLIC" inline_rules: "<!ELEMENT foo>")
EOF EOF
end end

View File

@ -6,11 +6,11 @@ describe Oga::XML::Document 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 expect(document.children[0]).to eq(child)
end end
it 'sets the document type' do it 'sets the document type' do
described_class.new(:type => :html).type.should == :html expect(described_class.new(:type => :html).type).to eq(:html)
end end
end end
@ -21,7 +21,7 @@ describe Oga::XML::Document do
document.children = [child] document.children = [child]
document.children[0].should == child expect(document.children[0]).to eq(child)
end end
it 'sets the child nodes using a NodeSet' do it 'sets the child nodes using a NodeSet' do
@ -30,7 +30,7 @@ describe Oga::XML::Document do
document.children = Oga::XML::NodeSet.new([child]) document.children = Oga::XML::NodeSet.new([child])
document.children[0].should == child expect(document.children[0]).to eq(child)
end end
end end
@ -38,7 +38,7 @@ describe Oga::XML::Document do
it 'returns self' do it 'returns self' do
doc = described_class.new doc = described_class.new
doc.root_node.should == doc expect(doc.root_node).to eq(doc)
end end
end end
@ -49,7 +49,7 @@ describe Oga::XML::Document do
end end
it 'generates the corresponding XML' do it 'generates the corresponding XML' do
@document.to_xml.should == '<!--foo-->' expect(@document.to_xml).to eq('<!--foo-->')
end end
end end
@ -65,8 +65,8 @@ describe Oga::XML::Document do
end end
it 'includes the XML of the declaration tag' do it 'includes the XML of the declaration tag' do
@document.to_xml expect(@document.to_xml)
.should == %Q{<?xml version="5.0" encoding="UTF-8" ?>\n<!--foo-->} .to eq(%Q{<?xml version="5.0" encoding="UTF-8" ?>\n<!--foo-->})
end end
end end
@ -82,7 +82,7 @@ describe Oga::XML::Document do
end end
it 'includes the doctype' do it 'includes the doctype' do
@document.to_xml.should == %Q{<!DOCTYPE html PUBLIC>\n<!--foo-->} expect(@document.to_xml).to eq(%Q{<!DOCTYPE html PUBLIC>\n<!--foo-->})
end end
end end
@ -100,18 +100,18 @@ describe Oga::XML::Document do
end end
it 'includes 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" ?>' \ expect(@document.to_xml).to eq('<?xml version="5.0" encoding="UTF-8" ?>' \
"\n<!DOCTYPE html PUBLIC>\n<!--foo-->" "\n<!DOCTYPE html PUBLIC>\n<!--foo-->")
end end
end end
describe '#html?' do describe '#html?' do
it 'returns false for an XML document' do it 'returns false for an XML document' do
described_class.new(:type => :xml).html?.should == false expect(described_class.new(:type => :xml).html?).to eq(false)
end end
it 'returns true for an HTML document' do it 'returns true for an HTML document' do
described_class.new(:type => :html).html?.should == true expect(described_class.new(:type => :html).html?).to eq(true)
end end
end end
@ -125,7 +125,7 @@ describe Oga::XML::Document do
end end
it 'returns the inspect value' do it 'returns the inspect value' do
@instance.inspect.should == <<-EOF.strip expect(@instance.inspect).to eq <<-EOF.strip
Document( Document(
doctype: Doctype(name: "html") doctype: Doctype(name: "html")
xml_declaration: XmlDeclaration(version: "1.0" encoding: "UTF-8") xml_declaration: XmlDeclaration(version: "1.0" encoding: "UTF-8")
@ -135,7 +135,7 @@ Document(
end end
it 'returns 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 expect(described_class.new.inspect).to eq <<-EOF.strip
Document( Document(
children: NodeSet() children: NodeSet()
) )
@ -145,7 +145,7 @@ Document(
describe '#literal_html_name?' do describe '#literal_html_name?' do
it 'returns false' do it 'returns false' do
described_class.new.literal_html_name?.should == false expect(described_class.new.literal_html_name?).to eq(false)
end end
end end
end end

View File

@ -3,11 +3,11 @@ require 'spec_helper'
describe Oga::XML::Element do describe Oga::XML::Element do
describe '#initialize' do describe '#initialize' do
it 'sets the name via the constructor' do it 'sets the name via the constructor' do
described_class.new(:name => 'p').name.should == 'p' expect(described_class.new(:name => 'p').name).to eq('p')
end end
it 'sets the default attributes' do it 'sets the default attributes' do
described_class.new.attributes.should == [] expect(described_class.new.attributes).to eq([])
end end
describe 'with a namespace' do describe 'with a namespace' do
@ -21,11 +21,11 @@ describe Oga::XML::Element do
end end
it 'registers the "foo" namespace' do it 'registers the "foo" namespace' do
@element.namespaces['foo'].is_a?(Oga::XML::Namespace).should == true expect(@element.namespaces['foo'].is_a?(Oga::XML::Namespace)).to eq(true)
end end
it 'keeps the attributes after registering the namespaces' do it 'keeps the attributes after registering the namespaces' do
@element.attributes.empty?.should == false expect(@element.attributes.empty?).to eq(false)
end end
end end
@ -37,7 +37,7 @@ describe Oga::XML::Element do
end end
it 'registers the default namespace' do it 'registers the default namespace' do
@element.namespaces['xmlns'].is_a?(Oga::XML::Namespace).should == true expect(@element.namespaces['xmlns'].is_a?(Oga::XML::Namespace)).to eq(true)
end end
end end
end end
@ -48,7 +48,7 @@ describe Oga::XML::Element do
element.namespace_name = 'foo' element.namespace_name = 'foo'
element.namespace_name.should == 'foo' expect(element.namespace_name).to eq('foo')
end end
end end
@ -75,35 +75,35 @@ describe Oga::XML::Element do
end end
it 'returns an attribute with only a name' do it 'returns an attribute with only a name' do
@instance.attribute('key').value.should == 'value' expect(@instance.attribute('key').value).to eq('value')
end end
it 'returns 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' expect(@instance.attribute(:key).value).to eq('value')
end end
it 'returns 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' expect(@instance.attribute('x:key').value).to eq('foo')
end end
it 'returns 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' expect(@instance.attribute(:'x:key').value).to eq('foo')
end end
it 'returns 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 expect(@instance.attribute('y:key').nil?).to eq(true)
end end
it 'returns 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 expect(@instance.attribute('x:foobar').nil?).to eq(true)
end end
it 'returns nil for a non existing attribute' do it 'returns nil for a non existing attribute' do
@instance.attribute('foobar').nil?.should == true expect(@instance.attribute('foobar').nil?).to eq(true)
end end
it 'returns 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 expect(@instance.attribute('bar').nil?).to eq(true)
end end
describe 'using an HTML document' do describe 'using an HTML document' do
@ -119,12 +119,12 @@ describe Oga::XML::Element do
end end
it 'returns an attribute with a name containing a namespace separator' do it 'returns an attribute with a name containing a namespace separator' do
el.attribute('foo:bar').should == attr expect(el.attribute('foo:bar')).to eq(attr)
end end
describe 'using a Symbol argument' do describe 'using a Symbol argument' do
it 'returns the attribute' do it 'returns the attribute' do
el.attribute(:'foo:bar').should == attr expect(el.attribute(:'foo:bar')).to eq(attr)
end end
end end
end end
@ -138,14 +138,15 @@ describe Oga::XML::Element do
end end
it 'returns the value of an attribute' do it 'returns the value of an attribute' do
@element.get('foo').should == 'bar' expect(@element.get('foo')).to eq('bar')
end end
end end
describe '#[]' do describe '#[]' do
it 'is an alias to get' do it 'is an alias to get' do
described_class.instance_method(:[]).should == expect(described_class.instance_method(:[])).to eq(
described_class.instance_method(:get) described_class.instance_method(:get)
)
end end
end end
@ -158,13 +159,13 @@ describe Oga::XML::Element do
it 'adds 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 expect(@element.attribute('foo')).to eq(@attribute)
end end
it 'sets 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 expect(@attribute.element).to eq(@element)
end end
end end
@ -178,21 +179,21 @@ describe Oga::XML::Element do
it 'adds a new attribute' do it 'adds a new attribute' do
@element.set('class', 'foo') @element.set('class', 'foo')
@element.get('class').should == 'foo' expect(@element.get('class')).to eq('foo')
end end
it 'supports the use of Symbols for attribute names' do it 'supports the use of Symbols for attribute names' do
@element.set(:foo, 'foo') @element.set(:foo, 'foo')
@element.get('foo').should == 'foo' expect(@element.get('foo')).to eq('foo')
@element.set('bar', 'bar') @element.set('bar', 'bar')
@element.get(:bar).should == 'bar' expect(@element.get(:bar)).to eq('bar')
end end
it 'adds 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' expect(@element.get('x:bar')).to eq('foo')
end end
it 'sets the namespace of an attribute' do it 'sets the namespace of an attribute' do
@ -200,7 +201,7 @@ describe Oga::XML::Element do
attr = @element.attribute('x:bar') attr = @element.attribute('x:bar')
attr.namespace.is_a?(Oga::XML::Namespace).should == true expect(attr.namespace.is_a?(Oga::XML::Namespace)).to eq(true)
end end
it 'overwrites the value of an existing attribute' do it 'overwrites the value of an existing attribute' do
@ -210,14 +211,15 @@ describe Oga::XML::Element do
@element.set('foo', 'baz') @element.set('foo', 'baz')
@element.get('foo').should == 'baz' expect(@element.get('foo')).to eq('baz')
end end
end end
describe '#[]=' do describe '#[]=' do
it 'is an alias to set' do it 'is an alias to set' do
described_class.instance_method(:[]=).should == expect(described_class.instance_method(:[]=)).to eq(
described_class.instance_method(:set) described_class.instance_method(:set)
)
end end
end end
@ -234,13 +236,13 @@ describe Oga::XML::Element do
it 'removes 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 expect(@element.get('foo')).to be_nil
end end
it 'removes 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 expect(@element.get('x:foo')).to be_nil
end end
end end
@ -252,7 +254,7 @@ describe Oga::XML::Element do
:namespaces => {'x' => namespace} :namespaces => {'x' => namespace}
) )
element.namespace.should == namespace expect(element.namespace).to eq(namespace)
end end
it 'returns the default namespace if available' do it 'returns the default namespace if available' do
@ -261,7 +263,7 @@ describe Oga::XML::Element do
:namespaces => {'xmlns' => namespace} :namespaces => {'xmlns' => namespace}
) )
element.namespace.should == namespace expect(element.namespace).to eq(namespace)
end end
it 'flushes the cache when changing the namespace name' do it 'flushes the cache when changing the namespace name' do
@ -272,7 +274,7 @@ describe Oga::XML::Element do
element.namespace_name = 'foo' element.namespace_name = 'foo'
element.namespace.should be_nil expect(element.namespace).to be_nil
end end
describe 'in an HTML document' do describe 'in an HTML document' do
@ -281,7 +283,7 @@ describe Oga::XML::Element do
el = described_class.new(:namespaces => {'xmlns' => ns}) el = described_class.new(:namespaces => {'xmlns' => ns})
doc = Oga::XML::Document.new(:type => :html, :children => [el]) doc = Oga::XML::Document.new(:type => :html, :children => [el])
el.namespace.should be_nil expect(el.namespace).to be_nil
end end
end end
end end
@ -294,7 +296,7 @@ describe Oga::XML::Element do
:namespaces => {'x' => namespace} :namespaces => {'x' => namespace}
) )
element.namespaces.should == {'x' => namespace} expect(element.namespaces).to eq({'x' => namespace})
end end
describe 'in an HTML document' do describe 'in an HTML document' do
@ -303,14 +305,14 @@ describe Oga::XML::Element do
el = described_class.new(:namespaces => {'xmlns' => ns}) el = described_class.new(:namespaces => {'xmlns' => ns})
doc = Oga::XML::Document.new(:type => :html, :children => [el]) doc = Oga::XML::Document.new(:type => :html, :children => [el])
el.namespaces.should == {} expect(el.namespaces).to eq({})
end end
end end
end end
describe '#default_namespace?' do describe '#default_namespace?' do
it 'returns true when an element has no explicit namespace' do it 'returns true when an element has no explicit namespace' do
described_class.new(:name => 'a').default_namespace?.should == true expect(described_class.new(:name => 'a').default_namespace?).to eq(true)
end end
it 'returns true when an element has an explicit default namespace' do it 'returns true when an element has an explicit default namespace' do
@ -319,7 +321,7 @@ describe Oga::XML::Element do
element.register_namespace(namespace.name, namespace.uri) element.register_namespace(namespace.name, namespace.uri)
element.default_namespace?.should == true expect(element.default_namespace?).to eq(true)
end end
it 'returns false when an element resides in a custom namespace' do it 'returns false when an element resides in a custom namespace' do
@ -327,7 +329,7 @@ describe Oga::XML::Element do
element.register_namespace('xmlns', 'foo') element.register_namespace('xmlns', 'foo')
element.default_namespace?.should == false expect(element.default_namespace?).to eq(false)
end end
end end
@ -341,11 +343,11 @@ describe Oga::XML::Element do
end end
it 'returns 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' expect(@n2.text).to eq('FooBar')
end end
it 'returns the text of the child node' do it 'returns the text of the child node' do
@n1.text.should == 'Foo' expect(@n1.text).to eq('Foo')
end end
end end
@ -359,11 +361,11 @@ describe Oga::XML::Element do
end end
it 'returns the inner text of the parent node' do it 'returns the inner text of the parent node' do
@n2.inner_text.should == 'Bar' expect(@n2.inner_text).to eq('Bar')
end end
it 'returns the inner text of the child node' do it 'returns the inner text of the child node' do
@n1.inner_text.should == 'Foo' expect(@n1.inner_text).to eq('Foo')
end end
end end
@ -374,7 +376,7 @@ describe Oga::XML::Element do
it 'sets 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' expect(@element.inner_text).to eq('foo')
end end
it 'removes all existing nodes before inserting a new text node' do it 'removes all existing nodes before inserting a new text node' do
@ -383,13 +385,13 @@ describe Oga::XML::Element do
@element.inner_text = 'bar' @element.inner_text = 'bar'
@element.children.length.should == 1 expect(@element.children.length).to eq(1)
end end
it 'sets the parent node of the newly inserted text node' do it 'sets the parent node of the newly inserted text node' do
@element.inner_text = 'foo' @element.inner_text = 'foo'
@element.children[0].parent.should == @element expect(@element.children[0].parent).to eq(@element)
end end
end end
@ -402,13 +404,13 @@ describe Oga::XML::Element do
end end
it 'returns 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) expect(@element.text_nodes).to eq(node_set(@t1, @t2))
end end
end end
describe '#to_xml' do describe '#to_xml' do
it 'generates the corresponding XML' do it 'generates the corresponding XML' do
described_class.new(:name => 'p').to_xml.should == '<p />' expect(described_class.new(:name => 'p').to_xml).to eq('<p />')
end end
it 'includes the namespace if present' do it 'includes the namespace if present' do
@ -419,7 +421,7 @@ describe Oga::XML::Element do
:children => [Oga::XML::Text.new(:text => 'Foo')] :children => [Oga::XML::Text.new(:text => 'Foo')]
) )
instance.to_xml.should == '<foo:p>Foo</foo:p>' expect(instance.to_xml).to eq('<foo:p>Foo</foo:p>')
end end
it 'includes a single attribute if present' do it 'includes a single attribute if present' do
@ -430,7 +432,7 @@ describe Oga::XML::Element do
] ]
) )
instance.to_xml.should == '<p key="value" />' expect(instance.to_xml).to eq('<p key="value" />')
end end
it 'includes multiple attributes if present' do it 'includes multiple attributes if present' do
@ -442,7 +444,7 @@ describe Oga::XML::Element do
] ]
) )
instance.to_xml.should == '<p key1="value1" key2="value2" />' expect(instance.to_xml).to eq('<p key1="value1" key2="value2" />')
end end
it 'includes the child nodes if present' do it 'includes the child nodes if present' do
@ -451,7 +453,7 @@ describe Oga::XML::Element do
:children => [Oga::XML::Comment.new(:text => 'foo')] :children => [Oga::XML::Comment.new(:text => 'foo')]
) )
instance.to_xml.should == '<p><!--foo--></p>' expect(instance.to_xml).to eq('<p><!--foo--></p>')
end end
it 'generates the corresponding XML when using a default namespace' do it 'generates the corresponding XML when using a default namespace' do
@ -461,28 +463,28 @@ describe Oga::XML::Element do
:namespaces => {'xmlns' => namespace} :namespaces => {'xmlns' => namespace}
) )
instance.to_xml.should == '<foo />' expect(instance.to_xml).to eq('<foo />')
end end
it 'generates 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>' expect(element.to_xml).to eq('<script></script>')
end end
it 'generates 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])
element.to_xml.should == '<link>' expect(element.to_xml).to eq('<link>')
end end
it 'generates the XML for an empty explicitly closed HTML element' do it 'generates the XML for an empty explicitly closed HTML element' do
element = described_class.new(:name => 'html') element = described_class.new(:name => 'html')
document = Oga::XML::Document.new(:type => :html, :children => [element]) document = Oga::XML::Document.new(:type => :html, :children => [element])
element.to_xml.should == '<html></html>' expect(element.to_xml).to eq('<html></html>')
end end
end end
@ -490,7 +492,7 @@ describe Oga::XML::Element do
it 'inspects 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")' expect(node.inspect).to eq('Element(name: "a")')
end end
it 'inspects a node with attributes and children' do it 'inspects a node with attributes and children' do
@ -500,8 +502,8 @@ describe Oga::XML::Element do
:attributes => [Oga::XML::Attribute.new(:name => 'x', :value => 'y')] :attributes => [Oga::XML::Attribute.new(:name => 'x', :value => 'y')]
) )
node.inspect.should == 'Element(name: "p" attributes: ' \ expect(node.inspect).to eq('Element(name: "p" attributes: ' \
'[Attribute(name: "x" value: "y")] children: NodeSet(Comment("foo")))' '[Attribute(name: "x" value: "y")] children: NodeSet(Comment("foo")))')
end end
it 'inspects a node with a namespace' do it 'inspects a node with a namespace' do
@ -511,8 +513,8 @@ describe Oga::XML::Element do
:namespaces => {'x' => Oga::XML::Namespace.new(:name => 'x')} :namespaces => {'x' => Oga::XML::Namespace.new(:name => 'x')}
) )
node.inspect.should == 'Element(name: "p" ' \ expect(node.inspect).to eq('Element(name: "p" ' \
'namespace: Namespace(name: "x" uri: nil))' 'namespace: Namespace(name: "x" uri: nil))')
end end
end end
@ -524,38 +526,38 @@ describe Oga::XML::Element do
end end
it 'returns a Namespace instance' do it 'returns a Namespace instance' do
@element.namespaces['foo'].is_a?(Oga::XML::Namespace).should == true expect(@element.namespaces['foo'].is_a?(Oga::XML::Namespace)).to eq(true)
end end
it 'sets the name of the namespace' do it 'sets the name of the namespace' do
@element.namespaces['foo'].name.should == 'foo' expect(@element.namespaces['foo'].name).to eq('foo')
end end
it 'sets the URI of the namespace' do it 'sets the URI of the namespace' do
@element.namespaces['foo'].uri.should == 'http://example.com' expect(@element.namespaces['foo'].uri).to eq('http://example.com')
end end
it 'raises 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) expect(block).to raise_error(ArgumentError)
end end
it 'flushes the cache when registering a namespace' do it 'flushes the cache when registering a namespace' do
@element.available_namespaces.should == { expect(@element.available_namespaces).to eq({
'foo' => @element.namespaces['foo'] 'foo' => @element.namespaces['foo']
} })
@element.register_namespace('bar', 'http://exmaple.com') @element.register_namespace('bar', 'http://exmaple.com')
@element.available_namespaces.should == { expect(@element.available_namespaces).to eq({
'foo' => @element.namespaces['foo'], 'foo' => @element.namespaces['foo'],
'bar' => @element.namespaces['bar'] 'bar' => @element.namespaces['bar']
} })
end end
it 'does not flush the cache when "flush" is set to false' do it 'does not flush the cache when "flush" is set to false' do
@element.should_not receive(:flush_namespaces_cache) expect(@element).not_to receive(:flush_namespaces_cache)
@element.register_namespace('bar', 'http://example.com', false) @element.register_namespace('bar', 'http://example.com', false)
end end
@ -578,23 +580,23 @@ describe Oga::XML::Element do
end end
it 'inherits the "foo" namespace from the parent' do it 'inherits the "foo" namespace from the parent' do
@child_ns['foo'].uri.should == 'bar' expect(@child_ns['foo'].uri).to eq('bar')
end end
it 'overwrites the "baz" namespace in the child' do it 'overwrites the "baz" namespace in the child' do
@child_ns['baz'].uri.should == 'xxx' expect(@child_ns['baz'].uri).to eq('xxx')
end end
it 'returns the "foo" namespace for the parent' do it 'returns the "foo" namespace for the parent' do
@parent_ns['foo'].uri.should == 'bar' expect(@parent_ns['foo'].uri).to eq('bar')
end end
it 'returns the "baz" namespace for the parent' do it 'returns the "baz" namespace for the parent' do
@parent_ns['baz'].uri.should == 'yyy' expect(@parent_ns['baz'].uri).to eq('yyy')
end end
it 'does not modify the list of direct namespaces' do it 'does not modify the list of direct namespaces' do
@child.namespaces.key?('foo').should == false expect(@child.namespaces.key?('foo')).to eq(false)
end end
describe 'in an HTML document' do describe 'in an HTML document' do
@ -603,28 +605,28 @@ describe Oga::XML::Element do
el = described_class.new(:namespaces => {'xmlns' => ns}) el = described_class.new(:namespaces => {'xmlns' => ns})
doc = Oga::XML::Document.new(:type => :html, :children => [el]) doc = Oga::XML::Document.new(:type => :html, :children => [el])
el.available_namespaces.should == {} expect(el.available_namespaces).to eq({})
end end
end end
end end
describe '#self_closing?' do describe '#self_closing?' do
it 'returns 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 expect(described_class.new(:name => 'foo')).to be_self_closing
end end
it 'returns 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 expect(node).not_to be_self_closing
end end
it 'returns 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 expect(element).to be_self_closing
end end
it 'returns false for a non empty HTML element' do it 'returns false for a non empty HTML element' do
@ -632,7 +634,7 @@ describe Oga::XML::Element do
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])
element.should_not be_self_closing expect(element).not_to be_self_closing
end end
end end
@ -640,22 +642,22 @@ describe Oga::XML::Element do
it 'flushes the namespaces cache of the current element' do it 'flushes the namespaces cache of the current element' do
element = described_class.new(:name => 'a') element = described_class.new(:name => 'a')
element.available_namespaces.should == {} expect(element.available_namespaces).to eq({})
element.register_namespace('foo', 'bar', false) element.register_namespace('foo', 'bar', false)
element.flush_namespaces_cache element.flush_namespaces_cache
element.available_namespaces.should == { expect(element.available_namespaces).to eq({
'foo' => element.namespaces['foo'] 'foo' => element.namespaces['foo']
} })
end end
it 'flushes the namespace cache of all child elements' do it 'flushes the namespace cache of all child elements' do
child = described_class.new(:name => 'b') child = described_class.new(:name => 'b')
parent = described_class.new(:name => 'a', :children => [child]) parent = described_class.new(:name => 'a', :children => [child])
child.should_receive(:flush_namespaces_cache) expect(child).to receive(:flush_namespaces_cache)
parent.flush_namespaces_cache parent.flush_namespaces_cache
end end
@ -666,7 +668,7 @@ describe Oga::XML::Element do
it 'returns a String' do it 'returns a String' do
element = described_class.new(:namespace_name => 'foo', :name => 'bar') element = described_class.new(:namespace_name => 'foo', :name => 'bar')
element.expanded_name.should == 'foo:bar' expect(element.expanded_name).to eq('foo:bar')
end end
end end
@ -674,18 +676,18 @@ describe Oga::XML::Element do
it 'returns a String' do it 'returns a String' do
element = described_class.new(:name => 'bar') element = described_class.new(:name => 'bar')
element.expanded_name.should == 'bar' expect(element.expanded_name).to eq('bar')
end end
end end
end end
describe '#literal_html_name?' do describe '#literal_html_name?' do
it 'returns true for an element name matching one of the literal HTML elements' do it 'returns true for an element name matching one of the literal HTML elements' do
described_class.new(:name => 'script').literal_html_name?.should == true expect(described_class.new(:name => 'script').literal_html_name?).to eq(true)
end end
it 'returns false for an element name not matching one of the literal HTML elements' do it 'returns false for an element name not matching one of the literal HTML elements' do
described_class.new(:name => 'foo').literal_html_name?.should == false expect(described_class.new(:name => 'foo').literal_html_name?).to eq(false)
end end
end end
end end

View File

@ -3,147 +3,147 @@ require 'spec_helper'
describe Oga::XML::Entities do describe Oga::XML::Entities do
describe 'decode' do describe 'decode' do
it 'decodes &lt; into <' do it 'decodes &lt; into <' do
described_class.decode('&lt;').should == '<' expect(described_class.decode('&lt;')).to eq('<')
end end
it 'decodes &gt; into >' do it 'decodes &gt; into >' do
described_class.decode('&gt;').should == '>' expect(described_class.decode('&gt;')).to eq('>')
end end
it "decodes &apos; into '" do it "decodes &apos; into '" do
described_class.decode('&apos;').should == "'" expect(described_class.decode('&apos;')).to eq("'")
end end
it 'decodes &quot; into "' do it 'decodes &quot; into "' do
described_class.decode('&quot;').should == '"' expect(described_class.decode('&quot;')).to eq('"')
end end
it 'decodes &amp; into &' do it 'decodes &amp; into &' do
described_class.decode('&amp;').should == '&' expect(described_class.decode('&amp;')).to eq('&')
end end
it 'decodes &#60; into <' do it 'decodes &#60; into <' do
described_class.decode('&#60;').should == '<' expect(described_class.decode('&#60;')).to eq('<')
end end
it 'decodes &#62; into >' do it 'decodes &#62; into >' do
described_class.decode('&#62;').should == '>' expect(described_class.decode('&#62;')).to eq('>')
end end
it "decodes &#39; into '" do it "decodes &#39; into '" do
described_class.decode('&#39;').should == "'" expect(described_class.decode('&#39;')).to eq("'")
end end
it 'decodes &#34; into "' do it 'decodes &#34; into "' do
described_class.decode('&#34;').should == '"' expect(described_class.decode('&#34;')).to eq('"')
end end
it 'decodes &#38; into &' do it 'decodes &#38; into &' do
described_class.decode('&#38;').should == '&' expect(described_class.decode('&#38;')).to eq('&')
end end
it 'decodes &#38;#60; into &#60;' do it 'decodes &#38;#60; into &#60;' do
described_class.decode('&#38;#60;').should == '&#60;' expect(described_class.decode('&#38;#60;')).to eq('&#60;')
end end
it 'decodes &#38;#38; into &#38;' do it 'decodes &#38;#38; into &#38;' do
described_class.decode('&#38;#38;').should == '&#38;' expect(described_class.decode('&#38;#38;')).to eq('&#38;')
end end
it 'decodes &amp;gt; into &gt;' do it 'decodes &amp;gt; into &gt;' do
described_class.decode('&amp;gt;').should == '&gt;' expect(described_class.decode('&amp;gt;')).to eq('&gt;')
end end
it 'decodes &amp;&amp;gt; into &>' do it 'decodes &amp;&amp;gt; into &>' do
described_class.decode('&amp;&amp;gt;').should == '&&gt;' expect(described_class.decode('&amp;&amp;gt;')).to eq('&&gt;')
end end
it 'decodes &amp;lt; into <' do it 'decodes &amp;lt; into <' do
described_class.decode('&amp;lt;').should == '&lt;' expect(described_class.decode('&amp;lt;')).to eq('&lt;')
end end
it 'decodes &amp;&amp;lt; into &<' do it 'decodes &amp;&amp;lt; into &<' do
described_class.decode('&amp;&amp;lt;').should == '&&lt;' expect(described_class.decode('&amp;&amp;lt;')).to eq('&&lt;')
end end
it 'decodes &#x3C; into <' do it 'decodes &#x3C; into <' do
described_class.decode('&#x3C;').should == '<' expect(described_class.decode('&#x3C;')).to eq('<')
end end
it 'decodes numeric entities starting with a 0' do it 'decodes numeric entities starting with a 0' do
described_class.decode('&#038;').should == '&' expect(described_class.decode('&#038;')).to eq('&')
end end
it 'preserves entity-like tokens' do it 'preserves entity-like tokens' do
described_class.decode('&#TAB;').should == '&#TAB;' expect(described_class.decode('&#TAB;')).to eq('&#TAB;')
end end
it 'preserves entity-like hex tokens' do it 'preserves entity-like hex tokens' do
described_class.decode('&#x;').should == '&#x;' expect(described_class.decode('&#x;')).to eq('&#x;')
end end
it 'preserves entity-like letters in non-hex mode' do it 'preserves entity-like letters in non-hex mode' do
described_class.decode('&#123A;').should == '&#123A;' expect(described_class.decode('&#123A;')).to eq('&#123A;')
end end
it "preserves numeric entities when they can't be decoded" do it "preserves numeric entities when they can't be decoded" do
described_class.decode('&#2013265920;').should == '&#2013265920;' expect(described_class.decode('&#2013265920;')).to eq('&#2013265920;')
end end
it "preserves hex entities when they can't be decoded" do it "preserves hex entities when they can't be decoded" do
described_class.decode('&#xffffff;').should == '&#xffffff;' expect(described_class.decode('&#xffffff;')).to eq('&#xffffff;')
end end
end end
describe 'encode' do describe 'encode' do
it 'encodes & as &amp;' do it 'encodes & as &amp;' do
described_class.encode('&').should == '&amp;' expect(described_class.encode('&')).to eq('&amp;')
end end
it 'does not encode double quotes' do it 'does not encode double quotes' do
described_class.encode('"').should == '"' expect(described_class.encode('"')).to eq('"')
end end
it 'does not encode single quotes' do it 'does not encode single quotes' do
described_class.encode("'").should == "'" expect(described_class.encode("'")).to eq("'")
end end
it 'encodes < as &lt;' do it 'encodes < as &lt;' do
described_class.encode('<').should == '&lt;' expect(described_class.encode('<')).to eq('&lt;')
end end
it 'encodes > as &gt;' do it 'encodes > as &gt;' do
described_class.encode('>').should == '&gt;' expect(described_class.encode('>')).to eq('&gt;')
end end
it 'encodes &gt; as &amp;gt;' do it 'encodes &gt; as &amp;gt;' do
described_class.encode('&gt;').should == '&amp;gt;' expect(described_class.encode('&gt;')).to eq('&amp;gt;')
end end
it 'encodes &lt; as &amp;lt;' do it 'encodes &lt; as &amp;lt;' do
described_class.encode('&lt;').should == '&amp;lt;' expect(described_class.encode('&lt;')).to eq('&amp;lt;')
end end
end end
describe 'encode_attribute' do describe 'encode_attribute' do
it 'encodes & as &amp;' do it 'encodes & as &amp;' do
described_class.encode_attribute('&').should == '&amp;' expect(described_class.encode_attribute('&')).to eq('&amp;')
end end
it 'encodes > as &gt;' do it 'encodes > as &gt;' do
described_class.encode_attribute('>').should == '&gt;' expect(described_class.encode_attribute('>')).to eq('&gt;')
end end
it 'encodes < as &gt;' do it 'encodes < as &gt;' do
described_class.encode_attribute('<').should == '&lt;' expect(described_class.encode_attribute('<')).to eq('&lt;')
end end
it 'encodes a single quote as &apos;' do it 'encodes a single quote as &apos;' do
described_class.encode_attribute("'").should == '&apos;' expect(described_class.encode_attribute("'")).to eq('&apos;')
end end
it 'encodes a double quote as &quot;' do it 'encodes a double quote as &quot;' do
described_class.encode_attribute('"').should == '&quot;' expect(described_class.encode_attribute('"')).to eq('&quot;')
end end
end end
end end

View File

@ -4,7 +4,7 @@ describe Oga::XML::Generator do
describe '#to_xml' do describe '#to_xml' do
describe 'using an unsupported root type' do describe 'using an unsupported root type' do
it 'raises TypeError' do it 'raises TypeError' do
-> { described_class.new(:foo).to_xml }.should raise_error(TypeError) expect { described_class.new(:foo).to_xml }.to raise_error(TypeError)
end end
end end
@ -15,7 +15,7 @@ describe Oga::XML::Generator do
output = described_class.new(element).to_xml output = described_class.new(element).to_xml
output.should == '<foo attr="value" />' expect(output).to eq('<foo attr="value" />')
end end
end end
@ -25,7 +25,7 @@ describe Oga::XML::Generator do
doc = Oga::XML::Document.new(children: [element]) doc = Oga::XML::Document.new(children: [element])
output = described_class.new(doc).to_xml output = described_class.new(doc).to_xml
output.should == '<foo />' expect(output).to eq('<foo />')
end end
end end
@ -35,7 +35,7 @@ describe Oga::XML::Generator do
doc = Oga::XML::Document.new(children: [element], type: :html) doc = Oga::XML::Document.new(children: [element], type: :html)
output = described_class.new(doc).to_xml output = described_class.new(doc).to_xml
output.should == '<foo></foo>' expect(output).to eq('<foo></foo>')
end end
end end
@ -46,7 +46,7 @@ describe Oga::XML::Generator do
doc = Oga::XML::Document.new(children: [el1], type: :html) doc = Oga::XML::Document.new(children: [el1], type: :html)
output = described_class.new(doc).to_xml output = described_class.new(doc).to_xml
output.should == '<foo><bar></bar></foo>' expect(output).to eq('<foo><bar></bar></foo>')
end end
end end
@ -65,7 +65,7 @@ describe Oga::XML::Generator do
output = described_class.new(root).to_xml output = described_class.new(root).to_xml
output.should == '<root><a /><b><c /></b></root>' expect(output).to eq('<root><a /><b><c /></b></root>')
end end
end end
@ -75,7 +75,7 @@ describe Oga::XML::Generator do
element = Oga::XML::Element.new(name: 'foo') element = Oga::XML::Element.new(name: 'foo')
document = Oga::XML::Document.new(children: [text, element]) document = Oga::XML::Document.new(children: [text, element])
described_class.new(text).to_xml.should == "\n" expect(described_class.new(text).to_xml).to eq("\n")
end end
end end
@ -85,7 +85,7 @@ describe Oga::XML::Generator do
element = Oga::XML::Element.new(name: 'foo') element = Oga::XML::Element.new(name: 'foo')
document = Oga::XML::Document.new(children: [text, element]) document = Oga::XML::Document.new(children: [text, element])
described_class.new(element).to_xml.should == '<foo />' expect(described_class.new(element).to_xml).to eq('<foo />')
end end
end end
@ -95,8 +95,8 @@ describe Oga::XML::Generator do
element2 = Oga::XML::Element.new(name: 'b') element2 = Oga::XML::Element.new(name: 'b')
document = Oga::XML::Document.new(children: [element1, element2]) document = Oga::XML::Document.new(children: [element1, element2])
described_class.new(element1).to_xml.should == '<a />' expect(described_class.new(element1).to_xml).to eq('<a />')
described_class.new(element2).to_xml.should == '<b />' expect(described_class.new(element2).to_xml).to eq('<b />')
end end
end end
@ -123,7 +123,7 @@ describe Oga::XML::Generator do
doc = Oga.parse_html(input) doc = Oga.parse_html(input)
output = described_class.new(doc) output = described_class.new(doc)
output.to_xml.should == input expect(output.to_xml).to eq(input)
end end
end end
@ -133,7 +133,7 @@ describe Oga::XML::Generator do
img = Oga::XML::Element.new(name: 'img') img = Oga::XML::Element.new(name: 'img')
doc = Oga::XML::Document.new(children: [img], type: :xml) doc = Oga::XML::Document.new(children: [img], type: :xml)
doc.to_xml.should == '<img />' expect(doc.to_xml).to eq('<img />')
end end
end end
@ -143,7 +143,7 @@ describe Oga::XML::Generator do
img = Oga::XML::Element.new(name: 'img', children: [text]) img = Oga::XML::Element.new(name: 'img', children: [text])
doc = Oga::XML::Document.new(children: [img], type: :xml) doc = Oga::XML::Document.new(children: [img], type: :xml)
doc.to_xml.should == '<img>kittens</img>' expect(doc.to_xml).to eq('<img>kittens</img>')
end end
end end
end end
@ -154,7 +154,7 @@ describe Oga::XML::Generator do
img = Oga::XML::Element.new(name: 'img') img = Oga::XML::Element.new(name: 'img')
doc = Oga::XML::Document.new(children: [img], type: :html) doc = Oga::XML::Document.new(children: [img], type: :html)
doc.to_xml.should == '<img>' expect(doc.to_xml).to eq('<img>')
end end
end end
@ -164,7 +164,7 @@ describe Oga::XML::Generator do
img = Oga::XML::Element.new(name: 'img', children: [text]) img = Oga::XML::Element.new(name: 'img', children: [text])
doc = Oga::XML::Document.new(children: [img], type: :html) doc = Oga::XML::Document.new(children: [img], type: :html)
doc.to_xml.should == '<img>kittens</img>' expect(doc.to_xml).to eq('<img>kittens</img>')
end end
end end
end end

View File

@ -3,40 +3,40 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'CDATA tags' do describe 'CDATA tags' do
it 'lexes a CDATA tag' do it 'lexes a CDATA tag' do
lex('<![CDATA[foo]]>').should == [ expect(lex('<![CDATA[foo]]>')).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, 'foo', 1], [:T_CDATA_BODY, 'foo', 1],
[:T_CDATA_END, nil, 1] [:T_CDATA_END, nil, 1]
] ])
end end
it 'lexes tags inside CDATA tags as regular text' do it 'lexes tags inside CDATA tags as regular text' do
lex('<![CDATA[<p>Foo</p>]]>').should == [ expect(lex('<![CDATA[<p>Foo</p>]]>')).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, '<p>Foo</p>', 1], [:T_CDATA_BODY, '<p>Foo</p>', 1],
[:T_CDATA_END, nil, 1] [:T_CDATA_END, nil, 1]
] ])
end end
it 'lexes a single bracket inside a CDATA tag' do it 'lexes a single bracket inside a CDATA tag' do
lex('<![CDATA[]]]>').should == [ expect(lex('<![CDATA[]]]>')).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, ']', 1], [:T_CDATA_BODY, ']', 1],
[:T_CDATA_END, nil, 1] [:T_CDATA_END, nil, 1]
] ])
end end
it 'lexes double brackets inside a CDATA tag' do it 'lexes double brackets inside a CDATA tag' do
lex('<![CDATA[]]]]>').should == [ expect(lex('<![CDATA[]]]]>')).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, ']', 1], [:T_CDATA_BODY, ']', 1],
[:T_CDATA_BODY, ']', 1], [:T_CDATA_BODY, ']', 1],
[:T_CDATA_END, nil, 1] [:T_CDATA_END, nil, 1]
] ])
end end
it 'lexes 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 == [ expect(lex('<a><![CDATA[foo]]><b><![CDATA[bar]]></b></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, 'foo', 1], [:T_CDATA_BODY, 'foo', 1],
@ -47,58 +47,58 @@ describe Oga::XML::Lexer do
[:T_CDATA_END, nil, 1], [:T_CDATA_END, nil, 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
it 'lexes a CDATA tag containing a newline after the open tag' do it 'lexes a CDATA tag containing a newline after the open tag' do
lex("<![CDATA[\nfoo]]>").should == [ expect(lex("<![CDATA[\nfoo]]>")).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, "\nfoo", 1], [:T_CDATA_BODY, "\nfoo", 1],
[:T_CDATA_END, nil, 2] [:T_CDATA_END, nil, 2]
] ])
end end
it 'lexes a CDATA tag containing a newline before the closing tag' do it 'lexes a CDATA tag containing a newline before the closing tag' do
lex("<![CDATA[foo\n]]>").should == [ expect(lex("<![CDATA[foo\n]]>")).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, "foo\n", 1], [:T_CDATA_BODY, "foo\n", 1],
[:T_CDATA_END, nil, 2] [:T_CDATA_END, nil, 2]
] ])
end end
it 'lexes a CDATA tag with the body surrounded by newlines' do it 'lexes a CDATA tag with the body surrounded by newlines' do
lex("<![CDATA[\nfoo\n]]>").should == [ expect(lex("<![CDATA[\nfoo\n]]>")).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, "\nfoo\n", 1], [:T_CDATA_BODY, "\nfoo\n", 1],
[:T_CDATA_END, nil, 3] [:T_CDATA_END, nil, 3]
] ])
end end
describe 'using an IO as input' do describe 'using an IO as input' do
it 'lexes a CDATA tag containing a newline after the open tag' do it 'lexes a CDATA tag containing a newline after the open tag' do
lex_stringio("<![CDATA[\nfoo]]>").should == [ expect(lex_stringio("<![CDATA[\nfoo]]>")).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, "\n", 1], [:T_CDATA_BODY, "\n", 1],
[:T_CDATA_BODY, "foo", 2], [:T_CDATA_BODY, "foo", 2],
[:T_CDATA_END, nil, 2] [:T_CDATA_END, nil, 2]
] ])
end end
it 'lexes a CDATA tag containing a newline before the closing tag' do it 'lexes a CDATA tag containing a newline before the closing tag' do
lex_stringio("<![CDATA[foo\n]]>").should == [ expect(lex_stringio("<![CDATA[foo\n]]>")).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, "foo\n", 1], [:T_CDATA_BODY, "foo\n", 1],
[:T_CDATA_END, nil, 2] [:T_CDATA_END, nil, 2]
] ])
end end
it 'lexes a CDATA tag with the body surrounded by newlines' do it 'lexes a CDATA tag with the body surrounded by newlines' do
lex_stringio("<![CDATA[\nfoo\n]]>").should == [ expect(lex_stringio("<![CDATA[\nfoo\n]]>")).to eq([
[:T_CDATA_START, nil, 1], [:T_CDATA_START, nil, 1],
[:T_CDATA_BODY, "\n", 1], [:T_CDATA_BODY, "\n", 1],
[:T_CDATA_BODY, "foo\n", 2], [:T_CDATA_BODY, "foo\n", 2],
[:T_CDATA_END, nil, 3] [:T_CDATA_END, nil, 3]
] ])
end end
end end
end end

View File

@ -3,71 +3,71 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'comments' do describe 'comments' do
it 'lexes a comment' do it 'lexes a comment' do
lex('<!-- foo -->').should == [ expect(lex('<!-- foo -->')).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, ' foo ', 1], [:T_COMMENT_BODY, ' foo ', 1],
[:T_COMMENT_END, nil, 1] [:T_COMMENT_END, nil, 1]
] ])
end end
it 'lexes a comment containing -' do it 'lexes a comment containing -' do
lex('<!-- - -->').should == [ expect(lex('<!-- - -->')).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, ' ', 1], [:T_COMMENT_BODY, ' ', 1],
[:T_COMMENT_BODY, '-', 1], [:T_COMMENT_BODY, '-', 1],
[:T_COMMENT_BODY, ' ', 1], [:T_COMMENT_BODY, ' ', 1],
[:T_COMMENT_END, nil, 1], [:T_COMMENT_END, nil, 1],
] ])
end end
it 'lexes a comment containing --' do it 'lexes a comment containing --' do
lex('<!-- -- -->').should == [ expect(lex('<!-- -- -->')).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, ' ', 1], [:T_COMMENT_BODY, ' ', 1],
[:T_COMMENT_BODY, '-', 1], [:T_COMMENT_BODY, '-', 1],
[:T_COMMENT_BODY, '-', 1], [:T_COMMENT_BODY, '-', 1],
[:T_COMMENT_BODY, ' ', 1], [:T_COMMENT_BODY, ' ', 1],
[:T_COMMENT_END, nil, 1] [:T_COMMENT_END, nil, 1]
] ])
end end
it 'lexes a comment containing ->' do it 'lexes a comment containing ->' do
lex('<!-- -> -->').should == [ expect(lex('<!-- -> -->')).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, ' ', 1], [:T_COMMENT_BODY, ' ', 1],
[:T_COMMENT_BODY, '-', 1], [:T_COMMENT_BODY, '-', 1],
[:T_COMMENT_BODY, '> ', 1], [:T_COMMENT_BODY, '> ', 1],
[:T_COMMENT_END, nil, 1] [:T_COMMENT_END, nil, 1]
] ])
end end
it 'lexes a comment followed by text' do it 'lexes a comment followed by text' do
lex('<!---->foo').should == [ expect(lex('<!---->foo')).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_END, nil, 1], [:T_COMMENT_END, nil, 1],
[:T_TEXT, 'foo', 1] [:T_TEXT, 'foo', 1]
] ])
end end
it 'lexes text followed by a comment' do it 'lexes text followed by a comment' do
lex('foo<!---->').should == [ expect(lex('foo<!---->')).to eq([
[:T_TEXT, 'foo', 1], [:T_TEXT, 'foo', 1],
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_END, nil, 1] [:T_COMMENT_END, nil, 1]
] ])
end end
it 'lexes an element followed by a comment' do it 'lexes an element followed by a comment' do
lex('<p></p><!---->').should == [ expect(lex('<p></p><!---->')).to eq([
[:T_ELEM_NAME, 'p', 1], [:T_ELEM_NAME, 'p', 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_END, nil, 1] [:T_COMMENT_END, nil, 1]
] ])
end end
it 'lexes two comments following each other' do it 'lexes two comments following each other' do
lex('<a><!--foo--><b><!--bar--></b></a>').should == [ expect(lex('<a><!--foo--><b><!--bar--></b></a>')).to eq([
[:T_ELEM_NAME, 'a', 1], [:T_ELEM_NAME, 'a', 1],
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, 'foo', 1], [:T_COMMENT_BODY, 'foo', 1],
@ -78,34 +78,34 @@ describe Oga::XML::Lexer do
[:T_COMMENT_END, nil, 1], [:T_COMMENT_END, nil, 1],
[:T_ELEM_END, nil, 1], [:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
] ])
end end
describe 'using an IO as input' do describe 'using an IO as input' do
it 'lexes a comment containing a newline after the open tag' do it 'lexes a comment containing a newline after the open tag' do
lex_stringio("<!--\nfoo-->").should == [ expect(lex_stringio("<!--\nfoo-->")).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, "\n", 1], [:T_COMMENT_BODY, "\n", 1],
[:T_COMMENT_BODY, "foo", 2], [:T_COMMENT_BODY, "foo", 2],
[:T_COMMENT_END, nil, 2] [:T_COMMENT_END, nil, 2]
] ])
end end
it 'lexes a comment containing a newline before the closing tag' do it 'lexes a comment containing a newline before the closing tag' do
lex_stringio("<!--foo\n-->").should == [ expect(lex_stringio("<!--foo\n-->")).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, "foo\n", 1], [:T_COMMENT_BODY, "foo\n", 1],
[:T_COMMENT_END, nil, 2] [:T_COMMENT_END, nil, 2]
] ])
end end
it 'lexes a comment with the body surrounded by newlines' do it 'lexes a comment with the body surrounded by newlines' do
lex_stringio("<!--\nfoo\n-->").should == [ expect(lex_stringio("<!--\nfoo\n-->")).to eq([
[:T_COMMENT_START, nil, 1], [:T_COMMENT_START, nil, 1],
[:T_COMMENT_BODY, "\n", 1], [:T_COMMENT_BODY, "\n", 1],
[:T_COMMENT_BODY, "foo\n", 2], [:T_COMMENT_BODY, "foo\n", 2],
[:T_COMMENT_END, nil, 3] [:T_COMMENT_END, nil, 3]
] ])
end end
end end
end end

View File

@ -3,32 +3,32 @@ require 'spec_helper'
describe Oga::XML::Lexer do describe Oga::XML::Lexer do
describe 'doctypes' do describe 'doctypes' do
it 'lexes the HTML5 doctype' do it 'lexes the HTML5 doctype' do
lex('<!DOCTYPE html>').should == [ expect(lex('<!DOCTYPE html>')).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_END, nil, 1] [:T_DOCTYPE_END, nil, 1]
] ])
end end
it 'lexes a doctype containing a newline before the doctype name' do it 'lexes a doctype containing a newline before the doctype name' do
lex("<!DOCTYPE\nhtml>").should == [ expect(lex("<!DOCTYPE\nhtml>")).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 2], [:T_DOCTYPE_NAME, 'html', 2],
[:T_DOCTYPE_END, nil, 2] [:T_DOCTYPE_END, nil, 2]
] ])
end end
it 'lexes a doctype with a public ID preceded by a newline' do it 'lexes a doctype with a public ID preceded by a newline' do
lex("<!DOCTYPE html\nPUBLIC>").should == [ expect(lex("<!DOCTYPE html\nPUBLIC>")).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_TYPE, 'PUBLIC', 2], [:T_DOCTYPE_TYPE, 'PUBLIC', 2],
[:T_DOCTYPE_END, nil, 2] [:T_DOCTYPE_END, nil, 2]
] ])
end end
it 'lexes 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 == [ expect(lex('<!DOCTYPE HTML PUBLIC "foobar" "baz">')).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'HTML', 1], [:T_DOCTYPE_NAME, 'HTML', 1],
[:T_DOCTYPE_TYPE, 'PUBLIC', 1], [:T_DOCTYPE_TYPE, 'PUBLIC', 1],
@ -39,11 +39,11 @@ describe Oga::XML::Lexer do
[:T_STRING_BODY, 'baz', 1], [:T_STRING_BODY, 'baz', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_DOCTYPE_END, nil, 1] [:T_DOCTYPE_END, nil, 1]
] ])
end end
it 'lexes 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 == [ expect(lex("<!DOCTYPE HTML PUBLIC 'foobar' 'baz'>")).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'HTML', 1], [:T_DOCTYPE_NAME, 'HTML', 1],
[:T_DOCTYPE_TYPE, 'PUBLIC', 1], [:T_DOCTYPE_TYPE, 'PUBLIC', 1],
@ -54,62 +54,62 @@ describe Oga::XML::Lexer do
[:T_STRING_BODY, 'baz', 1], [:T_STRING_BODY, 'baz', 1],
[:T_STRING_SQUOTE, nil, 1], [:T_STRING_SQUOTE, nil, 1],
[:T_DOCTYPE_END, nil, 1] [:T_DOCTYPE_END, nil, 1]
] ])
end end
it 'lexes an inline doctype' do it 'lexes an inline doctype' do
lex('<!DOCTYPE html [<!ELEMENT foo>]>').should == [ expect(lex('<!DOCTYPE html [<!ELEMENT foo>]>')).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_INLINE, '<!ELEMENT foo>', 1], [:T_DOCTYPE_INLINE, '<!ELEMENT foo>', 1],
[:T_DOCTYPE_END, nil, 1] [:T_DOCTYPE_END, nil, 1]
] ])
end end
it 'lexes an empty inline doctype' do it 'lexes an empty inline doctype' do
lex('<!DOCTYPE html []>').should == [ expect(lex('<!DOCTYPE html []>')).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_END, nil, 1] [:T_DOCTYPE_END, nil, 1]
] ])
end end
it 'lexes an inline doctype containing a newline' do it 'lexes an inline doctype containing a newline' do
lex("<!DOCTYPE html [foo\n]>").should == [ expect(lex("<!DOCTYPE html [foo\n]>")).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_INLINE, "foo\n", 1], [:T_DOCTYPE_INLINE, "foo\n", 1],
[:T_DOCTYPE_END, nil, 2] [:T_DOCTYPE_END, nil, 2]
] ])
end end
it 'lexes 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 == [ expect(lex(input)).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_INLINE, "foo\n", 1], [:T_DOCTYPE_INLINE, "foo\n", 1],
[:T_DOCTYPE_END, nil, 2] [:T_DOCTYPE_END, nil, 2]
] ])
end end
it 'lexes 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 == [ expect(lex(input)).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_INLINE, "\n", 1], [:T_DOCTYPE_INLINE, "\n", 1],
[:T_DOCTYPE_INLINE, "foo", 2], [:T_DOCTYPE_INLINE, "foo", 2],
[:T_DOCTYPE_END, nil, 2] [:T_DOCTYPE_END, nil, 2]
] ])
end end
# 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.
it 'lexes 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 == [ expect(lex('<!DOCTYPE html [<!ELEMENT foo>] "foo">')).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_INLINE, '<!ELEMENT foo>', 1], [:T_DOCTYPE_INLINE, '<!ELEMENT foo>', 1],
@ -117,7 +117,7 @@ describe Oga::XML::Lexer do
[:T_STRING_BODY, 'foo', 1], [:T_STRING_BODY, 'foo', 1],
[:T_STRING_DQUOTE, nil, 1], [:T_STRING_DQUOTE, nil, 1],
[:T_DOCTYPE_END, nil, 1] [:T_DOCTYPE_END, nil, 1]
] ])
end end
end end
end end

View File

@ -13,7 +13,7 @@ describe Oga::XML::Lexer do
</html> </html>
EOF EOF
lex(html).should == [ expect(lex(html)).to eq([
[:T_DOCTYPE_START, nil, 1], [:T_DOCTYPE_START, nil, 1],
[:T_DOCTYPE_NAME, 'html', 1], [:T_DOCTYPE_NAME, 'html', 1],
[:T_DOCTYPE_END, nil, 1], [:T_DOCTYPE_END, nil, 1],
@ -45,7 +45,7 @@ describe Oga::XML::Lexer do
# </html> # </html>
[:T_ELEM_END, nil, 7], [:T_ELEM_END, nil, 7],
[:T_TEXT, "\n", 7] [:T_TEXT, "\n", 7]
] ])
end end
end end
end end

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