texp 0.0.3 → 0.0.7

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.
@@ -12,9 +12,9 @@ class MonthTest < Test::Unit::TestCase
12
12
 
13
13
  def test_initial_conditions
14
14
  te = TExp::Month.new(2)
15
- assert te.include?(@date)
16
- assert te.include?(@date + 1)
17
- assert ! te.include?(@date + 30)
15
+ assert te.includes?(@date)
16
+ assert te.includes?(@date + 1)
17
+ assert ! te.includes?(@date + 30)
18
18
  end
19
19
  end
20
20
 
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'texp'
5
+
6
+ class OperatorsTest < Test::Unit::TestCase
7
+ def setup
8
+ @monday = Date.parse("Mar 3, 2008")
9
+ @tuesday = Date.parse("Mar 4, 2008")
10
+ @wednesday = Date.parse("Mar 5, 2008")
11
+ @thursday = Date.parse("Mar 6, 2008")
12
+ @friday = Date.parse("Mar 7, 2008")
13
+ end
14
+
15
+ def test_union
16
+ te = TExp.parse("2w") + TExp.parse("3w")
17
+
18
+ assert ! te.includes?(@monday)
19
+ assert te.includes?(@tuesday)
20
+ assert te.includes?(@wednesday)
21
+ assert ! te.includes?(@thursday)
22
+ assert ! te.includes?(@friday)
23
+ end
24
+
25
+ def test_intersection
26
+ te = TExp.parse("2w") * TExp.parse("1k")
27
+
28
+ assert te.includes?(@tuesday)
29
+ assert ! te.includes?(@wednesday)
30
+ assert ! te.includes?(@tuesday+7)
31
+ end
32
+
33
+ def test_difference
34
+ te = TExp.parse("3w1,1s") - TExp.parse("3w")
35
+
36
+ assert ! te.includes?(@monday)
37
+ assert te.includes?(@tuesday)
38
+ assert ! te.includes?(@wednesday)
39
+ assert te.includes?(@thursday)
40
+ assert ! te.includes?(@friday)
41
+ end
42
+
43
+ def test_negate
44
+ te = -TExp.parse("3w")
45
+
46
+ assert te.includes?(@monday)
47
+ assert te.includes?(@tuesday)
48
+ assert ! te.includes?(@wednesday)
49
+ assert te.includes?(@thursday)
50
+ assert te.includes?(@friday)
51
+ end
52
+ end
@@ -97,14 +97,14 @@ class ParseTest < Test::Unit::TestCase
97
97
 
98
98
  def test_parse_interval
99
99
  te = TExp.parse("2008-02-14,2i")
100
- assert te.include?(@date)
101
- assert ! te.include?(@date+1)
102
- assert te.include?(@date+2)
100
+ assert te.includes?(@date)
101
+ assert ! te.includes?(@date+1)
102
+ assert te.includes?(@date+2)
103
103
  end
104
104
 
105
105
  def test_parse_day_of_month
106
106
  te = TExp.parse("14d")
107
- te.include?(@date)
107
+ te.includes?(@date)
108
108
  end
109
109
 
110
110
  def test_parse_list
@@ -114,85 +114,85 @@ class ParseTest < Test::Unit::TestCase
114
114
 
115
115
  def test_parse_day_of_month_with_multiple_args
116
116
  te = TExp.parse("[13,14]d")
117
- assert te.include?(@date)
118
- assert te.include?(@date-1)
119
- assert ! te.include?(@date+2)
117
+ assert te.includes?(@date)
118
+ assert te.includes?(@date-1)
119
+ assert ! te.includes?(@date+2)
120
120
  end
121
121
 
122
122
  def test_parse_day_of_week_with_single_arg
123
123
  te = TExp.parse("4w")
124
- assert te.include?(@date)
125
- assert ! te.include?(@date+2)
124
+ assert te.includes?(@date)
125
+ assert ! te.includes?(@date+2)
126
126
  end
