runt 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +18 -0
- data/Rakefile +7 -4
- data/TODO +4 -2
- data/doc/tutorial_schedule.rdoc +355 -46
- data/doc/tutorial_te.rdoc +3 -3
- data/examples/reminder.rb +63 -0
- data/examples/schedule_tutorial.rb +59 -0
- data/examples/schedule_tutorialtest.rb +52 -0
- data/lib/runt/daterange.rb +1 -1
- data/lib/runt/pdate.rb +1 -1
- data/lib/runt/schedule.rb +1 -1
- data/lib/runt/temporalexpression.rb +109 -27
- data/test/baseexpressiontest.rb +110 -0
- data/test/collectiontest.rb +63 -0
- data/test/combinedexpressionstest.rb +158 -0
- data/test/daterangetest.rb +2 -0
- data/test/dayintervaltetest.rb +37 -0
- data/test/difftest.rb +37 -0
- data/test/dimonthtest.rb +59 -0
- data/test/diweektest.rb +32 -0
- data/test/everytetest.rb +36 -0
- data/test/intersecttest.rb +34 -0
- data/test/redaytest.rb +30 -0
- data/test/remonthtest.rb +37 -0
- data/test/reweektest.rb +51 -0
- data/test/reyeartest.rb +98 -0
- data/test/rspectest.rb +25 -0
- data/test/spectest.rb +36 -0
- data/test/temporalexpressiontest.rb +49 -585
- data/test/uniontest.rb +36 -0
- data/test/wimonthtest.rb +54 -0
- data/test/yeartetest.rb +22 -0
- metadata +54 -6
data/test/difftest.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for Diff class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class DiffTest < BaseExpressionTest
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
@diff = Diff.new(@stub1, @stub2)
|
13
|
+
@date = @pdate_20071008
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize
|
17
|
+
assert_same @stub1, @diff.expr1, "Expected #{@stub1} instance used to create expression. Instead got #{@diff.expr1}"
|
18
|
+
assert_same @stub2, @diff.expr2, "Expected #{@stub2} instance used to create expression. Instead got #{@diff.expr2}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_to_s
|
22
|
+
assert_equal @stub1.to_s + ' except for ' + @stub2.to_s, @diff.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_include
|
26
|
+
# Diff will match only if expr1 && !expr2
|
27
|
+
@stub1.match = false
|
28
|
+
@stub2.match = false
|
29
|
+
assert !@diff.include?(@date), "Diff instance should not include any dates"
|
30
|
+
@stub2.match = true
|
31
|
+
assert !@diff.include?(@date), "Diff instance should not include any dates"
|
32
|
+
@stub1.match = true
|
33
|
+
assert !@diff.include?(@date), "Diff instance should not include any dates"
|
34
|
+
@stub2.match = false
|
35
|
+
assert @diff.include?(@date), "Diff instance should include any dates"
|
36
|
+
end
|
37
|
+
end
|
data/test/dimonthtest.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for DIMonth class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class DIMonthTest < BaseExpressionTest
|
9
|
+
def setup
|
10
|
+
super
|
11
|
+
@date_range = @date_20050101..@date_20051231
|
12
|
+
end
|
13
|
+
|
14
|
+
###
|
15
|
+
# Dates functionality & tests contributed by Emmett Shear
|
16
|
+
###
|
17
|
+
def test_dates_mixin_first_tuesday
|
18
|
+
dates = DIMonth.new(First, Tuesday).dates(@date_range)
|
19
|
+
assert dates.size == 12
|
20
|
+
dates.each do |d|
|
21
|
+
assert @date_range.include?(d)
|
22
|
+
assert d.wday == 2 # tuesday
|
23
|
+
assert d.day < 8 # in the first week
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_dates_mixin_last_friday
|
28
|
+
dates = DIMonth.new(Last, Friday).dates(@date_range)
|
29
|
+
assert dates.size == 12
|
30
|
+
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
31
|
+
dates.each do |d|
|
32
|
+
assert @date_range.include?(d)
|
33
|
+
assert d.wday == 5 # friday
|
34
|
+
assert d.day > month_days[d.month-1] - 8 # last week
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_third_friday_of_the_month
|
39
|
+
expr = DIMonth.new(Third,Friday)
|
40
|
+
assert expr.include?(@date_20040116), "Third Friday of the month should include #{@date_20040116.to_s}"
|
41
|
+
assert !expr.include?(@date_20040109), "Third Friday of the month should not include #{@date_20040109.to_s}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_second_friday_of_the_month
|
45
|
+
expr = DIMonth.new(Second,Friday)
|
46
|
+
assert expr.include?(@date_20040109), "Second Friday of the month should include #{@date_20040109.to_s}"
|
47
|
+
assert !expr.include?(@date_20040116), "Second Friday of the month should not include #{@date_20040116.to_s}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_last_sunday_of_the_month
|
51
|
+
expr = DIMonth.new(Last_of,Sunday)
|
52
|
+
assert expr.include?(@date_20040125), "Last Sunday of the month should include #{@date_20040125}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_s
|
56
|
+
assert_equal 'last Sunday of the month', DIMonth.new(Last_of,Sunday).to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/test/diweektest.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for DIWeek class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class DIWeekTest < BaseExpressionTest
|
9
|
+
|
10
|
+
def test_day_in_week_te
|
11
|
+
expr = DIWeek.new(Friday)
|
12
|
+
assert expr.include?(@date_20040109), "'Friday' should include #{@date_20040109} which is a Friday"
|
13
|
+
assert expr.include?(@date_20040116), "'Friday' should include #{@date_20040116} which is a Friday"
|
14
|
+
assert !expr.include?(@date_20040125), "'Friday' should not include #{@date_20040125} which is a Sunday"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_day_in_week_te_to_s
|
18
|
+
assert_equal 'Friday', DIWeek.new(Friday).to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_day_in_week_dates
|
22
|
+
expr = DIWeek.new(Sunday)
|
23
|
+
dates = expr.dates(@date_20050101..@date_20050131)
|
24
|
+
assert dates.size == 5, "There are five Sundays in January, 2005: found #{dates.size}"
|
25
|
+
assert dates.include?(@date_20050102), "Should include #{@date_20050102}"
|
26
|
+
assert dates.include?(@date_20050109), "Should include #{@date_20050109}"
|
27
|
+
assert dates.include?(@date_20050116), "Should include #{@date_20050116}"
|
28
|
+
assert dates.include?(@date_20050123), "Should include #{@date_20050123}"
|
29
|
+
assert dates.include?(@date_20050130), "Should include #{@date_20050130}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/everytetest.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for EveryTE class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class EveryTETest < BaseExpressionTest
|
9
|
+
|
10
|
+
|
11
|
+
def test_every_2_minutes
|
12
|
+
date = @pdate_200401282100
|
13
|
+
expr=EveryTE.new(date, 2)
|
14
|
+
assert expr.include?(date + 2), "Expression #{expr.to_s} should include #{(date + 2).to_s}"
|
15
|
+
assert expr.include?(date + 4), "Expression #{expr.to_s} should include #{(date + 4).to_s}"
|
16
|
+
assert !expr.include?(date - 2), "Expression #{expr.to_s} should not include #{(date - 2).to_s}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_every_3_days
|
20
|
+
# Match every 3 days begining 2007-11-14
|
21
|
+
date = @pdate_20071114
|
22
|
+
expr=EveryTE.new(date, 3)
|
23
|
+
assert expr.include?(date + 6), "Expression #{expr.to_s} should include #{(date + 6).to_s}"
|
24
|
+
assert expr.include?(date + 9), "Expression #{expr.to_s} should include #{(date + 9).to_s}"
|
25
|
+
assert !expr.include?(date + 1), "Expression #{expr.to_s} should not include #{(date + 1).to_s}"
|
26
|
+
assert !expr.include?(date - 3), "Expression #{expr.to_s} should not include #{(date - 3).to_s}"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def test_to_s
|
31
|
+
date=@pdate_20071116100030
|
32
|
+
every_thirty_seconds=EveryTE.new(date, 30)
|
33
|
+
assert_equal "every 30 seconds starting #{Runt.format_date(date)}", every_thirty_seconds.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for Intersect class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class IntersectTest < BaseExpressionTest
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
@intersect = Intersect.new
|
13
|
+
@date = @pdate_20071008
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_to_s
|
17
|
+
assert_equal 'empty', @intersect.to_s
|
18
|
+
@intersect.add(@stub1)
|
19
|
+
assert_equal 'every ' + @stub1.to_s, @intersect.to_s
|
20
|
+
@intersect.add(@stub2)
|
21
|
+
assert_equal 'every ' + @stub1.to_s + ' and ' + @stub2.to_s, @intersect.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_include
|
26
|
+
assert !@intersect.include?(@date), "Empty Intersect instance should not include any dates"
|
27
|
+
@intersect.add(@stub1).add(@stub2) # both expressions will return false
|
28
|
+
assert !@intersect.include?(@date), "Intersect instance should not include any dates"
|
29
|
+
@stub2.match = true
|
30
|
+
assert !@intersect.include?(@date), "Intersect instance should not include any dates"
|
31
|
+
@stub1.match = true
|
32
|
+
assert @intersect.include?(@date), "Intersect instance should include any dates"
|
33
|
+
end
|
34
|
+
end
|
data/test/redaytest.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for REDay class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class REDayTest < BaseExpressionTest
|
9
|
+
|
10
|
+
|
11
|
+
def test_noon_to_430
|
12
|
+
#noon to 4:30pm
|
13
|
+
expr = REDay.new(12,0,16,30)
|
14
|
+
assert expr.include?(@pdate_2012050815), "Expression #{expr.to_s} should include #{@pdate_2012050815.to_s}"
|
15
|
+
assert expr.include?(@pdate_1922041816), "Expression #{expr.to_s} should include #{@pdate_1922041816.to_s}"
|
16
|
+
assert expr.include?(@pdate_1975060512), "Expression #{expr.to_s} should include #{@pdate_1975060512.to_s}"
|
17
|
+
assert !expr.include?(@pdate_2012050803), "Expression #{expr.to_s} should not include #{@pdate_2012050803.to_s}"
|
18
|
+
end
|
19
|
+
def test_830_to_midnight
|
20
|
+
expr = REDay.new(20,30,00,00)
|
21
|
+
assert expr.include?(@pdate_200401282100), "Expression #{expr.to_s} should include #{@pdate_200401282100.to_s}"
|
22
|
+
assert expr.include?(@pdate_200401280000), "Expression #{expr.to_s} should include #{@pdate_200401280000.to_s}"
|
23
|
+
assert !expr.include?(@pdate_200401280001), "Expression #{expr.to_s} should not include #{@pdate_200401280001.to_s}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_range_each_day_te_to_s
|
27
|
+
assert_equal 'from 11:10PM to 01:20AM daily', REDay.new(23,10,1,20).to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/test/remonthtest.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for REMonth class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class REMonthTest < BaseExpressionTest
|
9
|
+
|
10
|
+
|
11
|
+
def test_20th_thru_29th_of_every_month
|
12
|
+
expr = REMonth.new(20,29)
|
13
|
+
assert expr.include?(@date_20050123), "Expression #{expr.to_s} should include #{@date_20050123.to_s}"
|
14
|
+
assert !expr.include?(@date_20050116), "Expression #{expr.to_s} should not include #{@date_20050116.to_s}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_16th_of_every_month
|
18
|
+
expr = REMonth.new(16)
|
19
|
+
assert expr.include?(@date_20050116), "Expression #{expr.to_s} should include #{@date_20050116.to_s}"
|
20
|
+
assert !expr.include?(@date_20050123), "Expression #{expr.to_s} should not include #{@date_20050123.to_s}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_dates_mixin
|
24
|
+
expr = REMonth.new(22, 26)
|
25
|
+
dates = expr.dates(@pdate_20071024..@pdate_20071028)
|
26
|
+
assert dates.size == 3, "Expected 2 dates and got #{dates.size}"
|
27
|
+
# Use default Test::Unit assertion message
|
28
|
+
assert_equal "2007-10-24T00:00:00+00:00", dates[0].to_s
|
29
|
+
assert_equal "2007-10-25T00:00:00+00:00", dates[1].to_s
|
30
|
+
assert_equal "2007-10-26T00:00:00+00:00", dates[2].to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_range_each_month_to_s
|
34
|
+
assert_equal 'from the 2nd to the 5th monthly',REMonth.new(2,5).to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/test/reweektest.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for REWeek class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class REWeekTest < BaseExpressionTest
|
9
|
+
|
10
|
+
|
11
|
+
def test_invalid_ctor_arg
|
12
|
+
assert_raises(ArgumentError,"Expected ArgumentError for invalid day of week ordinal"){ REWeek.new(10,4) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_monday_thru_friday
|
16
|
+
expr = REWeek.new(Mon,Fri)
|
17
|
+
assert expr.include?(@date_20040116), "Expression #{expr.to_s} should include #{@date_20040116.to_s}"
|
18
|
+
assert !expr.include?(@date_20040125), "Expression #{expr.to_s} should not include #{@date_20040125.to_s}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_friday_thru_tuesday
|
22
|
+
expr = REWeek.new(Fri,Tue)
|
23
|
+
assert expr.include?(@date_20040125), "Expression #{expr.to_s} should include #{@date_20040125.to_s}"
|
24
|
+
assert !expr.include?(@pdate_20071024), "Expression #{expr.to_s} should not include #{@pdate_20071024.to_s}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_range_each_week_te
|
28
|
+
#Friday through Tuesday
|
29
|
+
expr = REWeek.new(Friday,Tuesday)
|
30
|
+
assert expr.include?(@time_20070928000000), "#{expr.inspect} should include Fri 12am"
|
31
|
+
assert expr.include?(@time_20070925115959), "#{expr.inspect} should include Tue 11:59pm"
|
32
|
+
assert !expr.include?(@time_20070926000000),"#{expr.inspect} should not include Wed 12am"
|
33
|
+
assert !expr.include?(@time_20070927065959),"#{expr.inspect} should not include Thurs 6:59am"
|
34
|
+
assert !expr.include?(@time_20070927115900),"#{expr.inspect} should not include Thurs 1159am"
|
35
|
+
assert expr.include?(@time_20070929110000), "#{expr.inspect} should include Sat 11am"
|
36
|
+
assert expr.include?(@time_20070929000000), "#{expr.inspect} should include Sat midnight"
|
37
|
+
assert expr.include?(@time_20070929235959), "#{expr.inspect} should include Saturday one minute before midnight"
|
38
|
+
assert expr.include?(@time_20070930235959), "#{expr.inspect} should include Sunday one minute before midnight"
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_to_s
|
42
|
+
assert_equal 'all week', REWeek.new(Tuesday,Tuesday).to_s
|
43
|
+
assert_equal 'Thursday through Saturday', REWeek.new(Thursday,Saturday).to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_dates_mixin
|
47
|
+
dates = REWeek.new(Tue,Wed).dates(@pdate_20071008..@pdate_20071030)
|
48
|
+
assert dates.size == 7
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/test/reyeartest.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'baseexpressiontest'
|
4
|
+
|
5
|
+
# Unit tests for REYear class
|
6
|
+
# Author:: Matthew Lipper
|
7
|
+
|
8
|
+
class REYearTest < BaseExpressionTest
|
9
|
+
|
10
|
+
def test_ctor_one_arg
|
11
|
+
expr = REYear.new(11)
|
12
|
+
assert expr.start_month == 11, "Start month should equal 11"
|
13
|
+
assert expr.end_month == 11, "End month should equal 11"
|
14
|
+
assert expr.start_day == REYear::NO_DAY, "Start day should equal constant NO_DAY"
|
15
|
+
assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ctor_two_args
|
19
|
+
expr = REYear.new(11,12)
|
20
|
+
assert expr.start_month == 11, "Start month should equal 11"
|
21
|
+
assert expr.end_month == 12, "End month should equal 12"
|
22
|
+
assert expr.start_day == REYear::NO_DAY, "Start day should equal constant NO_DAY"
|
23
|
+
assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_ctor_three_args
|
27
|
+
expr = REYear.new(10,21,12)
|
28
|
+
assert expr.start_month == 10, "Start month should equal 10"
|
29
|
+
assert expr.end_month == 12, "End month should equal 12"
|
30
|
+
assert expr.start_day == 21, "Start day should equal 21"
|
31
|
+
assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_ctor_three_args
|
35
|
+
expr = REYear.new(10,21,12,3)
|
36
|
+
assert expr.start_month == 10, "Start month should equal 10"
|
37
|
+
assert expr.end_month == 12, "End month should equal 12"
|
38
|
+
assert expr.start_day == 21, "Start day should equal 21"
|
39
|
+
assert expr.end_day == 3, "End day should equal 3"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_specific_days_same_month
|
43
|
+
expr = REYear.new(10,20,10,29)
|
44
|
+
assert expr.include?(@pdate_20071028), "#{expr.to_s} should include #{@pdate_20071028}"
|
45
|
+
assert !expr.include?(@pdate_20071114), "#{expr.to_s} should not include #{@pdate_20071114}"
|
46
|
+
assert !expr.include?(@pdate_20071030), "#{expr.to_s} should not include #{@pdate_20071030}"
|
47
|
+
assert !expr.include?(@pdate_20071008), "#{expr.to_s} should not include #{@pdate_20071008}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_specific_days_different_months
|
51
|
+
expr = REYear.new(5,31,9,6)
|
52
|
+
assert expr.include?(@pdate_198606), "#{expr.to_s} should include #{@pdate_198606}"
|
53
|
+
assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
|
54
|
+
assert !expr.include?(@pdate_20071008), "#{expr.to_s} should not include #{@pdate_20071008}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_default_days_different_months
|
58
|
+
expr = REYear.new(11,12)
|
59
|
+
assert expr.include?(@date_19611101), "#{expr.to_s} should include #{@date_19611101}"
|
60
|
+
assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_all_defaults
|
64
|
+
expr = REYear.new(8)
|
65
|
+
assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
|
66
|
+
assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
|
67
|
+
assert !expr.include?(@date_19611101), "#{expr.to_s} should not include #{@date_19611101}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_same_days_same_month
|
71
|
+
# Bug #5741
|
72
|
+
expr = REYear.new(9,21,9,21)
|
73
|
+
assert expr.include?(@pdate_20060921), "#{expr.to_s} should include #{@pdate_20060921.to_s}"
|
74
|
+
assert !expr.include?(@pdate_20060914), "#{expr.to_s} should not include #{@pdate_20060914.to_s}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_to_s
|
78
|
+
assert_equal 'June 1st through July 2nd', REYear.new(6, 1, 7, 2).to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_dates_mixin
|
82
|
+
expr = REYear.new(4, 28, 5, 6)
|
83
|
+
assert (expr.dates(@date_20040501..@date_20060504)).size == 22, "Should be 22 occurences in dates Array"
|
84
|
+
end
|
85
|
+
|
86
|
+
# From bug #5749
|
87
|
+
def test_mixed_precision_combo
|
88
|
+
# 10:00 am to 10:01 am
|
89
|
+
ten_ish = REDay.new(10,0,10,1)
|
90
|
+
# September 21st every year
|
91
|
+
every_21_sept = REYear.new(9,21,9,21)
|
92
|
+
# Between 10:00 am and 10:01 am every September 21st
|
93
|
+
combo = ten_ish & every_21_sept
|
94
|
+
assert !combo.include?(@pdate_20060921), "Should not include lower precision argument"
|
95
|
+
assert combo.include?(@pdate_200609211001), "Should include matching precision argument which is in range"
|
96
|
+
assert !combo.include?(@pdate_200609211002), "Should not include matching precision argument which is out of range"
|
97
|
+
end
|
98
|
+
end
|
data/test/rspectest.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
|
4
|
+
require 'baseexpressiontest'
|
5
|
+
|
6
|
+
# Unit tests for RSpec class
|
7
|
+
# Author:: Matthew Lipper
|
8
|
+
|
9
|
+
class RSpecTest < BaseExpressionTest
|
10
|
+
|
11
|
+
def test_include
|
12
|
+
rspec = RSpec.new(@stub1)
|
13
|
+
assert !rspec.include?("Any Object"), "Expression should not include any given argument"
|
14
|
+
@stub1.match = true
|
15
|
+
assert rspec.include?("Any Object"), "Expression should include any given argument"
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_overlap
|
19
|
+
range = DateRange.new(@date_20050101, @date_20050109)
|
20
|
+
rspec = RSpec.new(range)
|
21
|
+
assert !rspec.include?(@date_20050116), "Expression #{rspec.to_s} should not include #{@date_20050116.to_s}"
|
22
|
+
assert rspec.include?(@date_20050102), "Expression #{rspec.to_s} should include #{@date_20050102.to_s}"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/spectest.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
|
4
|
+
require 'baseexpressiontest'
|
5
|
+
|
6
|
+
# Unit tests for Spec class
|
7
|
+
# Author:: Matthew Lipper
|
8
|
+
|
9
|
+
class SpecTest < BaseExpressionTest
|
10
|
+
|
11
|
+
def setup
|
12
|
+
super
|
13
|
+
@spec = Spec.new(@stub1)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_initialize
|
17
|
+
assert_same @stub1, @spec.date_expr, "Expected #{@stub1}, instead got #{@spec.date_expr}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_include_arg_has_include_method
|
21
|
+
assert !@spec.include?(@stub2), "Expression should not include configured stub"
|
22
|
+
@stub2.match = true
|
23
|
+
assert @spec.include?(@stub2), "Expression should include configured stub"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_include_arg_without_include_method
|
27
|
+
@spec = Spec.new(4)
|
28
|
+
assert !@spec.include?(3), "Expression #{@spec.to_s} should not include 3"
|
29
|
+
assert @spec.include?(4), "Expression #{@spec.to_s} should include 4"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_to_s
|
33
|
+
assert_equal @stub1.to_s, @spec.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|