runt 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +153 -125
- data/LICENSE.txt +43 -43
- data/README +106 -100
- data/Rakefile +122 -122
- data/TODO +13 -13
- data/doc/tutorial_schedule.rdoc +393 -393
- data/doc/tutorial_sugar.rdoc +143 -0
- data/doc/tutorial_te.rdoc +190 -190
- data/examples/payment_report.rb +59 -0
- data/examples/payment_reporttest.rb +49 -0
- data/examples/reminder.rb +63 -63
- data/lib/runt.rb +237 -219
- data/lib/runt/daterange.rb +74 -74
- data/lib/runt/dprecision.rb +150 -141
- data/lib/runt/expressionbuilder.rb +65 -0
- data/lib/runt/pdate.rb +165 -153
- data/lib/runt/schedule.rb +88 -88
- data/lib/runt/sugar.rb +171 -0
- data/lib/runt/temporalexpression.rb +789 -777
- data/setup.rb +1331 -1331
- data/site/blue-robot3.css +131 -131
- data/site/dcl-small.gif +0 -0
- data/site/index.html +72 -94
- data/site/runt-logo.gif +0 -0
- data/site/runt-logo.psd +0 -0
- data/test/aftertetest.rb +31 -0
- data/test/beforetetest.rb +31 -0
- data/test/daterangetest.rb +89 -89
- data/test/dprecisiontest.rb +58 -55
- data/test/expressionbuildertest.rb +64 -0
- data/test/icalendartest.rb +621 -41
- data/test/pdatetest.rb +147 -117
- data/test/redaytest.rb +10 -0
- data/test/reyeartest.rb +99 -98
- data/test/runttest.rb +98 -101
- data/test/scheduletest.rb +148 -148
- data/test/sugartest.rb +104 -0
- data/test/temporalexpressiontest.rb +76 -76
- metadata +112 -95
data/test/pdatetest.rb
CHANGED
@@ -1,117 +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
|
-
@
|
20
|
-
#11:
|
21
|
-
@
|
22
|
-
#
|
23
|
-
@
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
assert(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
assert(!
|
47
|
-
|
48
|
-
assert(
|
49
|
-
|
50
|
-
assert(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
assert(PDate.
|
57
|
-
assert(PDate.
|
58
|
-
assert(PDate.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
assert(PDate.
|
66
|
-
assert(PDate.
|
67
|
-
assert(PDate.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
assert(PDate.
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
assert(
|
76
|
-
assert(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
r_min
|
94
|
-
assert( r_min.include?(PDate.min(2004,
|
95
|
-
assert(
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
#December
|
105
|
-
|
106
|
-
#December
|
107
|
-
|
108
|
-
assert(
|
109
|
-
#December 2004
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
CHANGED
@@ -26,5 +26,15 @@ class REDayTest < BaseExpressionTest
|
|
26
26
|
def test_range_each_day_te_to_s
|
27
27
|
assert_equal 'from 11:10PM to 01:20AM daily', REDay.new(23,10,1,20).to_s
|
28
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
|
29
39
|
|
30
40
|
end
|
data/test/reyeartest.rb
CHANGED
@@ -1,98 +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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
assert expr.include?(@
|
54
|
-
assert
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
assert
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
assert
|
67
|
-
assert !expr.include?(@
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
assert
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
assert combo.include?(@
|
96
|
-
assert
|
97
|
-
|
98
|
-
end
|
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
|