127
127
 
128
128
  def test_parse_day_of_week_with_multiple_args
129
129
  te = TExp.parse("[3,4]w")
130
- assert te.include?(@date)
131
- assert te.include?(@date-1)
132
- assert ! te.include?(@date+2)
130
+ assert te.includes?(@date)
131
+ assert te.includes?(@date-1)
132
+ assert ! te.includes?(@date+2)
133
133
  end
134
134
 
135
135
  def test_parse_month_with_single_arg
136
136
  te = TExp.parse("2m")
137
- assert te.include?(@date)
138
- assert ! te.include?(@date + 30)
137
+ assert te.includes?(@date)
138
+ assert ! te.includes?(@date + 30)
139
139
  end
140
140
 
141
141
  def test_parse_month_with_multiple_args
142
142
  te = TExp.parse("[2,3]m")
143
- assert te.include?(@date)
144
- assert te.include?(@date + 30)
145
- assert ! te.include?(@date + 60)
143
+ assert te.includes?(@date)
144
+ assert te.includes?(@date + 30)
145
+ assert ! te.includes?(@date + 60)
146
146
  end
147
147
 
148
148
  def test_parse_year_with_single_arg
149
149
  te = TExp.parse("2008y")
150
- assert te.include?(@date)
151
- assert ! te.include?(@date + 365)
150
+ assert te.includes?(@date)
151
+ assert ! te.includes?(@date + 365)
152
152
  end
153
153
 
154
154
  def test_parse_year_with_multiple_args
155
155
  te = TExp.parse("[2007,2008]y")
156
- assert te.include?(@date)
157
- assert te.include?(@date - 365)
158
- assert ! te.include?(@date + 365)
156
+ assert te.includes?(@date)
157
+ assert te.includes?(@date - 365)
158
+ assert ! te.includes?(@date + 365)
159
159
  end
160
160
 
161
161
  def test_parse_window
162
162
  te = TExp.parse("3w2,1s")
163
- assert ! te.include?(Date.parse("Mar 2, 2008"))
164
- assert te.include?(Date.parse("Mar 3, 2008"))
165
- assert te.include?(Date.parse("Mar 4, 2008"))
166
- assert te.include?(Date.parse("Mar 5, 2008"))
167
- assert te.include?(Date.parse("Mar 6, 2008"))
168
- assert ! te.include?(Date.parse("Mar 7, 2008"))
163
+ assert ! te.includes?(Date.parse("Mar 2, 2008"))
164
+ assert te.includes?(Date.parse("Mar 3, 2008"))
165
+ assert te.includes?(Date.parse("Mar 4, 2008"))
166
+ assert te.includes?(Date.parse("Mar 5, 2008"))
167
+ assert te.includes?(Date.parse("Mar 6, 2008"))
168
+ assert ! te.includes?(Date.parse("Mar 7, 2008"))
169
169
  end
170
170
 
171
171
  def test_parse_not
172
172
  te = TExp.parse("14dn")
173
- assert ! te.include?(@date)
174
- assert te.include?(@date + 1)
173
+ assert ! te.includes?(@date)
174
+ assert te.includes?(@date + 1)
175
175
  end
176
176
 
177
177
  def test_parse_and
178
- TExp.parse("14d").include?(@date)
179
- TExp.parse("2m").include?(@date)
178
+ TExp.parse("14d").includes?(@date)
179
+ TExp.parse("2m").includes?(@date)
180
180
  te = TExp.parse("[14d 2m] a")
181
- assert te.include?(@date)
182
- assert ! te.include?(@date + 1)
183
- assert ! te.include?(@date + 365)
181
+ assert te.includes?(@date)
182
+ assert ! te.includes?(@date + 1)
183
+ assert ! te.includes?(@date + 365)
184
184
  end
185
185
 
186
186
  def test_parse_or
187
187
  te = TExp.parse("[14d 15d] o")
188
- assert te.include?(@date)
189
- assert te.include?(@date + 1)
190
- assert ! te.include?(@date + 2)
188
+ assert te.includes?(@date)
189
+ assert te.includes?(@date + 1)
190
+ assert ! te.includes?(@date + 2)
191
191
  end
192
192
 
193
193
  def test_parse_every_day
194
194
  te = TExp.parse('e')
195
- assert te.include?(Date.today)
195
+ assert te.includes?(Date.today)
196
196
  end
197
197
  end
198
198
 
@@ -0,0 +1,8 @@
1
+ require 'test/texp_tests'
2
+ require 'texp'
3
+
4
+ class TimeExtTest < Test::Unit::TestCase
5
+ def test_time_to_date
6
+ assert_equal Date.today, Time.now.to_date
7
+ end
8
+ end
@@ -8,33 +8,33 @@ class WeekTest < Test::Unit::TestCase
8
8
 
9
9
  def test_week_include_with_one_week
10
10
  te = TExp::Week.new([1])
11
- assert te.include?(Date.parse("Feb 1, 2008"))
12
- assert te.include?(Date.parse("Feb 2, 2008"))
13
- assert te.include?(Date.parse("Feb 3, 2008"))
14
- assert te.include?(Date.parse("Feb 5, 2008"))
15
- assert te.include?(Date.parse("Feb 6, 2008"))
16
- assert te.include?(Date.parse("Feb 7, 2008"))
17
- assert ! te.include?(Date.parse("Feb 8, 2008"))
11
+ assert te.includes?(Date.parse("Feb 1, 2008"))
12
+ assert te.includes?(Date.parse("Feb 2, 2008"))
13
+ assert te.includes?(Date.parse("Feb 3, 2008"))
14
+ assert te.includes?(Date.parse("Feb 5, 2008"))
15
+ assert te.includes?(Date.parse("Feb 6, 2008"))
16
+ assert te.includes?(Date.parse("Feb 7, 2008"))
17
+ assert ! te.includes?(Date.parse("Feb 8, 2008"))
18
18
  end
19
19
 
20
20
  def test_week_include_with_several_weeks
21
21
  te = TExp::Week.new([2,4])
22
- assert ! te.include?(Date.parse("Feb 1, 2008"))
23
- assert ! te.include?(Date.parse("Feb 7, 2008"))
24
- assert te.include?(Date.parse("Feb 8, 2008"))
25
- assert te.include?(Date.parse("Feb 14, 2008"))
26
- assert ! te.include?(Date.parse("Feb 15, 2008"))
27
- assert ! te.include?(Date.parse("Feb 21, 2008"))
28
- assert te.include?(Date.parse("Feb 22, 2008"))
29
- assert te.include?(Date.parse("Feb 28, 2008"))
22
+ assert ! te.includes?(Date.parse("Feb 1, 2008"))
23
+ assert ! te.includes?(Date.parse("Feb 7, 2008"))
24
+ assert te.includes?(Date.parse("Feb 8, 2008"))
25
+ assert te.includes?(Date.parse("Feb 14, 2008"))
26
+ assert ! te.includes?(Date.parse("Feb 15, 2008"))
27
+ assert ! te.includes?(Date.parse("Feb 21, 2008"))
28
+ assert te.includes?(Date.parse("Feb 22, 2008"))
29
+ assert te.includes?(Date.parse("Feb 28, 2008"))
30
30
  end
31
31
 
32
32
  def test_week_with_last_week_of_month
33
33
  te = TExp::Week.new([-1])
34
- assert ! te.include?(Date.parse("Feb 1, 2008"))
35
- assert ! te.include?(Date.parse("Feb 22, 2008"))
36
- assert te.include?(Date.parse("Feb 23, 2008"))
37
- assert te.include?(Date.parse("Feb 29, 2008"))
34
+ assert ! te.includes?(Date.parse("Feb 1, 2008"))
35
+ assert ! te.includes?(Date.parse("Feb 22, 2008"))
36
+ assert te.includes?(Date.parse("Feb 23, 2008"))
37
+ assert te.includes?(Date.parse("Feb 29, 2008"))
38
38
  end
