Rewrote all XPath evaluator operator tests.
This commit is contained in:
parent
28a1f1b8a9
commit
ca5da3f9c9
|
@ -3,32 +3,31 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'add operator' do
|
context 'add operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>1</a><b>2</b></root>')
|
@document = parse('<root><a>1</a><b>2</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'add two numbers' do
|
example 'add two numbers' do
|
||||||
@evaluator.evaluate('1 + 2').should == 3.0
|
evaluate_xpath(@document, '1 + 2').should == 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'add a number and a string' do
|
example 'add a number and a string' do
|
||||||
@evaluator.evaluate('1 + "2"').should == 3.0
|
evaluate_xpath(@document, '1 + "2"').should == 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'add two strings' do
|
example 'add two strings' do
|
||||||
@evaluator.evaluate('"1" + "2"').should == 3.0
|
evaluate_xpath(@document, '"1" + "2"').should == 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'add a number and a node set' do
|
example 'add a number and a node set' do
|
||||||
@evaluator.evaluate('root/a + 2').should == 3.0
|
evaluate_xpath(@document, 'root/a + 2').should == 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'add two node sets' do
|
example 'add two node sets' do
|
||||||
@evaluator.evaluate('root/a + root/b').should == 3.0
|
evaluate_xpath(@document, 'root/a + root/b').should == 3.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return NaN when trying to add invalid values' do
|
example 'return NaN when trying to add invalid values' do
|
||||||
@evaluator.evaluate('"" + 1').should be_nan
|
evaluate_xpath(@document, '"" + 1').should be_nan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,30 +3,30 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'and operator' do
|
context 'and operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>1</a><b>1</b></root>')
|
@document = parse('<root><a>1</a><b>1</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if both boolean literals are true' do
|
example 'return true if both boolean literals are true' do
|
||||||
@evaluator.evaluate('true() and true()').should == true
|
evaluate_xpath(@document, 'true() and true()').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if one of the boolean literals is false' do
|
example 'return false if one of the boolean literals is false' do
|
||||||
@evaluator.evaluate('true() and false()').should == false
|
evaluate_xpath(@document, 'true() and false()').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if both node sets are non empty' do
|
example 'return true if both node sets are non empty' do
|
||||||
@evaluator.evaluate('root/a and root/b').should == true
|
evaluate_xpath(@document, 'root/a and root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'false false if one of the node sets is empty' do
|
example 'false false if one of the node sets is empty' do
|
||||||
@evaluator.evaluate('root/a and root/c').should == false
|
evaluate_xpath(@document, 'root/a and root/c').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'skip the right expression if the left one evaluates to false' do
|
example 'skip the right expression if the left one evaluates to false' do
|
||||||
@evaluator.should_not receive(:on_call_true)
|
evaluator = described_class.new(@document)
|
||||||
|
evaluator.should_not receive(:on_call_true)
|
||||||
|
|
||||||
@evaluator.evaluate('false() and true()').should == false
|
evaluator.evaluate('false() and true()').should == false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,32 +3,31 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'div operator' do
|
context 'div operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>1</a><b>2</b></root>')
|
@document = parse('<root><a>1</a><b>2</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'divide two numbers' do
|
example 'divide two numbers' do
|
||||||
@evaluator.evaluate('1 div 2').should == 0.5
|
evaluate_xpath(@document, '1 div 2').should == 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'divide a number and a string' do
|
example 'divide a number and a string' do
|
||||||
@evaluator.evaluate('1 div "2"').should == 0.5
|
evaluate_xpath(@document, '1 div "2"').should == 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'divide two strings' do
|
example 'divide two strings' do
|
||||||
@evaluator.evaluate('"1" div "2"').should == 0.5
|
evaluate_xpath(@document, '"1" div "2"').should == 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'divide a number and a node set' do
|
example 'divide a number and a node set' do
|
||||||
@evaluator.evaluate('root/a div 2').should == 0.5
|
evaluate_xpath(@document, 'root/a div 2').should == 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'divide two node sets' do
|
example 'divide two node sets' do
|
||||||
@evaluator.evaluate('root/a div root/b').should == 0.5
|
evaluate_xpath(@document, 'root/a div root/b').should == 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return NaN when trying to divide invalid values' do
|
example 'return NaN when trying to divide invalid values' do
|
||||||
@evaluator.evaluate('"" div 1').should be_nan
|
evaluate_xpath(@document, '"" div 1').should be_nan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,60 +3,59 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'equal operator' do
|
context 'equal operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>10</a><b class="foo">10</b></root>')
|
@document = parse('<root><a>10</a><b class="foo">10</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if two numbers are equal' do
|
example 'return true if two numbers are equal' do
|
||||||
@evaluator.evaluate('10 = 10').should == true
|
evaluate_xpath(@document, '10 = 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if two numbers are not equal' do
|
example 'return false if two numbers are not equal' do
|
||||||
@evaluator.evaluate('10 = 15').should == false
|
evaluate_xpath(@document, '10 = 15').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number and a string are equal' do
|
example 'return true if a number and a string are equal' do
|
||||||
@evaluator.evaluate('10 = "10"').should == true
|
evaluate_xpath(@document, '10 = "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if two strings are equal' do
|
example 'return true if two strings are equal' do
|
||||||
@evaluator.evaluate('"10" = "10"').should == true
|
evaluate_xpath(@document, '"10" = "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string and a number are equal' do
|
example 'return true if a string and a number are equal' do
|
||||||
@evaluator.evaluate('"10" = 10').should == true
|
evaluate_xpath(@document, '"10" = 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if two strings are not equal' do
|
example 'return false if two strings are not equal' do
|
||||||
@evaluator.evaluate('"a" = "b"').should == false
|
evaluate_xpath(@document, '"a" = "b"').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if two node sets are equal' do
|
example 'return true if two node sets are equal' do
|
||||||
@evaluator.evaluate('root/a = root/b').should == true
|
evaluate_xpath(@document, 'root/a = root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if two node sets are not equal' do
|
example 'return false if two node sets are not equal' do
|
||||||
@evaluator.evaluate('root/a = root/c').should == false
|
evaluate_xpath(@document, 'root/a = root/c').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set and a number are equal' do
|
example 'return true if a node set and a number are equal' do
|
||||||
@evaluator.evaluate('root/a = 10').should == true
|
evaluate_xpath(@document, 'root/a = 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set and a string are equal' do
|
example 'return true if a node set and a string are equal' do
|
||||||
@evaluator.evaluate('root/a = "10"').should == true
|
evaluate_xpath(@document, 'root/a = "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set wildcard and a number are equal' do
|
example 'return true if a node set wildcard and a number are equal' do
|
||||||
@evaluator.evaluate('root/* = 10').should == true
|
evaluate_xpath(@document, 'root/* = 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number and a node set wildcard are equal' do
|
example 'return true if a number and a node set wildcard are equal' do
|
||||||
@evaluator.evaluate('10 = root/*').should == true
|
evaluate_xpath(@document, '10 = root/*').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if an attribute and string are equal' do
|
example 'return true if an attribute and string are equal' do
|
||||||
@evaluator.evaluate('root/b/@class = "foo"').should == true
|
evaluate_xpath(@document, 'root/b/@class = "foo"').should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,40 +3,39 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'greater-than operator' do
|
context 'greater-than operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>10</a><b>20</b></root>')
|
@document = parse('<root><a>10</a><b>20</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is greater than another number' do
|
example 'return true if a number is greater than another number' do
|
||||||
@evaluator.evaluate('20 > 10').should == true
|
evaluate_xpath(@document, '20 > 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if a number is not greater than another number' do
|
example 'return false if a number is not greater than another number' do
|
||||||
@evaluator.evaluate('10 > 20').should == false
|
evaluate_xpath(@document, '10 > 20').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is greater than a string' do
|
example 'return true if a number is greater than a string' do
|
||||||
@evaluator.evaluate('20 > "10"').should == true
|
evaluate_xpath(@document, '20 > "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is greater than a number' do
|
example 'return true if a string is greater than a number' do
|
||||||
@evaluator.evaluate('"20" > 10').should == true
|
evaluate_xpath(@document, '"20" > 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is greater than another string' do
|
example 'return true if a string is greater than another string' do
|
||||||
@evaluator.evaluate('"20" > "10"').should == true
|
evaluate_xpath(@document, '"20" > "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is greater than a node set' do
|
example 'return true if a number is greater than a node set' do
|
||||||
@evaluator.evaluate('20 > root/a').should == true
|
evaluate_xpath(@document, '20 > root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is greater than a node set' do
|
example 'return true if a string is greater than a node set' do
|
||||||
@evaluator.evaluate('"20" > root/a').should == true
|
evaluate_xpath(@document, '"20" > root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set is greater than another node set' do
|
example 'return true if a node set is greater than another node set' do
|
||||||
@evaluator.evaluate('root/b > root/a').should == true
|
evaluate_xpath(@document, 'root/b > root/a').should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,64 +3,63 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'greater-than-or-equal operator' do
|
context 'greater-than-or-equal operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>10</a><b>20</b></root>')
|
@document = parse('<root><a>10</a><b>20</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is greater than another number' do
|
example 'return true if a number is greater than another number' do
|
||||||
@evaluator.evaluate('20 >= 10').should == true
|
evaluate_xpath(@document, '20 >= 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is equal to another number' do
|
example 'return true if a number is equal to another number' do
|
||||||
@evaluator.evaluate('10 >= 10').should == true
|
evaluate_xpath(@document, '10 >= 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if a number is not greater than/equal to another number' do
|
example 'return false if a number is not greater than/equal to another number' do
|
||||||
@evaluator.evaluate('10 >= 20').should == false
|
evaluate_xpath(@document, '10 >= 20').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is greater than a string' do
|
example 'return true if a number is greater than a string' do
|
||||||
@evaluator.evaluate('20 >= "10"').should == true
|
evaluate_xpath(@document, '20 >= "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is equal to a string' do
|
example 'return true if a number is equal to a string' do
|
||||||
@evaluator.evaluate('10 >= "10"').should == true
|
evaluate_xpath(@document, '10 >= "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is greater than a number' do
|
example 'return true if a string is greater than a number' do
|
||||||
@evaluator.evaluate('"20" >= 10').should == true
|
evaluate_xpath(@document, '"20" >= 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is equal to a number' do
|
example 'return true if a string is equal to a number' do
|
||||||
@evaluator.evaluate('"10" >= 10').should == true
|
evaluate_xpath(@document, '"10" >= 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is greater than another string' do
|
example 'return true if a string is greater than another string' do
|
||||||
@evaluator.evaluate('"20" >= "10"').should == true
|
evaluate_xpath(@document, '"20" >= "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is greater than a node set' do
|
example 'return true if a number is greater than a node set' do
|
||||||
@evaluator.evaluate('20 >= root/a').should == true
|
evaluate_xpath(@document, '20 >= root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is equal to a node set' do
|
example 'return true if a number is equal to a node set' do
|
||||||
@evaluator.evaluate('20 >= root/b').should == true
|
evaluate_xpath(@document, '20 >= root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is greater than a node set' do
|
example 'return true if a string is greater than a node set' do
|
||||||
@evaluator.evaluate('"20" >= root/a').should == true
|
evaluate_xpath(@document, '"20" >= root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is equal to a node set' do
|
example 'return true if a string is equal to a node set' do
|
||||||
@evaluator.evaluate('"10" >= root/a').should == true
|
evaluate_xpath(@document, '"10" >= root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set is greater than another node set' do
|
example 'return true if a node set is greater than another node set' do
|
||||||
@evaluator.evaluate('root/b >= root/a').should == true
|
evaluate_xpath(@document, 'root/b >= root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set is equal to another node set' do
|
example 'return true if a node set is equal to another node set' do
|
||||||
@evaluator.evaluate('root/b >= root/b').should == true
|
evaluate_xpath(@document, 'root/b >= root/b').should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,40 +3,39 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'lower-than operator' do
|
context 'lower-than operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>10</a><b>20</b></root>')
|
@document = parse('<root><a>10</a><b>20</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is lower than another number' do
|
example 'return true if a number is lower than another number' do
|
||||||
@evaluator.evaluate('10 < 20').should == true
|
evaluate_xpath(@document, '10 < 20').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if a number is not lower than another number' do
|
example 'return false if a number is not lower than another number' do
|
||||||
@evaluator.evaluate('20 < 10').should == false
|
evaluate_xpath(@document, '20 < 10').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is lower than a string' do
|
example 'return true if a number is lower than a string' do
|
||||||
@evaluator.evaluate('10 < "20"').should == true
|
evaluate_xpath(@document, '10 < "20"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is lower than a number' do
|
example 'return true if a string is lower than a number' do
|
||||||
@evaluator.evaluate('"10" < 20').should == true
|
evaluate_xpath(@document, '"10" < 20').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is lower than another string' do
|
example 'return true if a string is lower than another string' do
|
||||||
@evaluator.evaluate('"10" < "20"').should == true
|
evaluate_xpath(@document, '"10" < "20"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is lower than a node set' do
|
example 'return true if a number is lower than a node set' do
|
||||||
@evaluator.evaluate('10 < root/b').should == true
|
evaluate_xpath(@document, '10 < root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is lower than a node set' do
|
example 'return true if a string is lower than a node set' do
|
||||||
@evaluator.evaluate('"10" < root/b').should == true
|
evaluate_xpath(@document, '"10" < root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set is lower than another node set' do
|
example 'return true if a node set is lower than another node set' do
|
||||||
@evaluator.evaluate('root/a < root/b').should == true
|
evaluate_xpath(@document, 'root/a < root/b').should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,64 +3,63 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'lower-than-or-equal operator' do
|
context 'lower-than-or-equal operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>10</a><b>20</b></root>')
|
@document = parse('<root><a>10</a><b>20</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is lower than another number' do
|
example 'return true if a number is lower than another number' do
|
||||||
@evaluator.evaluate('10 <= 20').should == true
|
evaluate_xpath(@document, '10 <= 20').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is equal to another number' do
|
example 'return true if a number is equal to another number' do
|
||||||
@evaluator.evaluate('10 <= 10').should == true
|
evaluate_xpath(@document, '10 <= 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if a number is not lower than/equal to another number' do
|
example 'return false if a number is not lower than/equal to another number' do
|
||||||
@evaluator.evaluate('20 <= 10').should == false
|
evaluate_xpath(@document, '20 <= 10').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is lower than a string' do
|
example 'return true if a number is lower than a string' do
|
||||||
@evaluator.evaluate('10 <= "20"').should == true
|
evaluate_xpath(@document, '10 <= "20"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is equal to a string' do
|
example 'return true if a number is equal to a string' do
|
||||||
@evaluator.evaluate('10 <= "10"').should == true
|
evaluate_xpath(@document, '10 <= "10"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is lower than a number' do
|
example 'return true if a string is lower than a number' do
|
||||||
@evaluator.evaluate('"10" <= 20').should == true
|
evaluate_xpath(@document, '"10" <= 20').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is equal to a number' do
|
example 'return true if a string is equal to a number' do
|
||||||
@evaluator.evaluate('"10" <= 10').should == true
|
evaluate_xpath(@document, '"10" <= 10').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is lower than another string' do
|
example 'return true if a string is lower than another string' do
|
||||||
@evaluator.evaluate('"10" <= "20"').should == true
|
evaluate_xpath(@document, '"10" <= "20"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is lower than a node set' do
|
example 'return true if a number is lower than a node set' do
|
||||||
@evaluator.evaluate('10 <= root/b').should == true
|
evaluate_xpath(@document, '10 <= root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number is equal to a node set' do
|
example 'return true if a number is equal to a node set' do
|
||||||
@evaluator.evaluate('10 <= root/a').should == true
|
evaluate_xpath(@document, '10 <= root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is lower than a node set' do
|
example 'return true if a string is lower than a node set' do
|
||||||
@evaluator.evaluate('"10" <= root/b').should == true
|
evaluate_xpath(@document, '"10" <= root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string is equal to a node set' do
|
example 'return true if a string is equal to a node set' do
|
||||||
@evaluator.evaluate('"10" <= root/a').should == true
|
evaluate_xpath(@document, '"10" <= root/a').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set is lower than another node set' do
|
example 'return true if a node set is lower than another node set' do
|
||||||
@evaluator.evaluate('root/a <= root/b').should == true
|
evaluate_xpath(@document, 'root/a <= root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set is equal to another node set' do
|
example 'return true if a node set is equal to another node set' do
|
||||||
@evaluator.evaluate('root/b <= root/b').should == true
|
evaluate_xpath(@document, 'root/b <= root/b').should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,32 +3,31 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'mod operator' do
|
context 'mod operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>2</a><b>3</b></root>')
|
@document = parse('<root><a>2</a><b>3</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return the modulo of two numbers' do
|
example 'return the modulo of two numbers' do
|
||||||
@evaluator.evaluate('2 mod 3').should == 2.0
|
evaluate_xpath(@document, '2 mod 3').should == 2.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return the modulo of a number and a string' do
|
example 'return the modulo of a number and a string' do
|
||||||
@evaluator.evaluate('2 mod "3"').should == 2.0
|
evaluate_xpath(@document, '2 mod "3"').should == 2.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return the modulo of two strings' do
|
example 'return the modulo of two strings' do
|
||||||
@evaluator.evaluate('"2" mod "3"').should == 2.0
|
evaluate_xpath(@document, '"2" mod "3"').should == 2.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return the modulo of a node set and a number' do
|
example 'return the modulo of a node set and a number' do
|
||||||
@evaluator.evaluate('root/a mod 3').should == 2.0
|
evaluate_xpath(@document, 'root/a mod 3').should == 2.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return the modulo of two node sets' do
|
example 'return the modulo of two node sets' do
|
||||||
@evaluator.evaluate('root/a mod root/b').should == 2.0
|
evaluate_xpath(@document, 'root/a mod root/b').should == 2.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return NaN when trying to get the modulo of invalid values' do
|
example 'return NaN when trying to get the modulo of invalid values' do
|
||||||
@evaluator.evaluate('"" mod 1').should be_nan
|
evaluate_xpath(@document, '"" mod 1').should be_nan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,32 +3,31 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'multiplication operator' do
|
context 'multiplication operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>2</a><b>3</b></root>')
|
@document = parse('<root><a>2</a><b>3</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'multiply two numbers' do
|
example 'multiply two numbers' do
|
||||||
@evaluator.evaluate('2 * 3').should == 6.0
|
evaluate_xpath(@document, '2 * 3').should == 6.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'multiply a number and a string' do
|
example 'multiply a number and a string' do
|
||||||
@evaluator.evaluate('2 * "3"').should == 6.0
|
evaluate_xpath(@document, '2 * "3"').should == 6.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'multiply two strings' do
|
example 'multiply two strings' do
|
||||||
@evaluator.evaluate('"2" * "3"').should == 6.0
|
evaluate_xpath(@document, '"2" * "3"').should == 6.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'multiply a node set and a number' do
|
example 'multiply a node set and a number' do
|
||||||
@evaluator.evaluate('root/a * 3').should == 6.0
|
evaluate_xpath(@document, 'root/a * 3').should == 6.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'multiply two node sets' do
|
example 'multiply two node sets' do
|
||||||
@evaluator.evaluate('root/a * root/b').should == 6.0
|
evaluate_xpath(@document, 'root/a * root/b').should == 6.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return NaN when trying to multiply invalid values' do
|
example 'return NaN when trying to multiply invalid values' do
|
||||||
@evaluator.evaluate('"" * 1').should be_nan
|
evaluate_xpath(@document, '"" * 1').should be_nan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,48 +3,47 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'not-equal operator' do
|
context 'not-equal operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>10</a><b>10</b></root>')
|
@document = parse('<root><a>10</a><b>10</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if two numbers are not equal' do
|
example 'return true if two numbers are not equal' do
|
||||||
@evaluator.evaluate('10 != 20').should == true
|
evaluate_xpath(@document, '10 != 20').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if two numbers are equal' do
|
example 'return false if two numbers are equal' do
|
||||||
@evaluator.evaluate('10 != 10').should == false
|
evaluate_xpath(@document, '10 != 10').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a number and a string are not equal' do
|
example 'return true if a number and a string are not equal' do
|
||||||
@evaluator.evaluate('10 != "20"').should == true
|
evaluate_xpath(@document, '10 != "20"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if two strings are not equal' do
|
example 'return true if two strings are not equal' do
|
||||||
@evaluator.evaluate('"10" != "20"').should == true
|
evaluate_xpath(@document, '"10" != "20"').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a string and a number are not equal' do
|
example 'return true if a string and a number are not equal' do
|
||||||
@evaluator.evaluate('"10" != 20').should == true
|
evaluate_xpath(@document, '"10" != 20').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if two strings are equal' do
|
example 'return false if two strings are equal' do
|
||||||
@evaluator.evaluate('"a" != "a"').should == false
|
evaluate_xpath(@document, '"a" != "a"').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if two node sets are not equal' do
|
example 'return true if two node sets are not equal' do
|
||||||
@evaluator.evaluate('root != root/b').should == true
|
evaluate_xpath(@document, 'root != root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if two node sets are equal' do
|
example 'return false if two node sets are equal' do
|
||||||
@evaluator.evaluate('root/a != root/b').should == false
|
evaluate_xpath(@document, 'root/a != root/b').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set and a number are not equal' do
|
example 'return true if a node set and a number are not equal' do
|
||||||
@evaluator.evaluate('root/a != 20').should == true
|
evaluate_xpath(@document, 'root/a != 20').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if a node set and a string are not equal' do
|
example 'return true if a node set and a string are not equal' do
|
||||||
@evaluator.evaluate('root/a != "20"').should == true
|
evaluate_xpath(@document, 'root/a != "20"').should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,38 +3,38 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'or operator' do
|
context 'or operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>1</a><b>1</b></root>')
|
@document = parse('<root><a>1</a><b>1</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if both boolean literals are true' do
|
example 'return true if both boolean literals are true' do
|
||||||
@evaluator.evaluate('true() or true()').should == true
|
evaluate_xpath(@document, 'true() or true()').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if one of the boolean literals is false' do
|
example 'return true if one of the boolean literals is false' do
|
||||||
@evaluator.evaluate('true() or false()').should == true
|
evaluate_xpath(@document, 'true() or false()').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if the left node set is not empty' do
|
example 'return true if the left node set is not empty' do
|
||||||
@evaluator.evaluate('root/a or root/x').should == true
|
evaluate_xpath(@document, 'root/a or root/x').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if the right node set is not empty' do
|
example 'return true if the right node set is not empty' do
|
||||||
@evaluator.evaluate('root/x or root/b').should == true
|
evaluate_xpath(@document, 'root/x or root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return true if both node sets are not empty' do
|
example 'return true if both node sets are not empty' do
|
||||||
@evaluator.evaluate('root/a or root/b').should == true
|
evaluate_xpath(@document, 'root/a or root/b').should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return false if both node sets are empty' do
|
example 'return false if both node sets are empty' do
|
||||||
@evaluator.evaluate('root/x or root/y').should == false
|
evaluate_xpath(@document, 'root/x or root/y').should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'skip the right expression if the left one evaluates to false' do
|
example 'skip the right expression if the left one evaluates to false' do
|
||||||
@evaluator.should_not receive(:on_call_false)
|
evaluator = described_class.new(@document)
|
||||||
|
evaluator.should_not receive(:on_call_false)
|
||||||
|
|
||||||
@evaluator.evaluate('true() or false()').should == true
|
evaluator.evaluate('true() or false()').should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,60 +3,26 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'pipe operator' do
|
context 'pipe operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a></a><b></b></root>')
|
@document = parse('<root><a></a><b></b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
|
@a1 = @document.children[0].children[0]
|
||||||
|
@b1 = @document.children[0].children[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'merge two sets' do
|
example 'merge two node sets' do
|
||||||
before do
|
evaluate_xpath(@document, 'root/a | root/b').should == node_set(@a1, @b1)
|
||||||
@set = @evaluator.evaluate('/root/a | /root/b')
|
|
||||||
end
|
|
||||||
|
|
||||||
it_behaves_like :node_set, :length => 2
|
|
||||||
|
|
||||||
example 'include the <a> node' do
|
|
||||||
@set[0].name.should == 'a'
|
|
||||||
end
|
|
||||||
|
|
||||||
example 'include the <b> node' do
|
|
||||||
@set[1].name.should == 'b'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'merge two sets when the left hand side is empty' do
|
example 'merge two sets when the left hand side is empty' do
|
||||||
before do
|
evaluate_xpath(@document, 'foo | root/b').should == node_set(@b1)
|
||||||
@set = @evaluator.evaluate('foo | /root/b')
|
|
||||||
end
|
|
||||||
|
|
||||||
it_behaves_like :node_set, :length => 1
|
|
||||||
|
|
||||||
example 'include the <b> node' do
|
|
||||||
@set[0].name.should == 'b'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'merge two sets when the right hand side is empty' do
|
example 'merge two sets when the right hand side is empty' do
|
||||||
before do
|
evaluate_xpath(@document, 'root/a | foo').should == node_set(@a1)
|
||||||
@set = @evaluator.evaluate('/root/a | foo')
|
|
||||||
end
|
|
||||||
|
|
||||||
it_behaves_like :node_set, :length => 1
|
|
||||||
|
|
||||||
example 'include the <a> node' do
|
|
||||||
@set[0].name.should == 'a'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'merge two identical sets' do
|
example 'merge two identical sets' do
|
||||||
before do
|
evaluate_xpath(@document, 'root/a | root/a').should == node_set(@a1)
|
||||||
@set = @evaluator.evaluate('/root/a | /root/a')
|
|
||||||
end
|
|
||||||
|
|
||||||
it_behaves_like :node_set, :length => 1
|
|
||||||
|
|
||||||
example 'include only a single <a> node' do
|
|
||||||
@set[0].name.should == 'a'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,32 +3,31 @@ require 'spec_helper'
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
context 'subtraction operator' do
|
context 'subtraction operator' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<root><a>2</a><b>3</b></root>')
|
@document = parse('<root><a>2</a><b>3</b></root>')
|
||||||
@evaluator = described_class.new(@document)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'subtract two numbers' do
|
example 'subtract two numbers' do
|
||||||
@evaluator.evaluate('2 - 3').should == -1.0
|
evaluate_xpath(@document, '2 - 3').should == -1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'subtract a number and a string' do
|
example 'subtract a number and a string' do
|
||||||
@evaluator.evaluate('2 - "3"').should == -1.0
|
evaluate_xpath(@document, '2 - "3"').should == -1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'subtract two strings' do
|
example 'subtract two strings' do
|
||||||
@evaluator.evaluate('"2" - "3"').should == -1.0
|
evaluate_xpath(@document, '"2" - "3"').should == -1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'subtract a node set and a number' do
|
example 'subtract a node set and a number' do
|
||||||
@evaluator.evaluate('root/a - 3').should == -1.0
|
evaluate_xpath(@document, 'root/a - 3').should == -1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'subtract two node sets' do
|
example 'subtract two node sets' do
|
||||||
@evaluator.evaluate('root/a - root/b').should == -1.0
|
evaluate_xpath(@document, 'root/a - root/b').should == -1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'return NaN when trying to subtract invalid values' do
|
example 'return NaN when trying to subtract invalid values' do
|
||||||
@evaluator.evaluate('"" - 1').should be_nan
|
evaluate_xpath(@document, '"" - 1').should be_nan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue