runt19 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/History.txt +153 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +44 -0
- data/Manifest.txt +112 -0
- data/README.md +29 -0
- data/README.txt +106 -0
- data/Rakefile +2 -0
- data/TODO +13 -0
- data/examples/payment_report.rb +59 -0
- data/examples/payment_reporttest.rb +49 -0
- data/examples/reminder.rb +63 -0
- data/examples/schedule_tutorial.rb +59 -0
- data/examples/schedule_tutorialtest.rb +52 -0
- data/lib/runt.rb +249 -0
- data/lib/runt/daterange.rb +74 -0
- data/lib/runt/dprecision.rb +150 -0
- data/lib/runt/expressionbuilder.rb +65 -0
- data/lib/runt/pdate.rb +165 -0
- data/lib/runt/schedule.rb +88 -0
- data/lib/runt/sugar.rb +171 -0
- data/lib/runt/temporalexpression.rb +795 -0
- data/lib/runt/version.rb +3 -0
- data/lib/runt19.rb +1 -0
- data/runt19.gemspec +17 -0
- data/setup.rb +1331 -0
- data/site/blue-robot3.css +132 -0
- data/site/dcl-small.gif +0 -0
- data/site/index.html +72 -0
- data/site/logohover.png +0 -0
- data/site/runt-logo.gif +0 -0
- data/site/runt-logo.psd +0 -0
- data/test/aftertetest.rb +31 -0
- data/test/baseexpressiontest.rb +110 -0
- data/test/beforetetest.rb +31 -0
- data/test/collectiontest.rb +63 -0
- data/test/combinedexpressionstest.rb +158 -0
- data/test/daterangetest.rb +89 -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/dprecisiontest.rb +58 -0
- data/test/everytetest.rb +36 -0
- data/test/expressionbuildertest.rb +64 -0
- data/test/icalendartest.rb +1104 -0
- data/test/intersecttest.rb +34 -0
- data/test/pdatetest.rb +147 -0
- data/test/redaytest.rb +40 -0
- data/test/remonthtest.rb +37 -0
- data/test/reweektest.rb +51 -0
- data/test/reyeartest.rb +99 -0
- data/test/rspectest.rb +25 -0
- data/test/runttest.rb +98 -0
- data/test/scheduletest.rb +148 -0
- data/test/spectest.rb +36 -0
- data/test/sugartest.rb +104 -0
- data/test/temporalexpressiontest.rb +76 -0
- data/test/uniontest.rb +36 -0
- data/test/wimonthtest.rb +54 -0
- data/test/yeartetest.rb +22 -0
- metadata +137 -0
@@ -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/pdatetest.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'date'
|
5
|
+
require 'runt'
|
6
|
+
|
7
|
+
# Unit tests for PDate class
|
8
|
+
# Author:: Matthew Lipper
|
9
|
+
class PDateTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
include Runt
|
12
|
+
|
13
|
+
def setup
|
14
|
+
# 2010 (August - ignored)
|
15
|
+
@year_prec = PDate.year(2010,8)
|
16
|
+
#August, 2004
|
17
|
+
@month_prec = PDate.month(2004,8)
|
18
|
+
#January 25th, 2004 (11:39 am - ignored)
|
19
|
+
@week_prec = PDate.week(2004,1,25,11,39)
|
20
|
+
#January 25th, 2004 (11:39 am - ignored)
|
21
|
+
@day_prec = PDate.day(2004,1,25,11,39)
|
22
|
+
#11:59(:04 - ignored), December 31st, 1999
|
23
|
+
@minute_prec = PDate.min(1999,12,31,23,59,4)
|
24
|
+
#12:00:10 am, March 1st, 2004
|
25
|
+
@second_prec = PDate.sec(2004,3,1,0,0,10)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_marshal
|
29
|
+
# Thanks to Jodi Showers for finding/fixing this bug
|
30
|
+
pdate=PDate.new(2004,2,29,22,13,2)
|
31
|
+
assert_not_nil pdate.date_precision
|
32
|
+
data=Marshal.dump pdate
|
33
|
+
obj=Marshal.load data
|
34
|
+
assert_not_nil obj.date_precision
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_include
|
38
|
+
pdate = PDate.new(2006,3,10)
|
39
|
+
assert(pdate.include?(Date.new(2006,3,10)))
|
40
|
+
date = Date.new(2006,3,10)
|
41
|
+
assert(date.include?(PDate.new(2006,3,10)))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_new
|
45
|
+
date = PDate.new(2004,2,29)
|
46
|
+
assert(!date.date_precision.nil?)
|
47
|
+
date_time = PDate.new(2004,2,29,22,13,2)
|
48
|
+
assert(!date_time.date_precision.nil?)
|
49
|
+
date2 = PDate.day(2004,2,29)
|
50
|
+
assert(date==date2)
|
51
|
+
date_time2 = PDate.sec(2004,2,29,22,13,2)
|
52
|
+
assert(date_time==date_time2)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_plus
|
56
|
+
assert(PDate.year(2022,12)==(@year_prec+12))
|
57
|
+
assert(PDate.month(2005,2)==(@month_prec+6))
|
58
|
+
assert(PDate.week(2004,2,1)==(@week_prec+1))
|
59
|
+
assert(PDate.day(2004,2,1)==(@day_prec+7))
|
60
|
+
assert(PDate.min(2000,1,1,0,0)==(@minute_prec+1))
|
61
|
+
assert(PDate.sec(2004,3,1,0,0,21)==(@second_prec+11))
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_minus
|
65
|
+
assert(PDate.year(1998,12)==(@year_prec-12))
|
66
|
+
assert(PDate.month(2002,6)==(@month_prec-26))
|
67
|
+
assert(PDate.week(2004,1,11)==(@week_prec-2))
|
68
|
+
#Hmmm...FIXME? @day_prec-26 == 12/31??
|
69
|
+
assert(PDate.day(2003,12,30)==(@day_prec-26))
|
70
|
+
assert(PDate.min(1999,12,31,21,57)==(@minute_prec-122))
|
71
|
+
assert(PDate.sec(2004,2,29,23,59,59)==(@second_prec-11))
|
72
|
+
end
|
73
|
+
def test_spaceship_comparison_operator
|
74
|
+
sec_prec = PDate.sec(2002,8,28,6,04,02)
|
75
|
+
assert(PDate.year(1998,12)<sec_prec)
|
76
|
+
assert(PDate.month(2002,9)>sec_prec)
|
77
|
+
assert(PDate.week(2002,8,28)==sec_prec)
|
78
|
+
assert(PDate.day(2002,8,28)==sec_prec)
|
79
|
+
assert(PDate.min(1999,12,31,21,57)<sec_prec)
|
80
|
+
assert(DateTime.new(2002,8,28,6,04,02)==sec_prec)
|
81
|
+
assert(Date.new(2004,8,28)>sec_prec)
|
82
|
+
end
|
83
|
+
def test_succ
|
84
|
+
#~ fail("FIXME! Implement succ")
|
85
|
+
end
|
86
|
+
def test_range
|
87
|
+
#11:50 pm (:22 seconds ignored), February 2nd, 2004
|
88
|
+
min1 = PDate.min(2004,2,29,23,50,22)
|
89
|
+
#12:02 am , March 1st, 2004
|
90
|
+
min2 = PDate.min(2004,3,1,0,2)
|
91
|
+
#Inclusive Range w/minute precision
|
92
|
+
r_min = min1..min2
|
93
|
+
assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
|
94
|
+
assert( r_min.include?(PDate.min(2004,3,1,0,2)) )
|
95
|
+
assert( r_min.include?(PDate.min(2004,3,1,0,0)) )
|
96
|
+
assert( ! r_min.include?(PDate.min(2004,3,1,0,3)) )
|
97
|
+
#Exclusive Range w/minute precision
|
98
|
+
r_min = min1...min2
|
99
|
+
assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
|
100
|
+
assert( !r_min.include?(PDate.min(2004,3,1,0,2)) )
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_create_with_class_methods
|
104
|
+
#December 12th, 1968
|
105
|
+
no_prec = PDate.civil(1968,12,12)
|
106
|
+
#December 12th, 1968 (at 11:15 am - ignored)
|
107
|
+
day_prec = PDate.day(1968,12,12,11,15)
|
108
|
+
assert(no_prec==day_prec, "PDate instance does not equal precisioned instance.")
|
109
|
+
#December 2004 (24th - ignored)
|
110
|
+
month_prec1 = PDate.month(2004,12,24)
|
111
|
+
#December 31st, 2004 (31st - ignored)
|
112
|
+
month_prec2 = PDate.month(2004,12,31)
|
113
|
+
assert(month_prec1==month_prec2, "PDate.month instances not equal.")
|
114
|
+
#December 2004
|
115
|
+
month_prec3 = PDate.month(2004,12)
|
116
|
+
assert(month_prec1==month_prec3, "PDate.month instances not equal.")
|
117
|
+
assert(month_prec2==month_prec3, "PDate.month instances not equal.")
|
118
|
+
#December 2003
|
119
|
+
month_prec4 = PDate.month(2003,12)
|
120
|
+
assert(month_prec4!=month_prec1, "PDate.month instances not equal.")
|
121
|
+
|
122
|
+
one_week = [
|
123
|
+
PDate.week(2004, 12, 20), # Monday
|
124
|
+
PDate.week(2004, 12, 21), # Tuesday
|
125
|
+
PDate.week(2004, 12, 22), # Wednesday
|
126
|
+
PDate.week(2004, 12, 23), # Thursday
|
127
|
+
PDate.week(2004, 12, 24), # Friday
|
128
|
+
PDate.week(2004, 12, 25), # Saturday
|
129
|
+
PDate.week(2004, 12, 26), # Sunday
|
130
|
+
]
|
131
|
+
|
132
|
+
one_week.each do |week_prec1|
|
133
|
+
one_week.each do |week_prec2|
|
134
|
+
assert_equal week_prec1, week_prec2
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
week_before = PDate.week(2004, 12, 19)
|
139
|
+
week_after = PDate.week(2004, 12, 27)
|
140
|
+
|
141
|
+
one_week.each do |week_prec|
|
142
|
+
assert week_prec != week_before
|
143
|
+
assert week_prec != week_after
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
data/test/redaytest.rb
ADDED
@@ -0,0 +1,40 @@
|
|
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
|
+
def test_less_precise_argument_and_precision_policy
|
31
|
+
expr = REDay.new(8,00,10,00)
|
32
|
+
assert expr.include?(@pdate_20040531), \
|
33
|
+
"Expression #{expr.to_s} should include any lower precision argument by default"
|
34
|
+
|
35
|
+
expr = REDay.new(8,00,10,00, false)
|
36
|
+
assert !expr.include?(@pdate_20040531), \
|
37
|
+
"Expression #{expr.to_s} created with less_precise_match=false should not include any lower precision argument automatically"
|
38
|
+
end
|
39
|
+
|
40
|
+
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,99 @@
|
|
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
|
+
assert !expr.include?(@pdate_20060921), "#{expr.to_s} should not include #{@pdate_20060921}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_specific_days_different_months
|
52
|
+
expr = REYear.new(5,31,9,6)
|
53
|
+
assert expr.include?(@pdate_198606), "#{expr.to_s} should include #{@pdate_198606}"
|
54
|
+
assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
|
55
|
+
assert !expr.include?(@pdate_20071008), "#{expr.to_s} should not include #{@pdate_20071008}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_default_days_different_months
|
59
|
+
expr = REYear.new(11,12)
|
60
|
+
assert expr.include?(@date_19611101), "#{expr.to_s} should include #{@date_19611101}"
|
61
|
+
assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_all_defaults
|
65
|
+
expr = REYear.new(8)
|
66
|
+
assert expr.include?(@date_20040806), "#{expr.to_s} should include #{@date_20040806}"
|
67
|
+
assert !expr.include?(@pdate_198606), "#{expr.to_s} should not include #{@pdate_198606}"
|
68
|
+
assert !expr.include?(@date_19611101), "#{expr.to_s} should not include #{@date_19611101}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_same_days_same_month
|
72
|
+
# Bug #5741
|
73
|
+
expr = REYear.new(9,21,9,21)
|
74
|
+
assert expr.include?(@pdate_20060921), "#{expr.to_s} should include #{@pdate_20060921.to_s}"
|
75
|
+
assert !expr.include?(@pdate_20060914), "#{expr.to_s} should not include #{@pdate_20060914.to_s}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_to_s
|
79
|
+
assert_equal 'June 1st through July 2nd', REYear.new(6, 1, 7, 2).to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_dates_mixin
|
83
|
+
expr = REYear.new(4, 28, 5, 6)
|
84
|
+
assert((expr.dates(@date_20040501..@date_20060504)).size == 22, "Should be 22 occurences in dates Array")
|
85
|
+
end
|
86
|
+
|
87
|
+
# From bug #5749
|
88
|
+
def test_mixed_precision_combo
|
89
|
+
# 10:00 am to 10:01 am
|
90
|
+
ten_ish = REDay.new(10,0,10,1)
|
91
|
+
# September 21st every year
|
92
|
+
every_21_sept = REYear.new(9,21,9,21)
|
93
|
+
# Between 10:00 am and 10:01 am every September 21st
|
94
|
+
combo = ten_ish & every_21_sept
|
95
|
+
assert combo.include?(@pdate_20060921), "Should include lower precision argument"
|
96
|
+
assert combo.include?(@pdate_200609211001), "Should include matching precision argument which is in range"
|
97
|
+
assert !combo.include?(@pdate_200609211002), "Should not include matching precision argument which is out of range"
|
98
|
+
end
|
99
|
+
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/runttest.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'runt'
|
5
|
+
require 'date'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
class RuntModuleTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_last
|
11
|
+
assert Runt::Last == -1
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_last_of
|
15
|
+
assert Runt::Last_of == -1
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_second_to_last
|
19
|
+
assert Runt::Second_to_last == -2
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_ordinals
|
23
|
+
#1.upto(31){ |n| puts Runt.ordinalize(n); }
|
24
|
+
assert_equal '1st', Runt.ordinalize(1)
|
25
|
+
assert_equal '33rd', Runt.ordinalize(33)
|
26
|
+
assert_equal '50th', Runt.ordinalize(50)
|
27
|
+
assert_equal '2nd', Runt.ordinalize(2)
|
28
|
+
assert_equal 'second to last', Runt.ordinalize(-2)
|
29
|
+
assert_equal 'last', Runt.ordinalize(-1)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_day_name
|
33
|
+
i=0
|
34
|
+
Date::DAYNAMES.each do |n|
|
35
|
+
assert_equal Date::DAYNAMES[i], Runt.day_name(i)
|
36
|
+
i=i+1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_month_name
|
41
|
+
i=0
|
42
|
+
Date::MONTHNAMES.each do |n|
|
43
|
+
assert_equal Date::MONTHNAMES[i], Runt.month_name(i)
|
44
|
+
i=i+1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_strftime
|
49
|
+
d=DateTime.new(2006,2,26,14,45)
|
50
|
+
assert_equal '02:45PM', Runt.format_time(d)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_numeric_class_additions
|
54
|
+
assert_equal 0.000001, 1.microsecond
|
55
|
+
assert_equal 0.000001, 1.microseconds
|
56
|
+
assert_equal 0.001, 1.millisecond
|
57
|
+
assert_equal 0.001, 1.milliseconds
|
58
|
+
assert_equal 7, 7.second
|
59
|
+
assert_equal 7, 7.seconds
|
60
|
+
assert_equal 60, 1.minute
|
61
|
+
assert_equal 60, 1.minutes
|
62
|
+
assert_equal 3600, 1.hour
|
63
|
+
assert_equal 3600, 1.hours
|
64
|
+
assert_equal 86400, 1.day
|
65
|
+
assert_equal 86400, 1.days
|
66
|
+
assert_equal 604800, 1.week
|
67
|
+
assert_equal 604800, 1.weeks
|
68
|
+
assert_equal 2592000, 1.month
|
69
|
+
assert_equal 2592000, 1.months
|
70
|
+
assert_equal 31536000, 1.year
|
71
|
+
assert_equal 31536000, 1.years
|
72
|
+
assert_equal 315360000, 1.decade
|
73
|
+
assert_equal 315360000, 1.decades
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_time_class_dprecision
|
77
|
+
time=Time.parse('Monday 06 November 2006 07:38')
|
78
|
+
assert_equal(Runt::DPrecision::DEFAULT,time.date_precision)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_date_class_dprecision
|
82
|
+
date=Date.today
|
83
|
+
assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_datetime_class_dprecision
|
87
|
+
date=DateTime.civil
|
88
|
+
assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_time_plus
|
92
|
+
time=Time.local(2006, 12, 9, 5, 56, 12)
|
93
|
+
# Default precision is minute
|
94
|
+
assert_equal(Runt::PDate.min(2006,12,9,5,56),Runt::DPrecision.to_p(time))
|
95
|
+
assert_not_equal(Time.parse("Sat Dec 09 05:56:00 -0500 2006"),time)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|