diff --git a/spec/oga/xpath/evaluator/calls/boolean_spec.rb b/spec/oga/xpath/evaluator/calls/boolean_spec.rb
index a3d99b2..6d42a83 100644
--- a/spec/oga/xpath/evaluator/calls/boolean_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/boolean_spec.rb
@@ -3,56 +3,55 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'boolean() function' do
before do
- @document = parse('foo')
- @evaluator = described_class.new(@document)
+ @document = parse('foo')
end
example 'return true for a non empty string literal' do
- @evaluator.evaluate('boolean("foo")').should == true
+ evaluate_xpath(@document, 'boolean("foo")').should == true
end
example 'return false for an empty string' do
- @evaluator.evaluate('boolean("")').should == false
+ evaluate_xpath(@document, 'boolean("")').should == false
end
example 'return true for a positive integer' do
- @evaluator.evaluate('boolean(10)').should == true
+ evaluate_xpath(@document, 'boolean(10)').should == true
end
example 'return true for a boolean true' do
- @evaluator.evaluate('boolean(true())').should == true
+ evaluate_xpath(@document, 'boolean(true())').should == true
end
example 'return false for a boolean false' do
- @evaluator.evaluate('boolean(false())').should == false
+ evaluate_xpath(@document, 'boolean(false())').should == false
end
example 'return true for a positive float' do
- @evaluator.evaluate('boolean(10.5)').should == true
+ evaluate_xpath(@document, 'boolean(10.5)').should == true
end
example 'return true for a negative integer' do
- @evaluator.evaluate('boolean(-5)').should == true
+ evaluate_xpath(@document, 'boolean(-5)').should == true
end
example 'return true for a negative float' do
- @evaluator.evaluate('boolean(-5.2)').should == true
+ evaluate_xpath(@document, 'boolean(-5.2)').should == true
end
example 'return false for a zero integer' do
- @evaluator.evaluate('boolean(0)').should == false
+ evaluate_xpath(@document, 'boolean(0)').should == false
end
example 'return false for a zero float' do
- @evaluator.evaluate('boolean(0.0)').should == false
+ evaluate_xpath(@document, 'boolean(0.0)').should == false
end
example 'return true for a non empty node set' do
- @evaluator.evaluate('boolean(root/a)').should == true
+ evaluate_xpath(@document, 'boolean(root/a)').should == true
end
example 'return false for an empty node set' do
- @evaluator.evaluate('boolean(root/b)').should == false
+ evaluate_xpath(@document, 'boolean(root/b)').should == false
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/ceiling_spec.rb b/spec/oga/xpath/evaluator/calls/ceiling_spec.rb
index 69cac32..d6f0193 100644
--- a/spec/oga/xpath/evaluator/calls/ceiling_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/ceiling_spec.rb
@@ -3,28 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'ceiling() function' do
before do
- @document = parse('10.123')
- @evaluator = described_class.new(@document)
+ @document = parse('10.123')
end
example 'return the ceiling of a literal number' do
- @evaluator.evaluate('ceiling(10.123)').should == 11.0
+ evaluate_xpath(@document, 'ceiling(10.123)').should == 11.0
end
example 'return the ceiling of a literal string' do
- @evaluator.evaluate('ceiling("10.123")').should == 11.0
+ evaluate_xpath(@document, 'ceiling("10.123")').should == 11.0
end
example 'return the ceiling of a node set' do
- @evaluator.evaluate('ceiling(root)').should == 11.0
+ evaluate_xpath(@document, 'ceiling(root)').should == 11.0
end
example 'return NaN for empty node sets' do
- @evaluator.evaluate('ceiling(foo)').should be_nan
+ evaluate_xpath(@document, 'ceiling(foo)').should be_nan
end
example 'return NaN for an empty literal string' do
- @evaluator.evaluate('ceiling("")').should be_nan
+ evaluate_xpath(@document, 'ceiling("")').should be_nan
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/concat_spec.rb b/spec/oga/xpath/evaluator/calls/concat_spec.rb
index 1378507..24a3b40 100644
--- a/spec/oga/xpath/evaluator/calls/concat_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/concat_spec.rb
@@ -3,28 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'concat() function' do
before do
- @document = parse('foobar')
- @evaluator = described_class.new(@document)
+ @document = parse('foobar')
end
example 'concatenate two strings' do
- @evaluator.evaluate('concat("foo", "bar")').should == 'foobar'
+ evaluate_xpath(@document, 'concat("foo", "bar")').should == 'foobar'
end
example 'concatenate two integers' do
- @evaluator.evaluate('concat(10, 20)').should == '1020'
+ evaluate_xpath(@document, 'concat(10, 20)').should == '1020'
end
example 'concatenate two floats' do
- @evaluator.evaluate('concat(10.5, 20.5)').should == '10.520.5'
+ evaluate_xpath(@document, 'concat(10.5, 20.5)').should == '10.520.5'
end
example 'concatenate two node sets' do
- @evaluator.evaluate('concat(root/a, root/b)').should == 'foobar'
+ evaluate_xpath(@document, 'concat(root/a, root/b)').should == 'foobar'
end
example 'concatenate a node set and a string' do
- @evaluator.evaluate('concat(root/a, "baz")').should == 'foobaz'
+ evaluate_xpath(@document, 'concat(root/a, "baz")').should == 'foobaz'
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/contains_spec.rb b/spec/oga/xpath/evaluator/calls/contains_spec.rb
index 3725ed4..66a5fe0 100644
--- a/spec/oga/xpath/evaluator/calls/contains_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/contains_spec.rb
@@ -3,36 +3,35 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'contains() function' do
before do
- @document = parse('foofoobar')
- @evaluator = described_class.new(@document)
+ @document = parse('foofoobar')
end
example 'return true if the 1st string contains the 2nd string' do
- @evaluator.evaluate('contains("foobar", "oo")').should == true
+ evaluate_xpath(@document, 'contains("foobar", "oo")').should == true
end
example "return false if the 1st string doesn't contain the 2nd string" do
- @evaluator.evaluate('contains("foobar", "baz")').should == false
+ evaluate_xpath(@document, 'contains("foobar", "baz")').should == false
end
example 'return true if the 1st node set contains the 2nd string' do
- @evaluator.evaluate('contains(root/a, "oo")').should == true
+ evaluate_xpath(@document, 'contains(root/a, "oo")').should == true
end
example 'return true if the 1st node set contains the 2nd node set' do
- @evaluator.evaluate('contains(root/b, root/a)').should == true
+ evaluate_xpath(@document, 'contains(root/b, root/a)').should == true
end
example "return false if the 1st node doesn't contain the 2nd node set" do
- @evaluator.evaluate('contains(root/a, root/b)').should == false
+ evaluate_xpath(@document, 'contains(root/a, root/b)').should == false
end
example 'return true if the 1st string contains the 2nd node set' do
- @evaluator.evaluate('contains("foobar", root/a)').should == true
+ evaluate_xpath(@document, 'contains("foobar", root/a)').should == true
end
example 'return true when using two empty strings' do
- @evaluator.evaluate('contains("", "")').should == true
+ evaluate_xpath(@document, 'contains("", "")').should == true
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/count_spec.rb b/spec/oga/xpath/evaluator/calls/count_spec.rb
index 379d284..5a148c9 100644
--- a/spec/oga/xpath/evaluator/calls/count_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/count_spec.rb
@@ -3,34 +3,33 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'count() function' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
end
example 'return the amount of nodes as a Float' do
- @evaluator.evaluate('count(root)').is_a?(Float).should == true
+ evaluate_xpath(@document, 'count(root)').is_a?(Float).should == true
end
example 'count the amount of nodes' do
- @evaluator.evaluate('count(root)').should == 1
+ evaluate_xpath(@document, 'count(root)').should == 1
end
example 'count the amount of nodes' do
- @evaluator.evaluate('count(root/a)').should == 2
+ evaluate_xpath(@document, 'count(root/a)').should == 2
end
example 'count the amount of nodes' do
- @evaluator.evaluate('count(root/a/b)').should == 1
+ evaluate_xpath(@document, 'count(root/a/b)').should == 1
end
example 'raise ArgumentError if no arguments are given' do
- block = lambda { @evaluator.evaluate('count()') }
+ block = -> { evaluate_xpath(@document, 'count()') }
block.should raise_error(ArgumentError)
end
example 'raise TypeError if the argument is not a NodeSet' do
- block = lambda { @evaluator.evaluate('count(1)') }
+ block = -> { evaluate_xpath(@document, 'count(1)') }
block.should raise_error(TypeError)
end
diff --git a/spec/oga/xpath/evaluator/calls/false_spec.rb b/spec/oga/xpath/evaluator/calls/false_spec.rb
index 4403d0d..787696a 100644
--- a/spec/oga/xpath/evaluator/calls/false_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/false_spec.rb
@@ -3,11 +3,11 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'false() function' do
before do
- @evaluator = described_class.new(parse(''))
+ @document = parse('')
end
example 'return false' do
- @evaluator.evaluate('false()').should == false
+ evaluate_xpath(@document, 'false()').should == false
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/floor_spec.rb b/spec/oga/xpath/evaluator/calls/floor_spec.rb
index a8208f0..86fa4d6 100644
--- a/spec/oga/xpath/evaluator/calls/floor_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/floor_spec.rb
@@ -3,28 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'floor() function' do
before do
- @document = parse('10.123')
- @evaluator = described_class.new(@document)
+ @document = parse('10.123')
end
example 'return the floor of a literal number' do
- @evaluator.evaluate('floor(10.123)').should == 10.0
+ evaluate_xpath(@document, 'floor(10.123)').should == 10.0
end
example 'return the floor of a literal string' do
- @evaluator.evaluate('floor("10.123")').should == 10.0
+ evaluate_xpath(@document, 'floor("10.123")').should == 10.0
end
example 'return the floor of a node set' do
- @evaluator.evaluate('floor(root)').should == 10.0
+ evaluate_xpath(@document, 'floor(root)').should == 10.0
end
example 'return NaN for empty node sets' do
- @evaluator.evaluate('floor(foo)').should be_nan
+ evaluate_xpath(@document, 'floor(foo)').should be_nan
end
example 'return NaN for an empty literal string' do
- @evaluator.evaluate('floor("")').should be_nan
+ evaluate_xpath(@document, 'floor("")').should be_nan
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/id_spec.rb b/spec/oga/xpath/evaluator/calls/id_spec.rb
index 7f17b75..2834bf1 100644
--- a/spec/oga/xpath/evaluator/calls/id_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/id_spec.rb
@@ -3,50 +3,22 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'id() function' do
before do
- @document = parse('a1')
- @first_a = @document.children[0].children[0]
- @second_a = @document.children[0].children[1]
- @evaluator = described_class.new(@document)
+ @document = parse('a1')
+
+ @a1 = @document.children[0].children[0]
+ @a2 = @document.children[0].children[1]
end
- context 'using a single string ID' do
- before do
- @set = @evaluator.evaluate('id("a1")')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @first_a
- end
+ example 'return a node set containing the nodes with ID "a1"' do
+ evaluate_xpath(@document, 'id("a1")').should == node_set(@a1)
end
- context 'using multiple string IDs' do
- before do
- @set = @evaluator.evaluate('id("a1 a2")')
- end
-
- it_behaves_like :node_set, :length => 2
-
- example 'return the first node' do
- @set[0].should == @first_a
- end
-
- example 'return the second node' do
- @set[1].should == @second_a
- end
+ example 'return a node set containing the nodes with ID "a1" or "a2"' do
+ evaluate_xpath(@document, 'id("a1 a2")').should == node_set(@a1, @a2)
end
- context 'using a node set' do
- before do
- @set = @evaluator.evaluate('id(root/a[2])')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @first_a
- end
+ example 'return a node set containing the nodes with an ID based on a path' do
+ evaluate_xpath(@document, 'id(root/a[2])').should == node_set(@a1)
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/lang_spec.rb b/spec/oga/xpath/evaluator/calls/lang_spec.rb
index 4298056..0474970 100644
--- a/spec/oga/xpath/evaluator/calls/lang_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/lang_spec.rb
@@ -3,44 +3,23 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'lang() function' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
+
+ @root = @document.children[0]
+ @a1 = @root.children[0]
+ @a2 = @root.children[1]
end
- context 'selecting nodes with lang="en"' do
- before do
- @set = @evaluator.evaluate('root[lang("en")]')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].should == @document.children[0]
- end
+ example 'return a node set containing nodes with language "en"' do
+ evaluate_xpath(@document, 'root[lang("en")]').should == node_set(@root)
end
- context 'selecting nodes with lang="nl"' do
- before do
- @set = @evaluator.evaluate('root/a[lang("nl")]')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the second node' do
- @set[0].should == @document.children[0].children[1]
- end
+ example 'return a node set containing the nodes with language "nl"' do
+ evaluate_xpath(@document, 'root/a[lang("nl")]').should == node_set(@a2)
end
- context 'inheriting the language from ancestor nodes' do
- before do
- @set = @evaluator.evaluate('root/a[lang("en")]')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @document.children[0].children[0]
- end
+ example 'return a node set containing the nodes with an inherited language' do
+ evaluate_xpath(@document, 'root/a[lang("en")]').should == node_set(@a1)
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/last_spec.rb b/spec/oga/xpath/evaluator/calls/last_spec.rb
index 7714ff3..6c311db 100644
--- a/spec/oga/xpath/evaluator/calls/last_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/last_spec.rb
@@ -4,14 +4,12 @@ describe Oga::XPath::Evaluator do
context 'last() function' do
before do
@document = parse('foobar')
- @second_a = @document.children[0].children[1]
- @set = described_class.new(@document).evaluate('root/a[last()]')
+
+ @a2 = @document.children[0].children[1]
end
- it_behaves_like :node_set, :length => 1
-
- example 'return the second node' do
- @set[0].should == @second_a
+ example 'return a node set containing the last node' do
+ evaluate_xpath(@document, 'root/a[last()]').should == node_set(@a2)
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/local_name_spec.rb b/spec/oga/xpath/evaluator/calls/local_name_spec.rb
index b2925d4..b25e774 100644
--- a/spec/oga/xpath/evaluator/calls/local_name_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/local_name_spec.rb
@@ -3,48 +3,38 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'local-name() function' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
end
- context 'outside predicates' do
- example 'return the local name of the node' do
- @evaluator.evaluate('local-name(root/x:a)').should == 'a'
- end
-
- example 'return the local name of the node' do
- @evaluator.evaluate('local-name(root/b)').should == 'b'
- end
-
- example 'return the local name for the "num" attribute' do
- @evaluator.evaluate('local-name(root/b/@x:num)').should == 'num'
- end
-
- example 'return only the name of the first node in the set' do
- @evaluator.evaluate('local-name(root/*)').should == 'a'
- end
-
- example 'return an empty string by default' do
- @evaluator.evaluate('local-name(foo)').should == ''
- end
-
- example 'raise a TypeError for invalid argument types' do
- block = lambda { @evaluator.evaluate('local-name("foo")') }
-
- block.should raise_error(TypeError)
- end
+ example 'return the local name of the node' do
+ evaluate_xpath(@document, 'local-name(root/x:a)').should == 'a'
end
- context 'inside predicates' do
- before do
- @set = @evaluator.evaluate('root/b[local-name()]')
- end
+ example 'return the local name of the node' do
+ evaluate_xpath(@document, 'local-name(root/b)').should == 'b'
+ end
- it_behaves_like :node_set, :length => 1
+ example 'return the local name for the "num" attribute' do
+ evaluate_xpath(@document, 'local-name(root/b/@x:num)').should == 'num'
+ end
- example 'return the node' do
- @set[0].should == @document.children[0].children[1]
- end
+ example 'return only the name of the first node in the set' do
+ evaluate_xpath(@document, 'local-name(root/*)').should == 'a'
+ end
+
+ example 'return an empty string by default' do
+ evaluate_xpath(@document, 'local-name(foo)').should == ''
+ end
+
+ example 'raise a TypeError for invalid argument types' do
+ block = -> { evaluate_xpath(@document, 'local-name("foo")') }
+
+ block.should raise_error(TypeError)
+ end
+
+ example 'return a node set containing nodes with a local name' do
+ evaluate_xpath(@document, 'root/b[local-name()]')
+ .should == node_set(@document.children[0].children[1])
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/name_spec.rb b/spec/oga/xpath/evaluator/calls/name_spec.rb
index 6a8bfb4..cf6373c 100644
--- a/spec/oga/xpath/evaluator/calls/name_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/name_spec.rb
@@ -3,48 +3,38 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'name() function' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
end
- context 'outside predicates' do
- example 'return the name of the node' do
- @evaluator.evaluate('name(root/x:a)').should == 'x:a'
- end
-
- example 'return the name of the node' do
- @evaluator.evaluate('name(root/b)').should == 'b'
- end
-
- example 'return the local name for the "num" attribute' do
- @evaluator.evaluate('name(root/b/@x:num)').should == 'x:num'
- end
-
- example 'return only the name of the first node in the set' do
- @evaluator.evaluate('name(root/*)').should == 'x:a'
- end
-
- example 'return an empty string by default' do
- @evaluator.evaluate('name(foo)').should == ''
- end
-
- example 'raise a TypeError for invalid argument types' do
- block = lambda { @evaluator.evaluate('name("foo")') }
-
- block.should raise_error(TypeError)
- end
+ example 'return the name of the node' do
+ evaluate_xpath(@document, 'name(root/x:a)').should == 'x:a'
end
- context 'inside predicates' do
- before do
- @set = @evaluator.evaluate('root/b[name()]')
- end
+ example 'return the name of the node' do
+ evaluate_xpath(@document, 'name(root/b)').should == 'b'
+ end
- it_behaves_like :node_set, :length => 1
+ example 'return the local name for the "num" attribute' do
+ evaluate_xpath(@document, 'name(root/b/@x:num)').should == 'x:num'
+ end
- example 'return the node' do
- @set[0].should == @document.children[0].children[1]
- end
+ example 'return only the name of the first node in the set' do
+ evaluate_xpath(@document, 'name(root/*)').should == 'x:a'
+ end
+
+ example 'return an empty string by default' do
+ evaluate_xpath(@document, 'name(foo)').should == ''
+ end
+
+ example 'raise a TypeError for invalid argument types' do
+ block = -> { evaluate_xpath(@document, 'name("foo")') }
+
+ block.should raise_error(TypeError)
+ end
+
+ example 'return a node set containing nodes with a name' do
+ evaluate_xpath(@document, 'root/b[name()]')
+ .should == node_set(@document.children[0].children[1])
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb b/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb
index 632da48..704a579 100644
--- a/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/namespace_uri_spec.rb
@@ -3,40 +3,30 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'namespace-uri() function' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
end
- context 'outside predicates' do
- example 'return the namespace URI of the node' do
- @evaluator.evaluate('namespace-uri(root/x:a)').should == 'y'
- end
-
- example 'return the namespace URI of the "num" attribute' do
- @evaluator.evaluate('namespace-uri(root/b/@x:num)').should == 'y'
- end
-
- example 'return an empty string when there is no namespace URI' do
- @evaluator.evaluate('namespace-uri(root/b)').should == ''
- end
-
- example 'raise TypeError for invalid argument types' do
- block = lambda { @evaluator.evaluate('namespace-uri("foo")') }
-
- block.should raise_error(TypeError)
- end
+ example 'return the namespace URI of the node' do
+ evaluate_xpath(@document, 'namespace-uri(root/x:a)').should == 'y'
end
- context 'inside predicates' do
- before do
- @set = @evaluator.evaluate('root/*[namespace-uri()]')
- end
+ example 'return the namespace URI of the "num" attribute' do
+ evaluate_xpath(@document, 'namespace-uri(root/b/@x:num)').should == 'y'
+ end
- it_behaves_like :node_set, :length => 1
+ example 'return an empty string when there is no namespace URI' do
+ evaluate_xpath(@document, 'namespace-uri(root/b)').should == ''
+ end
- example 'return the node' do
- @set[0].should == @document.children[0].children[0]
- end
+ example 'raise TypeError for invalid argument types' do
+ block = -> { evaluate_xpath(@document, 'namespace-uri("foo")') }
+
+ block.should raise_error(TypeError)
+ end
+
+ example 'return a node set containing nodes with a namespace URI' do
+ evaluate_xpath(@document, 'root/*[namespace-uri()]')
+ .should == node_set(@document.children[0].children[0])
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/normalize_space_spec.rb b/spec/oga/xpath/evaluator/calls/normalize_space_spec.rb
index 9337a8a..1f78418 100644
--- a/spec/oga/xpath/evaluator/calls/normalize_space_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/normalize_space_spec.rb
@@ -3,38 +3,28 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'normalize-space() function' do
before do
- @document = parse(' fo o ')
- @evaluator = described_class.new(@document)
+ @document = parse(' fo o ')
end
- context 'outside predicates' do
- example 'normalize a literal string' do
- @evaluator.evaluate('normalize-space(" fo o ")').should == 'fo o'
- end
-
- example 'normalize a string in a node set' do
- @evaluator.evaluate('normalize-space(root/a)').should == 'fo o'
- end
-
- example 'normalize an integer' do
- @evaluator.evaluate('normalize-space(10)').should == '10'
- end
-
- example 'normalize a float' do
- @evaluator.evaluate('normalize-space(10.5)').should == '10.5'
- end
+ example 'normalize a literal string' do
+ evaluate_xpath(@document, 'normalize-space(" fo o ")').should == 'fo o'
end
- context 'inside predicates' do
- before do
- @set = @evaluator.evaluate('root/a[normalize-space()]')
- end
+ example 'normalize a string in a node set' do
+ evaluate_xpath(@document, 'normalize-space(root/a)').should == 'fo o'
+ end
- it_behaves_like :node_set, :length => 1
+ example 'normalize an integer' do
+ evaluate_xpath(@document, 'normalize-space(10)').should == '10'
+ end
- example 'return the node' do
- @set[0].should == @document.children[0].children[0]
- end
+ example 'normalize a float' do
+ evaluate_xpath(@document, 'normalize-space(10.5)').should == '10.5'
+ end
+
+ example 'return a node set containing nodes with normalized spaces' do
+ evaluate_xpath(@document, 'root/a[normalize-space()]')
+ .should == node_set(@document.children[0].children[0])
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/not_spec.rb b/spec/oga/xpath/evaluator/calls/not_spec.rb
index 2edda52..54a8775 100644
--- a/spec/oga/xpath/evaluator/calls/not_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/not_spec.rb
@@ -3,24 +3,23 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'not() function' do
before do
- @document = parse('foo')
- @evaluator = described_class.new(@document)
+ @document = parse('foo')
end
example 'return false when the argument is a non-zero integer' do
- @evaluator.evaluate('not(10)').should == false
+ evaluate_xpath(@document, 'not(10)').should == false
end
example 'return true when the argument is a zero integer' do
- @evaluator.evaluate('not(0)').should == true
+ evaluate_xpath(@document, 'not(0)').should == true
end
example 'return false when the argument is a non-empty node set' do
- @evaluator.evaluate('not(root)').should == false
+ evaluate_xpath(@document, 'not(root)').should == false
end
example 'return itrue when the argument is an empty node set' do
- @evaluator.evaluate('not(foo)').should == true
+ evaluate_xpath(@document, 'not(foo)').should == true
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/number_spec.rb b/spec/oga/xpath/evaluator/calls/number_spec.rb
index 887dfef..6011b9e 100644
--- a/spec/oga/xpath/evaluator/calls/number_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/number_spec.rb
@@ -3,48 +3,47 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'number() function' do
before do
- @document = parse('1010.5')
- @evaluator = described_class.new(@document)
+ @document = parse('1010.5')
end
example 'convert a literal string to a number' do
- @evaluator.evaluate('number("10")').should == 10.0
+ evaluate_xpath(@document, 'number("10")').should == 10.0
end
example 'convert a literal string with deciamsl to a number' do
- @evaluator.evaluate('number("10.5")').should == 10.5
+ evaluate_xpath(@document, 'number("10.5")').should == 10.5
end
example 'convert boolean true to a number' do
- @evaluator.evaluate('number(true())').should == 1.0
+ evaluate_xpath(@document, 'number(true())').should == 1.0
end
example 'convert boolean false to a number' do
- @evaluator.evaluate('number(false())').should be_zero
+ evaluate_xpath(@document, 'number(false())').should be_zero
end
example 'convert a node set to a number' do
- @evaluator.evaluate('number(root/a)').should == 10.0
+ evaluate_xpath(@document, 'number(root/a)').should == 10.0
end
example 'convert a node set with decimals to a number' do
- @evaluator.evaluate('number(root/b)').should == 10.5
+ evaluate_xpath(@document, 'number(root/b)').should == 10.5
end
example 'convert a comment to a number' do
- @evaluator.evaluate('number(root/comment())').should == 10.0
+ evaluate_xpath(@document, 'number(root/comment())').should == 10.0
end
example 'return NaN for values that can not be converted to floats' do
- @evaluator.evaluate('number("a")').should be_nan
+ evaluate_xpath(@document, 'number("a")').should be_nan
end
example 'return NaN for empty node sets' do
- @evaluator.evaluate('number(foo)').should be_nan
+ evaluate_xpath(@document, 'number(foo)').should be_nan
end
example 'return NaN for empty strings' do
- @evaluator.evaluate('number("")').should be_nan
+ evaluate_xpath(@document, 'number("")').should be_nan
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/position_spec.rb b/spec/oga/xpath/evaluator/calls/position_spec.rb
index b26ebf8..28692fc 100644
--- a/spec/oga/xpath/evaluator/calls/position_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/position_spec.rb
@@ -4,17 +4,19 @@ describe Oga::XPath::Evaluator do
context 'position() function' do
before do
@document = parse('foobar')
- @set = described_class.new(@document).evaluate('root/a[position()]')
+
+ @a1 = @document.children[0].children[0]
+ @a2 = @document.children[0].children[1]
end
- it_behaves_like :node_set, :length => 2
-
- example 'return the first node' do
- @set[0].should == @document.children[0].children[0]
+ example 'return a node set containing the first node' do
+ evaluate_xpath(@document, 'root/a[position() = 1]')
+ .should == node_set(@a1)
end
- example 'return the second node' do
- @set[1].should == @document.children[0].children[1]
+ example 'return a node set containing the second node' do
+ evaluate_xpath(@document, 'root/a[position() = 2]')
+ .should == node_set(@a2)
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/round_spec.rb b/spec/oga/xpath/evaluator/calls/round_spec.rb
index 2d0ea6c..bafbcfd 100644
--- a/spec/oga/xpath/evaluator/calls/round_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/round_spec.rb
@@ -3,28 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'round() function' do
before do
- @document = parse('10.123')
- @evaluator = described_class.new(@document)
+ @document = parse('10.123')
end
example 'return the rounded value of a literal number' do
- @evaluator.evaluate('round(10.123)').should == 10.0
+ evaluate_xpath(@document, 'round(10.123)').should == 10.0
end
example 'return the rounded value of a literal string' do
- @evaluator.evaluate('round("10.123")').should == 10.0
+ evaluate_xpath(@document, 'round("10.123")').should == 10.0
end
example 'return the rounded value of a node set' do
- @evaluator.evaluate('round(root)').should == 10.0
+ evaluate_xpath(@document, 'round(root)').should == 10.0
end
example 'return NaN for empty node sets' do
- @evaluator.evaluate('round(foo)').should be_nan
+ evaluate_xpath(@document, 'round(foo)').should be_nan
end
example 'return NaN for an empty literal string' do
- @evaluator.evaluate('round("")').should be_nan
+ evaluate_xpath(@document, 'round("")').should be_nan
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/starts_with_spec.rb b/spec/oga/xpath/evaluator/calls/starts_with_spec.rb
index 5153d0b..cb1b156 100644
--- a/spec/oga/xpath/evaluator/calls/starts_with_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/starts_with_spec.rb
@@ -3,36 +3,35 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'starts-with() function' do
before do
- @document = parse('foofoobar')
- @evaluator = described_class.new(@document)
+ @document = parse('foofoobar')
end
example 'return true if the 1st string starts with the 2nd string' do
- @evaluator.evaluate('starts-with("foobar", "foo")').should == true
+ evaluate_xpath(@document, 'starts-with("foobar", "foo")').should == true
end
example "return false if the 1st string doesn't start with the 2nd string" do
- @evaluator.evaluate('starts-with("foobar", "baz")').should == false
+ evaluate_xpath(@document, 'starts-with("foobar", "baz")').should == false
end
example 'return true if the 1st node set starts with the 2nd string' do
- @evaluator.evaluate('starts-with(root/a, "foo")').should == true
+ evaluate_xpath(@document, 'starts-with(root/a, "foo")').should == true
end
example 'return true if the 1st node set starts with the 2nd node set' do
- @evaluator.evaluate('starts-with(root/b, root/a)').should == true
+ evaluate_xpath(@document, 'starts-with(root/b, root/a)').should == true
end
example "return false if the 1st node set doesn't start with the 2nd string" do
- @evaluator.evaluate('starts-with(root/a, "baz")').should == false
+ evaluate_xpath(@document, 'starts-with(root/a, "baz")').should == false
end
example 'return true if the 1st string starts with the 2nd node set' do
- @evaluator.evaluate('starts-with("foobar", root/a)').should == true
+ evaluate_xpath(@document, 'starts-with("foobar", root/a)').should == true
end
example 'return true when using two empty strings' do
- @evaluator.evaluate('starts-with("", "")').should == true
+ evaluate_xpath(@document, 'starts-with("", "")').should == true
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/string_length_spec.rb b/spec/oga/xpath/evaluator/calls/string_length_spec.rb
index 1a63da6..bcb8aa4 100644
--- a/spec/oga/xpath/evaluator/calls/string_length_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/string_length_spec.rb
@@ -3,40 +3,29 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'string-length() function' do
before do
- @document = parse('x')
- @evaluator = described_class.new(@document)
+ @document = parse('x')
end
- context 'outside predicates' do
- example 'return the length of a literal string' do
- @evaluator.evaluate('string-length("foo")').should == 3.0
- end
-
- example 'return the length of a literal integer' do
- @evaluator.evaluate('string-length(10)').should == 2.0
- end
-
- example 'return the length of a literal float' do
- # This includes the counting of the dot. That is, "10.5".length => 4
- @evaluator.evaluate('string-length(10.5)').should == 4.0
- end
-
- example 'return the length of a string in a node set' do
- @evaluator.evaluate('string-length(root)').should == 1.0
- end
+ example 'return the length of a literal string' do
+ evaluate_xpath(@document, 'string-length("foo")').should == 3.0
end
- context 'inside predicates' do
- before do
- # Since the length of is 1 this should just return the node.
- @set = @evaluator.evaluate('root/a[string-length()]')
- end
+ example 'return the length of a literal integer' do
+ evaluate_xpath(@document, 'string-length(10)').should == 2.0
+ end
- it_behaves_like :node_set, :length => 1
+ example 'return the length of a literal float' do
+ # This includes the counting of the dot. That is, "10.5".length => 4
+ evaluate_xpath(@document, 'string-length(10.5)').should == 4.0
+ end
- example 'return the node' do
- @set[0].should == @document.children[0].children[0]
- end
+ example 'return the length of a string in a node set' do
+ evaluate_xpath(@document, 'string-length(root)').should == 1.0
+ end
+
+ example 'return a node set containing nodes with a specific text length' do
+ evaluate_xpath(@document, 'root/a[string-length() = 1]')
+ .should == node_set(@document.children[0].children[0])
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/string_spec.rb b/spec/oga/xpath/evaluator/calls/string_spec.rb
index c09e310..ad6fb72 100644
--- a/spec/oga/xpath/evaluator/calls/string_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/string_spec.rb
@@ -11,66 +11,58 @@ describe Oga::XPath::Evaluator do
EOF
- @evaluator = described_class.new(@document)
end
- context 'outside predicates' do
- example 'convert the node to a string' do
- @evaluator.evaluate('string(root)')
- .should == "\n a1\n b1\n \n foobar\n"
- end
-
- example 'convert the node to a string' do
- @evaluator.evaluate('string(root/a)').should == 'a1'
- end
-
- example 'convert the node to a string' do
- @evaluator.evaluate('string(root/b)').should == 'b1'
- end
-
- example 'convert the "num" attribute to a string' do
- @evaluator.evaluate('string(root/b/@num)').should == '10'
- end
-
- example 'convert the first node in a set to a string' do
- @evaluator.evaluate('string(root/*)').should == 'a1'
- end
-
- example 'convert an integer to a string' do
- @evaluator.evaluate('string(10)').should == '10'
- end
-
- example 'convert a float to a string' do
- @evaluator.evaluate('string(10.5)').should == '10.5'
- end
-
- example 'convert a string to a string' do
- @evaluator.evaluate('string("foo")').should == 'foo'
- end
-
- example 'convert a comment to a string' do
- @evaluator.evaluate('string(root/c/comment())').should == 'foo'
- end
-
- example 'convert a CDATA to a string' do
- @evaluator.evaluate('string(root/d/node())').should == 'foobar'
- end
-
- example 'return an empty string by default' do
- @evaluator.evaluate('string(foobar)').should == ''
- end
+ example 'convert the node to a string' do
+ evaluate_xpath(@document, 'string(root)')
+ .should == "\n a1\n b1\n \n foobar\n"
end
- context 'inside predicates' do
- before do
- @set = @evaluator.evaluate('root/b[string()]')
- end
+ example 'convert the node to a string' do
+ evaluate_xpath(@document, 'string(root/a)').should == 'a1'
+ end
- it_behaves_like :node_set, :length => 1
+ example 'convert the node to a string' do
+ evaluate_xpath(@document, 'string(root/b)').should == 'b1'
+ end
- example 'return the node' do
- @set[0].name.should == 'b'
- end
+ example 'convert the "num" attribute to a string' do
+ evaluate_xpath(@document, 'string(root/b/@num)').should == '10'
+ end
+
+ example 'convert the first node in a set to a string' do
+ evaluate_xpath(@document, 'string(root/*)').should == 'a1'
+ end
+
+ example 'convert an integer to a string' do
+ evaluate_xpath(@document, 'string(10)').should == '10'
+ end
+
+ example 'convert a float to a string' do
+ evaluate_xpath(@document, 'string(10.5)').should == '10.5'
+ end
+
+ example 'convert a string to a string' do
+ evaluate_xpath(@document, 'string("foo")').should == 'foo'
+ end
+
+ example 'convert a comment to a string' do
+ evaluate_xpath(@document, 'string(root/c/comment())').should == 'foo'
+ end
+
+ example 'convert a CDATA to a string' do
+ evaluate_xpath(@document, 'string(root/d/node())').should == 'foobar'
+ end
+
+ example 'return an empty string by default' do
+ evaluate_xpath(@document, 'string(foobar)').should == ''
+ end
+
+ example 'return a node set containing nodes with certain text' do
+ b = @document.children[0].children[1].next_element
+
+ evaluate_xpath(@document, 'root/b[string() = "b1"]')
+ .should == node_set(b)
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/substring_after_spec.rb b/spec/oga/xpath/evaluator/calls/substring_after_spec.rb
index f30d136..16c3e67 100644
--- a/spec/oga/xpath/evaluator/calls/substring_after_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/substring_after_spec.rb
@@ -3,28 +3,28 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'substring-after() function' do
before do
- @document = parse('-a-b-c')
- @evaluator = described_class.new(@document)
+ @document = parse('-a-b-c')
end
example 'return the substring of the 1st string after the 2nd string' do
- @evaluator.evaluate('substring-after("a-b-c", "-")').should == 'b-c'
+ evaluate_xpath(@document, 'substring-after("a-b-c", "-")').should == 'b-c'
end
example 'return an empty string if the 2nd string is not present' do
- @evaluator.evaluate('substring-after("a-b-c", "x")').should == ''
+ evaluate_xpath(@document, 'substring-after("a-b-c", "x")').should == ''
end
example 'return the substring of the 1st node set after the 2nd string' do
- @evaluator.evaluate('substring-after(root/b, "-")').should == 'b-c'
+ evaluate_xpath(@document, 'substring-after(root/b, "-")').should == 'b-c'
end
example 'return the substring of the 1st node set after the 2nd node set' do
- @evaluator.evaluate('substring-after(root/b, root/a)').should == 'b-c'
+ evaluate_xpath(@document, 'substring-after(root/b, root/a)')
+ .should == 'b-c'
end
example 'return an empty string when using two empty strings' do
- @evaluator.evaluate('substring-after("", "")').should == ''
+ evaluate_xpath(@document, 'substring-after("", "")').should == ''
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/substring_before_spec.rb b/spec/oga/xpath/evaluator/calls/substring_before_spec.rb
index a12fb45..f075452 100644
--- a/spec/oga/xpath/evaluator/calls/substring_before_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/substring_before_spec.rb
@@ -3,28 +3,28 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'substring-before() function' do
before do
- @document = parse('-a-b-c')
- @evaluator = described_class.new(@document)
+ @document = parse('-a-b-c')
end
example 'return the substring of the 1st string before the 2nd string' do
- @evaluator.evaluate('substring-before("a-b-c", "-")').should == 'a'
+ evaluate_xpath(@document, 'substring-before("a-b-c", "-")').should == 'a'
end
example 'return an empty string if the 2nd string is not present' do
- @evaluator.evaluate('substring-before("a-b-c", "x")').should == ''
+ evaluate_xpath(@document, 'substring-before("a-b-c", "x")').should == ''
end
example 'return the substring of the 1st node set before the 2nd string' do
- @evaluator.evaluate('substring-before(root/b, "-")').should == 'a'
+ evaluate_xpath(@document, 'substring-before(root/b, "-")').should == 'a'
end
example 'return the substring of the 1st node set before the 2nd node set' do
- @evaluator.evaluate('substring-before(root/b, root/a)').should == 'a'
+ evaluate_xpath(@document, 'substring-before(root/b, root/a)')
+ .should == 'a'
end
example 'return an empty string when using two empty strings' do
- @evaluator.evaluate('substring-before("", "")').should == ''
+ evaluate_xpath(@document, 'substring-before("", "")').should == ''
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/substring_spec.rb b/spec/oga/xpath/evaluator/calls/substring_spec.rb
index c07a3f6..7792c37 100644
--- a/spec/oga/xpath/evaluator/calls/substring_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/substring_spec.rb
@@ -3,28 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'substring() function' do
before do
- @document = parse('foobar3')
- @evaluator = described_class.new(@document)
+ @document = parse('foobar3')
end
example 'return the substring of a string' do
- @evaluator.evaluate('substring("foo", 2)').should == 'oo'
+ evaluate_xpath(@document, 'substring("foo", 2)').should == 'oo'
end
example 'return the substring of a string using a custom length' do
- @evaluator.evaluate('substring("foo", 2, 1)').should == 'o'
+ evaluate_xpath(@document, 'substring("foo", 2, 1)').should == 'o'
end
example 'return the substring of a node set' do
- @evaluator.evaluate('substring(root/a, 2)').should == 'oobar'
+ evaluate_xpath(@document, 'substring(root/a, 2)').should == 'oobar'
end
example 'return the substring of a node set with a node set as the length' do
- @evaluator.evaluate('substring(root/a, 1, root/b)').should == 'foo'
+ evaluate_xpath(@document, 'substring(root/a, 1, root/b)').should == 'foo'
end
example 'return an empty string when the source string is empty' do
- @evaluator.evaluate('substring("", 1, 3)').should == ''
+ evaluate_xpath(@document, 'substring("", 1, 3)').should == ''
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/sum_spec.rb b/spec/oga/xpath/evaluator/calls/sum_spec.rb
index f6b7b64..51d0e50 100644
--- a/spec/oga/xpath/evaluator/calls/sum_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/sum_spec.rb
@@ -3,25 +3,24 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'sum() spec' do
before do
- @document = parse('12')
- @evaluator = described_class.new(@document)
+ @document = parse('12')
end
example 'return the sum of the node' do
# The test of is "12", which is then converted to a number.
- @evaluator.evaluate('sum(root)').should == 12.0
+ evaluate_xpath(@document, 'sum(root)').should == 12.0
end
example 'return the sum of the child nodes of the node' do
- @evaluator.evaluate('sum(root/*)').should == 3.0
+ evaluate_xpath(@document, 'sum(root/*)').should == 3.0
end
example 'return zero by default' do
- @evaluator.evaluate('sum(foo)').should be_zero
+ evaluate_xpath(@document, 'sum(foo)').should be_zero
end
example 'raise a TypeError for non node set arguments' do
- block = lambda { @evaluator.evaluate('sum("foo")') }
+ block = -> { evaluate_xpath(@document, 'sum("foo")') }
block.should raise_error(TypeError)
end
diff --git a/spec/oga/xpath/evaluator/calls/translate_spec.rb b/spec/oga/xpath/evaluator/calls/translate_spec.rb
index bdc1491..bdb030c 100644
--- a/spec/oga/xpath/evaluator/calls/translate_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/translate_spec.rb
@@ -3,32 +3,36 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'translate() function' do
before do
- @document = parse('barabcABC')
- @evaluator = described_class.new(@document)
+ @document = parse('barabcABC')
end
example 'translate a string using all string literals' do
- @evaluator.evaluate('translate("bar", "abc", "ABC")').should == 'BAr'
+ evaluate_xpath(@document, 'translate("bar", "abc", "ABC")')
+ .should == 'BAr'
end
example "remove characters that don't occur in the replacement string" do
- @evaluator.evaluate('translate("-aaa-", "abc-", "ABC")').should == 'AAA'
+ evaluate_xpath(@document, 'translate("-aaa-", "abc-", "ABC")')
+ .should == 'AAA'
end
example 'use the first character occurence in the search string' do
- @evaluator.evaluate('translate("ab", "aba", "123")').should == '12'
+ evaluate_xpath(@document, 'translate("ab", "aba", "123")').should == '12'
end
example 'ignore excess characters in the replacement string' do
- @evaluator.evaluate('translate("abc", "abc", "123456")').should == '123'
+ evaluate_xpath(@document, 'translate("abc", "abc", "123456")')
+ .should == '123'
end
example 'translate a node set string using string literals' do
- @evaluator.evaluate('translate(root/a, "abc", "ABC")').should == 'BAr'
+ evaluate_xpath(@document, 'translate(root/a, "abc", "ABC")')
+ .should == 'BAr'
end
example 'translate a node set string using other node set strings' do
- @evaluator.evaluate('translate(root/a, root/b, root/c)').should == 'BAr'
+ evaluate_xpath(@document, 'translate(root/a, root/b, root/c)')
+ .should == 'BAr'
end
end
end
diff --git a/spec/oga/xpath/evaluator/calls/true_spec.rb b/spec/oga/xpath/evaluator/calls/true_spec.rb
index 5d90fd4..0a04e01 100644
--- a/spec/oga/xpath/evaluator/calls/true_spec.rb
+++ b/spec/oga/xpath/evaluator/calls/true_spec.rb
@@ -3,11 +3,11 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'true() function' do
before do
- @evaluator = described_class.new(parse(''))
+ @document = parse('')
end
example 'return true' do
- @evaluator.evaluate('true()').should == true
+ evaluate_xpath(@document, 'true()').should == true
end
end
end