runt 0.6.0 → 0.7.0

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.
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'runt'
5
+ require 'runt/sugar'
6
+
7
+ class SugarTest < Test::Unit::TestCase
8
+ include Runt
9
+
10
+ def test_build__should_return_nil_when_an_unknown_name_is_given
11
+ assert self.build('duh').nil?
12
+ end
13
+
14
+ def test_method_missing_should_be_called_for_invalid_name
15
+ begin
16
+ self.some_tuesday
17
+ rescue NoMethodError
18
+ # YAY!
19
+ end
20
+ end
21
+
22
+ def test_const_should_return_runt_constant
23
+ assert_equal Runt::Monday, Runt.const('monday'), \
24
+ "Expected #{Runt::Monday} but was #{Runt.const('monday')}"
25
+ end
26
+
27
+ def test_method_missing_should_define_dimonth
28
+ make_ordinals.each do |ordinal|
29
+ make_days.each do |day|
30
+ name = ordinal + '_' + day
31
+ result = self.send(name)
32
+ expected = DIMonth.new(Runt.const(ordinal), Runt.const(day))
33
+ assert_expression expected, result
34
+ end
35
+ end
36
+ end
37
+
38
+ def test_method_missing_should_define_diweek
39
+ assert_expression(DIWeek.new(Monday), self.monday)
40
+ assert_expression(DIWeek.new(Tuesday), self.tuesday)
41
+ assert_expression(DIWeek.new(Wednesday), self.wednesday)
42
+ assert_expression(DIWeek.new(Thursday), self.thursday)
43
+ assert_expression(DIWeek.new(Friday), self.friday)
44
+ assert_expression(DIWeek.new(Saturday), self.saturday)
45
+ assert_expression(DIWeek.new(Sunday), self.sunday)
46
+ end
47
+
48
+ def test_parse_time
49
+ assert_equal [13,2], parse_time('1','02','pm')
50
+ assert_equal [1,2], parse_time('1','02','am')
51
+ end
52
+
53
+ def test_method_missing_should_define_re_day
54
+ assert_expression(REDay.new(8,45,14,00), daily_8_45am_to_2_00pm)
55
+ end
56
+
57
+ def test_method_missing_should_define_re_week
58
+ make_days.each do |st_day|
59
+ make_days.each do |end_day|
60
+ if Runt.const(st_day) <= Runt.const(end_day) then
61
+ assert_expression REWeek.new(Runt.const(st_day), \
62
+ Runt.const(end_day)), self.send('weekly_' + st_day + '_to_' + end_day)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def test_method_missing_should_define_re_month
69
+ assert_expression(REMonth.new(3,14), monthly_3rd_to_14th)
70
+ end
71
+ def test_method_missing_should_define_re_year
72
+ # Imperfect but "good enough" for now
73
+ make_months.each do |st_month|
74
+ make_months.each do |end_month|
75
+ st_mon_number = Runt.const(st_month)
76
+ end_mon_number = Runt.const(end_month)
77
+ next if st_mon_number > end_mon_number
78
+ st_day = rand(27) + 1
79
+ end_day = rand(27) + 1
80
+ if st_mon_number == end_mon_number && st_day > end_day then
81
+ st_day, end_day = end_day, st_day
82
+ end
83
+ #puts "Checking #{st_month} #{st_day} - #{end_month} #{end_day}"
84
+ assert_expression REYear.new(st_mon_number, st_day, end_mon_number, end_day), \
85
+ self.send('yearly_' + st_month + '_' + st_day.to_s + '_to_' + end_month + '_' + end_day.to_s)
86
+ end
87
+ end
88
+ end
89
+
90
+ private
91
+ def assert_expression(expected, actual)
92
+ assert_equal expected.to_s, actual.to_s, \
93
+ "Expected #{expected.to_s} but was #{actual.to_s}"
94
+ end
95
+ def make_ordinals
96
+ Runt::WEEK_OF_MONTH_ORDINALS.delete('()').split('|')
97
+ end
98
+ def make_days
99
+ Runt::DAYS.delete('()').split('|')
100
+ end
101
+ def make_months
102
+ Runt::MONTHS.delete('()').split('|')
103
+ end
104
+ end
@@ -1,76 +1,76 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'baseexpressiontest'
4
-
5
- # Unit tests for TExpr classes
6
- # Author:: Matthew Lipper
7
-
8
- class TExprTest < BaseExpressionTest
9
-
10
- include TExpr
11
-
12
- def test_include
13
- assert !self.include?(true), "Default include? method should always return false"
14
- end
15
-
16
- def test_to_s
17
- assert_equal self.to_s, 'TExpr', "Default to_s method should always return 'TExpr'"
18
- end
19
-
20
- def test_or_from_union
21
- union = Union.new
22
- same_union = union.or(@stub1)
23
- assert_same union, same_union, "Expected same Union instance that received the or method"
24
- assert_same @stub1, union.expressions.first, "Union instance should have added the stub expression"
25
- end
26
-
27
- def test_or_from_nonunion
28
- result = @stub1.or(@stub2) {|e| e}
29
- assert_equal Runt::Union, result.class, "Expected an Union instance. Instead got #{result.class}"
30
- assert_same @stub1, result.expressions.first, "Result should be new Union instance containing both stub expressions"
31
- assert_same @stub2, result.expressions.last, "Result should be new Union instance containing both stub expressions"
32
- end
33
-
34
- def test_and_from_intersect
35
- intersect = Intersect.new
36
- result = intersect.and(@stub1)
37
- assert_same intersect, result, "Expected same Intersect instance that received the and method"
38
- assert_same @stub1, intersect.expressions.first, "Intersect instance should have added the stub expression"
39
- end
40
-
41
- def test_or_from_nonintersect
42
- result = @stub1.and(@stub2) {|e| e}
43
- assert_equal Runt::Intersect, result.class, "Expected an Intersect instance. Instead got #{result.class}"
44
- assert_same @stub1, result.expressions.first, "Result should be new Intersect instance containing both stub expressions"
45
- assert_same @stub2, result.expressions.last, "Result should be new Intersect instance containing both stub expressions"
46
- end
47
-
48
- def test_minus
49
- result = @stub1.minus(@stub2) {|e| e}
50
- assert_equal Runt::Diff, result.class, "Expected an Diff instance. Instead got #{result.class}"
51
- assert_same @stub1, result.expr1, "Expected first stub instance used to create Diff expression"
52
- assert_same @stub2, result.expr2, "Expected second stub instance used to create Diff expression"
53
- end
54
-
55
- def test_dates_no_limit
56
- # Normally, your range is made up of Date-like Objects
57
- range = 1..3
58
- assert @stub1.dates(range).empty?, "Expected empty Array of Objects returned from stub expression"
59
- @stub1.match = true
60
- result = @stub1.dates(range)
61
- assert_equal 1, result[0], "Expected Array of Objects given by range to be returned from stub expression"
62
- assert_equal 2, result[1], "Expected Array of Objects given by range to be returned from stub expression"
63
- assert_equal 3, result[2], "Expected Array of Objects given by range to be returned from stub expression"
64
- end
65
-
66
- def test_dates_with_limit
67
- range = 1..3
68
- assert @stub1.dates(range).empty?, "Expected empty Array of Objects returned from stub expression"
69
- @stub1.match = true
70
- result = @stub1.dates(range,2)
71
- assert_equal 2, result.size, "Expected Array of only 2 Objects. Got #{result.size}"
72
- assert_equal 1, result[0], "Expected Array of Objects given by range to be returned from stub expression"
73
- assert_equal 2, result[1], "Expected Array of Objects given by range to be returned from stub expression"
74
- end
75
-
76
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'baseexpressiontest'
4
+
5
+ # Unit tests for TExpr classes
6
+ # Author:: Matthew Lipper
7
+
8
+ class TExprTest < BaseExpressionTest
9
+
10
+ include TExpr
11
+
12
+ def test_include
13
+ assert !self.include?(true), "Default include? method should always return false"
14
+ end
15
+
16
+ def test_to_s
17
+ assert_equal self.to_s, 'TExpr', "Default to_s method should always return 'TExpr'"
18
+ end
19
+
20
+ def test_or_from_union
21
+ union = Union.new
22
+ same_union = union.or(@stub1)
23
+ assert_same union, same_union, "Expected same Union instance that received the or method"
24
+ assert_same @stub1, union.expressions.first, "Union instance should have added the stub expression"
25
+ end
26
+
27
+ def test_or_from_nonunion
28
+ result = @stub1.or(@stub2) {|e| e}
29
+ assert_equal Runt::Union, result.class, "Expected an Union instance. Instead got #{result.class}"
30
+ assert_same @stub1, result.expressions.first, "Result should be new Union instance containing both stub expressions"
31
+ assert_same @stub2, result.expressions.last, "Result should be new Union instance containing both stub expressions"
32
+ end
33
+
34
+ def test_and_from_intersect
35
+ intersect = Intersect.new
36
+ result = intersect.and(@stub1)
37
+ assert_same intersect, result, "Expected same Intersect instance that received the and method"
38
+ assert_same @stub1, intersect.expressions.first, "Intersect instance should have added the stub expression"
39
+ end
40
+
41
+ def test_or_from_nonintersect
42
+ result = @stub1.and(@stub2) {|e| e}
43
+ assert_equal Runt::Intersect, result.class, "Expected an Intersect instance. Instead got #{result.class}"
44
+ assert_same @stub1, result.expressions.first, "Result should be new Intersect instance containing both stub expressions"
45
+ assert_same @stub2, result.expressions.last, "Result should be new Intersect instance containing both stub expressions"
46
+ end
47
+
48
+ def test_minus
49
+ result = @stub1.minus(@stub2) {|e| e}
50
+ assert_equal Runt::Diff, result.class, "Expected an Diff instance. Instead got #{result.class}"
51
+ assert_same @stub1, result.expr1, "Expected first stub instance used to create Diff expression"
52
+ assert_same @stub2, result.expr2, "Expected second stub instance used to create Diff expression"
53
+ end
54
+
55
+ def test_dates_no_limit
56
+ # Normally, your range is made up of Date-like Objects
57
+ range = 1..3
58
+ assert @stub1.dates(range).empty?, "Expected empty Array of Objects returned from stub expression"
59
+ @stub1.match = true
60
+ result = @stub1.dates(range)
61
+ assert_equal 1, result[0], "Expected Array of Objects given by range to be returned from stub expression"
62
+ assert_equal 2, result[1], "Expected Array of Objects given by range to be returned from stub expression"
63
+ assert_equal 3, result[2], "Expected Array of Objects given by range to be returned from stub expression"
64
+ end
65
+
66
+ def test_dates_with_limit
67
+ range = 1..3
68
+ assert @stub1.dates(range).empty?, "Expected empty Array of Objects returned from stub expression"
69
+ @stub1.match = true
70
+ result = @stub1.dates(range,2)
71
+ assert_equal 2, result.size, "Expected Array of only 2 Objects. Got #{result.size}"
72
+ assert_equal 1, result[0], "Expected Array of Objects given by range to be returned from stub expression"
73
+ assert_equal 2, result[1], "Expected Array of Objects given by range to be returned from stub expression"
74
+ end
75
+
76
+ end
metadata CHANGED
@@ -1,131 +1,148 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: runt
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.6.0
7
- date: 2007-12-31 00:00:00 -05:00
8
- summary: Ruby Temporal Expressions.
9
- require_paths:
10
- - lib
11
- email: mlipper@gmail.com
12
- homepage: http://runt.rubyforge.org
13
- rubyforge_project: runt
14
- description: Runt is a Ruby version of temporal patterns by Martin Fowler. Runt provides an API for scheduling recurring events using set-like semantics.
15
- autorequire: runt
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.7.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Matthew Lipper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-30 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Runt is a Ruby version of temporal patterns by Martin Fowler. Runt provides an API for scheduling recurring events using set-like semantics.
17
+ email: mlipper@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - CHANGES
25
+ - TODO
26
+ - LICENSE.txt
27
+ - doc/tutorial_te.rdoc
28
+ - doc/tutorial_schedule.rdoc
29
+ - doc/tutorial_sugar.rdoc
31
30
  files:
32
31
  - setup.rb
33
- - CHANGES
34
- - doc
35
- - examples
36
- - lib
37
32
  - LICENSE.txt
38
33
  - Rakefile
39
- - README
40
- - site
41
- - test
42
34
  - TODO
43
- - lib/runt/daterange.rb
44
- - lib/runt/dprecision.rb
35
+ - CHANGES
36
+ - README
45
37
  - lib/runt/pdate.rb
46
- - lib/runt/schedule.rb
38
+ - lib/runt/dprecision.rb
47
39
  - lib/runt/temporalexpression.rb
40
+ - lib/runt/daterange.rb
41
+ - lib/runt/schedule.rb
42
+ - lib/runt/sugar.rb
43
+ - lib/runt/expressionbuilder.rb
48
44
  - lib/runt.rb
49
- - test/baseexpressiontest.rb
50
- - test/collectiontest.rb
45
+ - test/reweektest.rb
46
+ - test/icalendartest.rb
47
+ - test/everytetest.rb
51
48
  - test/combinedexpressionstest.rb
49
+ - test/wimonthtest.rb
50
+ - test/reyeartest.rb
51
+ - test/runttest.rb
52
+ - test/uniontest.rb
53
+ - test/yeartetest.rb
52
54
  - test/daterangetest.rb
53
- - test/dayintervaltetest.rb
54
- - test/difftest.rb
55
- - test/dimonthtest.rb
56
- - test/diweektest.rb
55
+ - test/baseexpressiontest.rb
56
+ - test/spectest.rb
57
+ - test/collectiontest.rb
58
+ - test/scheduletest.rb
59
+ - test/pdatetest.rb
57
60
  - test/dprecisiontest.rb
58
- - test/everytetest.rb
59
- - test/icalendartest.rb
60
61
  - test/intersecttest.rb
61
- - test/pdatetest.rb
62
+ - test/dimonthtest.rb
63
+ - test/temporalexpressiontest.rb
62
64
  - test/redaytest.rb
65
+ - test/diweektest.rb
66
+ - test/difftest.rb
67
+ - test/dayintervaltetest.rb
63
68
  - test/remonthtest.rb
64
- - test/reweektest.rb
65
- - test/reyeartest.rb
66
69
  - test/rspectest.rb
67
- - test/runttest.rb
68
- - test/scheduletest.rb
69
- - test/spectest.rb
70
- - test/temporalexpressiontest.rb
71
- - test/uniontest.rb
72
- - test/wimonthtest.rb
73
- - test/yeartetest.rb
74
- - examples/reminder.rb
70
+ - test/aftertetest.rb
71
+ - test/sugartest.rb
72
+ - test/beforetetest.rb
73
+ - test/expressionbuildertest.rb
75
74
  - examples/schedule_tutorial.rb
