test/unit/ut_6_condition.rb in ruote-2.2.0 vs test/unit/ut_6_condition.rb in ruote-2.3.0
- old
+ new
@@ -3,11 +3,11 @@
# testing ruote
#
# Sun Jun 14 17:30:43 JST 2009
#
-require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
+require File.expand_path('../../test_helper', __FILE__)
require 'ruote/svc/treechecker'
require 'ruote/svc/expression_map'
@@ -21,18 +21,28 @@
def attribute(k)
@h[k]
end
end
- def assert_not_skip(result, h)
+ def assert_apply(h)
- fe = FakeExpression.new(h)
+ e = FakeExpression.new(h)
+ a = [ e.attribute(:if), e.attribute(:unless) ]
- sif = fe.attribute(:if)
- sunless = fe.attribute(:unless)
+ assert(
+ Ruote::Exp::Condition.apply?(*a),
+ "exp #{h.inspect} was meant to be applied (#{a.inspect})")
+ end
- assert_equal result, Ruote::Exp::Condition.apply?(sif, sunless)
+ def assert_skip(h)
+
+ e = FakeExpression.new(h)
+ a = [ e.attribute(:if), e.attribute(:unless) ]
+
+ assert(
+ ! Ruote::Exp::Condition.apply?(*a),
+ "exp #{h.inspect} was meant to be skipped (#{a.inspect})")
end
def assert_b(b, conditional=nil)
if conditional == nil
@@ -44,43 +54,54 @@
b,
Ruote::Exp::Condition.true?(conditional),
">#{conditional}< was expected to be #{b}")
end
+ def test_blank
+
+ assert_b(false, '')
+ assert_b(false, ' ')
+ assert_b(true, true)
+ assert_b(false, false)
+ end
+
def test_if
- assert_not_skip false, :if => 'true == false'
- assert_not_skip false, :if => "'true' == 'false'"
- assert_not_skip false, :if => '"true" == "false"'
+ assert_skip :if => 'true == false'
+ assert_skip :if => "'true' == 'false'"
+ assert_skip :if => '"true" == "false"'
- assert_not_skip true, :if => 'a == a'
- assert_not_skip true, :if => '"a" == "a"'
+ assert_skip :if => ''
+ assert_skip :if => ' '
- assert_not_skip true, :if => 'blah blah blah'
+ assert_apply :if => 'a == a'
+ assert_apply :if => '"a" == "a"'
+
+ assert_apply :if => 'blah blah blah'
end
def test_unless
- assert_not_skip true, :unless => 'true == false'
- assert_not_skip false, :unless => 'false == false'
+ assert_apply :unless => 'true == false'
+ assert_skip :unless => 'false == false'
end
def test_set
- assert_not_skip true, :if => 'true set'
- assert_not_skip true, :if => "'true' set"
- assert_not_skip true, :if => '"true" set'
+ assert_apply :if => 'true set'
+ assert_apply :if => "'true' set"
+ assert_apply :if => '"true" set'
- assert_not_skip true, :if => 'true is set'
- assert_not_skip true, :if => '"true" is set'
- assert_not_skip true, :if => "'true' is set"
- assert_not_skip false, :if => 'true is not set'
+ assert_apply :if => 'true is set'
+ assert_apply :if => '"true" is set'
+ assert_apply :if => "'true' is set"
+ assert_skip :if => 'true is not set'
end
def test_illegal_code
- assert_not_skip true, :if => 'exit'
+ assert_apply :if => 'exit'
end
def test_true
assert_b true, 'true == true'
@@ -124,16 +145,16 @@
assert_b false, 'a == '
end
def test_strip
- assert_not_skip true, :if => 'a == a '
- assert_not_skip true, :if => ' a == a '
- assert_not_skip true, :if => ' a == a'
- assert_not_skip true, :if => 'a == a'
- assert_not_skip true, :if => 'a == a'
- assert_not_skip true, :if => 'a==a'
+ assert_apply :if => 'a == a '
+ assert_apply :if => ' a == a '
+ assert_apply :if => ' a == a'
+ assert_apply :if => 'a == a'
+ assert_apply :if => 'a == a'
+ assert_apply :if => 'a==a'
end
def test_boolean_literals
assert_b true, true
@@ -143,12 +164,21 @@
def test_complex_strings
assert_b true, "'some dude' == 'some dude'"
assert_b true, "some dude == \"some dude\""
assert_b true, "some dude == 'some dude'"
+
+ assert_b false, "'some other dude' == 'some dude'"
+ assert_b false, "some other dude == 'some dude'"
end
+ def test_numbers
+
+ assert_b true, '2.310000 > 0'
+ assert_b false, '2.310000 < 0'
+ end
+
def test_and_or
assert_b "1 and 2 and 3"
assert_b "1 && 2 && 3"
@@ -194,12 +224,20 @@
assert_e /^a/, "/^a/"
assert_e 'Loan', 'Loan'
assert_e 'Loan/Grant', 'Loan/Grant'
assert_e 'Loan/Grant', 'Loan / Grant'
+
+ assert_e 'redo', '"redo"'
end
+ def test_something_or_not
+
+ assert_b "something"
+ assert_b false, ""
+ end
+
def test_is_empty
assert_b "'' empty"
assert_b "'' is empty"
assert_b '"" empty'
@@ -257,10 +295,13 @@
assert_b "1 in [1, 2]"
assert_b "1 in {1 => 2}"
assert_b false, "3 in [1, 2]"
assert_b false, "2 in {1 => 2}"
+
+ assert_b "a in [a, b]"
+ assert_b "'a' in [a, b]"
end
def test_not_in
assert_b "7 not in [1, 2]"
@@ -274,12 +315,13 @@
assert_b false, "1 in [1 2]"
assert_b false, "1 in {x}"
end
- def test_comparators
+ def test_matching
assert_b "alpha =~ /^a/"
+ assert_b "'alpha toto' =~ /^a/"
assert_b false, "alpha =~ /^b/"
end
end