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.
- data/ChangeLog +36 -2
- data/README +92 -0
- data/Rakefile +26 -1
- data/TAGS +369 -0
- data/lib/texp.rb +6 -1
- data/lib/texp/base.rb +139 -10
- data/lib/texp/builder.rb +254 -0
- data/lib/texp/day_interval.rb +19 -15
- data/lib/texp/day_of_month.rb +1 -7
- data/lib/texp/day_of_week.rb +1 -7
- data/lib/texp/dsl.rb +338 -0
- data/lib/texp/errors.rb +18 -0
- data/lib/texp/every_day.rb +1 -5
- data/lib/texp/logic.rb +16 -40
- data/lib/texp/month.rb +1 -6
- data/lib/texp/operators.rb +53 -0
- data/lib/texp/parse.rb +9 -27
- data/lib/texp/time_ext.rb +7 -0
- data/lib/texp/version.rb +3 -0
- data/lib/texp/week.rb +1 -7
- data/lib/texp/window.rb +30 -12
- data/lib/texp/year.rb +1 -6
- data/test/texp/base_test.rb +82 -0
- data/test/texp/day_interval_test.rb +24 -12
- data/test/texp/day_of_month_test.rb +10 -10
- data/test/texp/day_of_week_test.rb +14 -14
- data/test/texp/dsl_test.rb +288 -0
- data/test/texp/every_day_test.rb +1 -1
- data/test/texp/ext_test.rb +3 -3
- data/test/texp/logic_test.rb +18 -18
- data/test/texp/month_test.rb +3 -3
- data/test/texp/operators_test.rb +52 -0
- data/test/texp/parse_test.rb +39 -39
- data/test/texp/time_ext_test.rb +8 -0
- data/test/texp/week_test.rb +19 -19
- data/test/texp/window_test.rb +41 -12
- data/test/texp/year_test.rb +7 -7
- data/test/texp_tests.rb +27 -0
- metadata +14 -6
- data/lib/texp/core.rb +0 -41
- data/lib/texp/hash_builder.rb +0 -44
- data/test/texp/hash_test.rb +0 -26
- data/test/texp/logic_text_test.rb +0 -0
data/test/texp/month_test.rb
CHANGED
@@ -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.
|
16
|
-
assert te.
|
17
|
-
assert ! te.
|
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
|
data/test/texp/parse_test.rb
CHANGED
@@ -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.
|
101
|
-
assert ! te.
|
102
|
-
assert te.
|
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.
|
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.
|
118
|
-
assert te.
|
119
|
-
assert ! te.
|
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.
|
125
|
-
assert ! te.
|
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.
|
131
|
-
assert te.
|
132
|
-
assert ! te.
|
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.
|
138
|
-
assert ! te.
|
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.
|
144
|
-
assert te.
|
145
|
-
assert ! te.
|
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.
|
151
|
-
assert ! te.
|
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.
|
157
|
-
assert te.
|
158
|
-
assert ! te.
|
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.
|
164
|
-
assert te.
|
165
|
-
assert te.
|
166
|
-
assert te.
|
167
|
-
assert te.
|
168
|
-
assert ! te.
|
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.
|
174
|
-
assert te.
|
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").
|
179
|
-
TExp.parse("2m").
|
178
|
+
TExp.parse("14d").includes?(@date)
|
179
|
+
TExp.parse("2m").includes?(@date)
|
180
180
|
te = TExp.parse("[14d 2m] a")
|
181
|
-
assert te.
|
182
|
-
assert ! te.
|
183
|
-
assert ! te.
|
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.
|
189
|
-
assert te.
|
190
|
-
assert ! te.
|
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.
|
195
|
+
assert te.includes?(Date.today)
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
data/test/texp/week_test.rb
CHANGED
@@ -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.
|
12
|
-
assert te.
|
13
|
-
assert te.
|
14
|
-
assert te.
|
15
|
-
assert te.
|
16
|
-
assert te.
|
17
|
-
assert ! te.
|
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.
|
23
|
-
assert ! te.
|
24
|
-
assert te.
|
25
|
-
assert te.
|
26
|
-
assert ! te.
|
27
|
-
assert ! te.
|
28
|
-
assert te.
|
29
|
-
assert te.
|
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.
|
35
|
-
assert ! te.
|
36
|
-
assert te.
|
37
|
-
assert te.
|
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
|
data/test/texp/window_test.rb
CHANGED
@@ -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.
|
13
|
-
assert te.
|
14
|
-
assert te.
|
15
|
-
assert te.
|
16
|
-
assert te.
|
17
|
-
assert ! te.
|
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.
|
24
|
-
assert ! te.
|
25
|
-
assert ! te.
|
26
|
-
assert te.
|
27
|
-
assert ! te.
|
28
|
-
assert ! te.
|
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
|
data/test/texp/year_test.rb
CHANGED
@@ -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.
|
16
|
-
assert te.
|
17
|
-
assert ! te.
|
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.
|
23
|
-
assert te.
|
24
|
-
assert te.
|
25
|
-
assert ! te.
|
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
|
|
data/test/texp_tests.rb
ADDED
@@ -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.
|
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-
|
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/
|
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
|