76
75
  - examples/schedule_tutorialtest.rb
77
- - doc/tutorial_schedule.rdoc
76
+ - examples/reminder.rb
77
+ - examples/payment_report.rb
78
+ - examples/payment_reporttest.rb
78
79
  - doc/tutorial_te.rdoc
80
+ - doc/tutorial_schedule.rdoc
81
+ - doc/tutorial_sugar.rdoc
79
82
  - site/blue-robot3.css
80
- - site/dcl-small.gif
81
- - site/index.html
82
83
  - site/logohover.png
84
+ - site/index.html
83
85
  - site/runt-logo.gif
84
86
  - site/runt-logo.psd
87
+ - site/dcl-small.gif
88
+ has_rdoc: true
89
+ homepage: http://runt.rubyforge.org
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --main
93
+ - README
94
+ - --title
95
+ - Runt
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: "0"
109
+ version:
110
+ requirements:
111
+ - none
112
+ rubyforge_project: runt
113
+ rubygems_version: 1.2.0
114
+ signing_key:
115
+ specification_version: 2
116
+ summary: Ruby Temporal Expressions.
85
117
  test_files:
86
- - examples/schedule_tutorialtest.rb
87
- - test/baseexpressiontest.rb
88
- - test/collectiontest.rb
118
+ - test/reweektest.rb
119
+ - test/icalendartest.rb
120
+ - test/everytetest.rb
89
121
  - test/combinedexpressionstest.rb
122
+ - test/wimonthtest.rb
123
+ - test/reyeartest.rb
124
+ - test/runttest.rb
125
+ - test/uniontest.rb
126
+ - test/yeartetest.rb
90
127
  - test/daterangetest.rb
91
- - test/dayintervaltetest.rb
92
- - test/difftest.rb
93
- - test/dimonthtest.rb
94
- - test/diweektest.rb
128
+ - test/baseexpressiontest.rb
129
+ - test/spectest.rb
130
+ - test/collectiontest.rb
131
+ - test/scheduletest.rb
132
+ - test/pdatetest.rb
95
133
  - test/dprecisiontest.rb
96
- - test/everytetest.rb
97
- - test/icalendartest.rb
98
134
  - test/intersecttest.rb
99
- - test/pdatetest.rb
135
+ - test/dimonthtest.rb
136
+ - test/temporalexpressiontest.rb
100
137
  - test/redaytest.rb
138
+ - test/diweektest.rb
139
+ - test/difftest.rb
140
+ - test/dayintervaltetest.rb
101
141
  - test/remonthtest.rb
102
- - test/reweektest.rb
103
- - test/reyeartest.rb
104
142
  - test/rspectest.rb
105
- - test/runttest.rb
106
- - test/scheduletest.rb
107
- - test/spectest.rb
108
- - test/temporalexpressiontest.rb
109
- - test/uniontest.rb
110
- - test/wimonthtest.rb
111
- - test/yeartetest.rb
112
- rdoc_options:
113
- - --main
114
- - README
115
- - --title
116
- - Runt
117
- extra_rdoc_files:
118
- - README
119
- - CHANGES
120
- - TODO
121
- - LICENSE.txt
122
- - doc/tutorial_schedule.rdoc
123
- - doc/tutorial_te.rdoc
124
- executables: []
125
-
126
- extensions: []
127
-
128
- requirements:
129
- - none
130
- dependencies: []
131
-
143
+ - test/aftertetest.rb
144
+ - test/sugartest.rb
145
+ - test/beforetetest.rb
146
+ - test/expressionbuildertest.rb
147
+ - examples/schedule_tutorialtest.rb
148
+ - examples/payment_reporttest.rb