39
39
 
40
40
  # Test some private methods
@@ -9,23 +9,52 @@ class WindowTest < Test::Unit::TestCase
9
9
  def test_window
10
10
  wed = TExp.parse("3w")
11
11
  te = TExp::Window.new(wed, 2, 1)
12
- assert ! te.include?(Date.parse("Mar 2, 2008"))
13
- assert te.include?(Date.parse("Mar 3, 2008"))
14
- assert te.include?(Date.parse("Mar 4, 2008"))
15
- assert te.include?(Date.parse("Mar 5, 2008"))
16
- assert te.include?(Date.parse("Mar 6, 2008"))
17
- assert ! te.include?(Date.parse("Mar 7, 2008"))
12
+ assert ! te.includes?(Date.parse("Mar 2, 2008"))
13
+ assert te.includes?(Date.parse("Mar 3, 2008"))
14
+ assert te.includes?(Date.parse("Mar 4, 2008"))
15
+ assert te.includes?(Date.parse("Mar 5, 2008"))
16
+ assert te.includes?(Date.parse("Mar 6, 2008"))
17
+ assert ! te.includes?(Date.parse("Mar 7, 2008"))
18
18
  end
19
19
 
20
20
  def test_narrow_window
21
21
  wed = TExp.parse("3w")
22
22
  te = TExp::Window.new(wed, 0, 0)
23
- assert ! te.include?(Date.parse("Mar 2, 2008"))
24
- assert ! te.include?(Date.parse("Mar 3, 2008"))
25
- assert ! te.include?(Date.parse("Mar 4, 2008"))
26
- assert te.include?(Date.parse("Mar 5, 2008"))
27
- assert ! te.include?(Date.parse("Mar 6, 2008"))
28
- assert ! te.include?(Date.parse("Mar 7, 2008"))
23
+ assert ! te.includes?(Date.parse("Mar 2, 2008"))
24
+ assert ! te.includes?(Date.parse("Mar 3, 2008"))
25
+ assert ! te.includes?(Date.parse("Mar 4, 2008"))
26
+ assert te.includes?(Date.parse("Mar 5, 2008"))
27
+ assert ! te.includes?(Date.parse("Mar 6, 2008"))
28
+ assert ! te.includes?(Date.parse("Mar 7, 2008"))
29
+ end
30
+
31
+ def test_window_reporting
32
+ mar5 = Date.parse("Mar 5, 2008")
33
+ wed = TExp.parse("3w")
34
+ te = TExp::Window.new(wed, 2, 1)
35
+
36
+ assert_equal mar5-2, te.first_day_of_window(mar5)
37
+ assert_equal mar5+1, te.last_day_of_window(mar5)
38
+ end
39
+
40
+ def test_window_reporting_when_outside_window
41
+ mar5 = Date.parse("Mar 8, 2008")
42
+ wed = TExp.parse("3w")
43
+ te = TExp::Window.new(wed, 2, 1)
44
+
45
+ assert_nil te.first_day_of_window(mar5)
46
+ assert_nil te.last_day_of_window(mar5)
47
+ end
48
+
49
+ def test_windows_on_non_window_temporal_expressions
50
+ mar5 = Date.parse("Mar 5, 2008")
51
+ te = TExp.parse("3w")
52
+
53
+ assert_equal mar5, te.first_day_of_window(mar5)
54
+ assert_equal mar5, te.last_day_of_window(mar5)
55
+
56
+ assert_nil te.first_day_of_window(mar5+1)
57
+ assert_nil te.last_day_of_window(mar5+1)
29
58
  end
30
59
 
31
60
  end
@@ -12,17 +12,17 @@ class YearTest < Test::Unit::TestCase
12
12
 
13
13
  def test_single_arg
14
14
  te = TExp::Year.new(2008)
15
- assert te.include?(@date)
16
- assert te.include?(@date + 30)
17
- assert ! te.include?(@date + 365)
15
+ assert te.includes?(@date)
16
+ assert te.includes?(@date + 30)
17
+ assert ! te.includes?(@date + 365)
18
18
  end
19
19
 
20
20
  def test_single_arg
21
21
  te = TExp::Year.new([2007,2008])
22
- assert te.include?(@date - 365)
23
- assert te.include?(@date)
24
- assert te.include?(@date + 30)
25
- assert ! te.include?(@date + 365)
22
+ assert te.includes?(@date - 365)
23
+ assert te.includes?(@date)
24
+ assert te.includes?(@date + 30)
25
+ assert ! te.includes?(@date + 365)
26
26
  end
27
27
  end
28
28
 
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'texp'
3
+
4
+ # Convenience method for parsing dates.
5
+ def d(date_string)
6
+ Date.parse(date_string)
7
+ end
8
+
9
+ module TExpAssertions
10
+ def assert_includes(te, *dates)
11
+ dates.each do |date|
12
+ date = Date.parse(date) if date.kind_of?(String)
13
+ assert te.includes?(date), "#{te} should include #{date}"
14
+ end
15
+ end
16
+
17
+ def assert_not_includes(te, *dates)
18
+ dates.each do |date|
19
+ date = Date.parse(date) if date.kind_of?(String)
20
+ assert ! te.includes?(date), "#{te} should not include #{date}"
21
+ end
22
+ end
23
+ end
24
+
25
+ class Test::Unit::TestCase
26
+ include TExpAssertions
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-06 00:00:00 -05:00
12
+ date: 2008-03-10 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,32 +29,40 @@ files:
29
29
  - MIT-LICENSE
30
30
  - Rakefile
31
31
  - README
32
+ - TAGS
32
33
  - lib/texp.rb
33
34
  - lib/texp/base.rb
34
- - lib/texp/core.rb
35
+ - lib/texp/builder.rb
35
36
  - lib/texp/day_interval.rb
36
37
  - lib/texp/day_of_month.rb
37
38
  - lib/texp/day_of_week.rb
39
+ - lib/texp/dsl.rb
40
+ - lib/texp/errors.rb
38
41
  - lib/texp/every_day.rb
39
42
  - lib/texp/ext.rb
40
- - lib/texp/hash_builder.rb
41
43
  - lib/texp/logic.rb
42
44
  - lib/texp/month.rb
45
+ - lib/texp/operators.rb
43
46
  - lib/texp/parse.rb
47
+ - lib/texp/time_ext.rb
48
+ - lib/texp/version.rb
44
49
  - lib/texp/week.rb
45
50
  - lib/texp/window.rb
46
51
  - lib/texp/year.rb
52
+ - test/texp_tests.rb
53
+ - test/texp/base_test.rb
47
54
  - test/texp/day_interval_test.rb
48
55
  - test/texp/day_of_month_test.rb
49
56
  - test/texp/day_of_week_test.rb
57
+ - test/texp/dsl_test.rb
50
58
  - test/texp/every_day_test.rb
51
59
  - test/texp/ext_test.rb
52
- - test/texp/hash_test.rb
53
60
  - test/texp/inspect_test.rb
54
61
  - test/texp/logic_test.rb
55
- - test/texp/logic_text_test.rb
56
62
  - test/texp/month_test.rb
63
+ - test/texp/operators_test.rb
57
64
  - test/texp/parse_test.rb
65
+ - test/texp/time_ext_test.rb
58
66
  - test/texp/week_test.rb
59
67
  - test/texp/window_test.rb
60
68
  - test/texp/year_test.rb