runt 0.7.0 → 0.9.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.
Files changed (49) hide show
  1. data/.gitignore +19 -0
  2. data/.travis.yml +5 -0
  3. data/{CHANGES → CHANGES.txt} +24 -8
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -44
  6. data/README.md +79 -0
  7. data/Rakefile +6 -119
  8. data/doc/tutorial_schedule.md +365 -0
  9. data/doc/tutorial_sugar.md +170 -0
  10. data/doc/tutorial_te.md +155 -0
  11. data/lib/runt.rb +36 -21
  12. data/lib/runt/dprecision.rb +4 -2
  13. data/lib/runt/pdate.rb +101 -95
  14. data/lib/runt/schedule.rb +18 -0
  15. data/lib/runt/sugar.rb +41 -9
  16. data/lib/runt/temporalexpression.rb +246 -30
  17. data/lib/runt/version.rb +3 -0
  18. data/runt.gemspec +24 -0
  19. data/site/.cvsignore +1 -0
  20. data/site/dcl-small.gif +0 -0
  21. data/site/index-rubforge-www.html +72 -0
  22. data/site/index.html +75 -60
  23. data/site/runt-logo.gif +0 -0
  24. data/site/runt-logo.psd +0 -0
  25. data/test/baseexpressiontest.rb +10 -8
  26. data/test/combinedexpressionstest.rb +166 -158
  27. data/test/daterangetest.rb +4 -6
  28. data/test/diweektest.rb +32 -32
  29. data/test/dprecisiontest.rb +2 -4
  30. data/test/everytetest.rb +6 -0
  31. data/test/expressionbuildertest.rb +2 -3
  32. data/test/icalendartest.rb +3 -6
  33. data/test/minitest_helper.rb +7 -0
  34. data/test/pdatetest.rb +21 -6
  35. data/test/redaytest.rb +3 -0
  36. data/test/reyeartest.rb +1 -1
  37. data/test/runttest.rb +5 -8
  38. data/test/scheduletest.rb +13 -14
  39. data/test/sugartest.rb +28 -6
  40. data/test/{spectest.rb → temporaldatetest.rb} +14 -4
  41. data/test/{rspectest.rb → temporalrangetest.rb} +4 -4
  42. data/test/test_runt.rb +11 -0
  43. data/test/weekintervaltest.rb +106 -0
  44. metadata +161 -116
  45. data/README +0 -106
  46. data/doc/tutorial_schedule.rdoc +0 -393
  47. data/doc/tutorial_sugar.rdoc +0 -143
  48. data/doc/tutorial_te.rdoc +0 -190
  49. data/setup.rb +0 -1331
@@ -1,19 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
3
+ require 'minitest_helper'
6
4
 
7
5
  # Unit tests for DateRange class
8
6
  #
9
7
  # Author:: Matthew Lipper
10
- class DateRangeTest < Test::Unit::TestCase
8
+ class DateRangeTest < MiniTest::Unit::TestCase
11
9
 
12
10
  include Runt
13
11
 
14
12
  def test_sub_range
15
- r_start = PDate.sec(2004,2,29,16,24,12)
16
- r_end = PDate.sec(2004,3,2,4,22,58)
13
+ r_start = PDate.min(2004,2,29,16,24)
14
+ r_end = PDate.min(2004,3,2,4,22)
17
15
  range = DateRange.new(r_start,r_end)
18
16
  assert(range.min==r_start)
19
17
  assert(range.max==r_end)
@@ -1,32 +1,32 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'baseexpressiontest'
4
-
5
- # Unit tests for DIWeek class
6
- # Author:: Matthew Lipper
7
-
8
- class DIWeekTest < BaseExpressionTest
9
-
10
- def test_day_in_week_te
11
- expr = DIWeek.new(Friday)
12
- assert expr.include?(@date_20040109), "'Friday' should include #{@date_20040109} which is a Friday"
13
- assert expr.include?(@date_20040116), "'Friday' should include #{@date_20040116} which is a Friday"
14
- assert !expr.include?(@date_20040125), "'Friday' should not include #{@date_20040125} which is a Sunday"
15
- end
16
-
17
- def test_day_in_week_te_to_s
18
- assert_equal 'Friday', DIWeek.new(Friday).to_s
19
- end
20
-
21
- def test_day_in_week_dates
22
- expr = DIWeek.new(Sunday)
23
- dates = expr.dates(@date_20050101..@date_20050131)
24
- assert dates.size == 5, "There are five Sundays in January, 2005: found #{dates.size}"
25
- assert dates.include?(@date_20050102), "Should include #{@date_20050102}"
26
- assert dates.include?(@date_20050109), "Should include #{@date_20050109}"
27
- assert dates.include?(@date_20050116), "Should include #{@date_20050116}"
28
- assert dates.include?(@date_20050123), "Should include #{@date_20050123}"
29
- assert dates.include?(@date_20050130), "Should include #{@date_20050130}"
30
- end
31
-
32
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'baseexpressiontest'
4
+
5
+ # Unit tests for DIWeek class
6
+ # Author:: Matthew Lipper
7
+
8
+ class DIWeekTest < BaseExpressionTest
9
+
10
+ def test_day_in_week_te
11
+ expr = DIWeek.new(Friday)
12
+ assert expr.include?(@date_20040109), "'Friday' should include #{@date_20040109} which is a Friday"
13
+ assert expr.include?(@date_20040116), "'Friday' should include #{@date_20040116} which is a Friday"
14
+ assert !expr.include?(@date_20040125), "'Friday' should not include #{@date_20040125} which is a Sunday"
15
+ end
16
+
17
+ def test_day_in_week_te_to_s
18
+ assert_equal 'Friday', DIWeek.new(Friday).to_s
19
+ end
20
+
21
+ def test_day_in_week_dates
22
+ expr = DIWeek.new(Sunday)
23
+ dates = expr.dates(@date_20050101..@date_20050131)
24
+ assert dates.size == 5, "There are five Sundays in January, 2005: found #{dates.size}"
25
+ assert dates.include?(@date_20050102), "Should include #{@date_20050102}"
26
+ assert dates.include?(@date_20050109), "Should include #{@date_20050109}"
27
+ assert dates.include?(@date_20050116), "Should include #{@date_20050116}"
28
+ assert dates.include?(@date_20050123), "Should include #{@date_20050123}"
29
+ assert dates.include?(@date_20050130), "Should include #{@date_20050130}"
30
+ end
31
+
32
+ end
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
3
+ require 'minitest_helper'
6
4
 
7
5
  # Unit tests for DPrecision class
8
6
  #
9
7
  # Author:: Matthew Lipper
10
8
 
11
- class DPrecisionTest < Test::Unit::TestCase
9
+ class DPrecisionTest < MiniTest::Unit::TestCase
12
10
 
13
11
  include Runt
14
12
 
@@ -7,6 +7,12 @@ require 'baseexpressiontest'
7
7
 
8
8
  class EveryTETest < BaseExpressionTest
9
9
 
10
+ def test_every_other_week
11
+ date = @pdate_20081112
12
+ expr = EveryTE.new(date, 14, DPrecision::DAY)
13
+ assert !expr.include?(date + 7)
14
+ assert expr.include?(date + 14)
15
+ end
10
16
 
11
17
  def test_every_2_minutes
12
18
  date = @pdate_200401282100
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'runt'
3
+ require 'minitest_helper'
5
4
 
6
- class ExpressionBuilderTest < Test::Unit::TestCase
5
+ class ExpressionBuilderTest < MiniTest::Unit::TestCase
7
6
 
8
7
  def setup
9
8
  @builder = ExpressionBuilder.new
@@ -1,15 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'date'
5
- require 'runt'
6
- require 'set'
3
+ require 'minitest_helper'
7
4
 
8
- include Runt
9
5
 
10
6
  # RFC 2445 is the iCalendar specification. It includes dozens of
11
7
  # specific examples that make great tests for Runt temporal expressions.
12
- class ICalendarTest < Test::Unit::TestCase
8
+ class ICalendarTest < MiniTest::Unit::TestCase
9
+ include Runt
13
10
 
14
11
  # "Daily for 10 occurences"
15
12
  def test_example_1
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'runt'
4
+ require 'date'
5
+ require 'time'
6
+ require 'rubygems' # Needed for minitest on 1.8.7
7
+ require 'minitest/autorun'
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'date'
5
- require 'runt'
3
+ require 'minitest_helper'
6
4
 
7
5
  # Unit tests for PDate class
8
6
  # Author:: Matthew Lipper
9
- class PDateTest < Test::Unit::TestCase
7
+ class PDateTest < MiniTest::Unit::TestCase
10
8
 
11
9
  include Runt
12
10
 
@@ -25,13 +23,24 @@ class PDateTest < Test::Unit::TestCase
25
23
  @second_prec = PDate.sec(2004,3,1,0,0,10)
26
24
  end
27
25
 
26
+ def test_pdate_with_native_range
27
+ start_dt = PDate.min(2013,04,22,8,0)
28
+ middle_dt = PDate.min(2013,04,22,8,2)
29
+ end_dt = PDate.min(2013,04,22,8,04)
30
+ range = start_dt..end_dt
31
+ assert(range.include?(middle_dt))
32
+ end
33
+
28
34
  def test_marshal
29
35
  # Thanks to Jodi Showers for finding/fixing this bug
30
36
  pdate=PDate.new(2004,2,29,22,13,2)
31
- assert_not_nil pdate.date_precision
37
+ refute_nil pdate.date_precision
32
38
  data=Marshal.dump pdate
33
39
  obj=Marshal.load data
34
- assert_not_nil obj.date_precision
40
+ refute_nil obj.date_precision
41
+ #FIXME: marshall broken in 1.9
42
+ #assert(obj.eql?(pdate))
43
+ #assert(pdate.eql?(obj))
35
44
  end
36
45
 
37
46
  def test_include
@@ -144,4 +153,10 @@ class PDateTest < Test::Unit::TestCase
144
153
  end
145
154
  end
146
155
 
156
+ def test_parse_with_precision
157
+ month_parsed = PDate.parse('April 2004', :precision => PDate::MONTH)
158
+ assert_equal month_parsed, PDate.month(2004,04)
159
+ refute_equal month_parsed, PDate.year(2004,04)
160
+ end
161
+
147
162
  end
@@ -35,6 +35,9 @@ class REDayTest < BaseExpressionTest
35
35
  expr = REDay.new(8,00,10,00, false)
36
36
  assert !expr.include?(@pdate_20040531), \
37
37
  "Expression #{expr.to_s} created with less_precise_match=false should not include any lower precision argument automatically"
38
+ ## Date class which has no public hour or min methods should not cause an exception
39
+ assert !expr.include?(@date_19611101), \
40
+ "Expression #{expr.to_s} created with less_precise_match=false should not hurl when given a Date instance"
38
41
  end
39
42
 
40
43
  end
@@ -31,7 +31,7 @@ class REYearTest < BaseExpressionTest
31
31
  assert expr.end_day == REYear::NO_DAY, "End day should equal constant NO_DAY"
32
32
  end
33
33
 
34
- def test_ctor_three_args
34
+ def test_ctor_four_args
35
35
  expr = REYear.new(10,21,12,3)
36
36
  assert expr.start_month == 10, "Start month should equal 10"
37
37
  assert expr.end_month == 12, "End month should equal 12"
@@ -1,11 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
6
- require 'pp'
3
+ require 'minitest_helper'
7
4
 
8
- class RuntModuleTest < Test::Unit::TestCase
5
+ class RuntModuleTest < MiniTest::Unit::TestCase
9
6
 
10
7
  def test_last
11
8
  assert Runt::Last == -1
@@ -80,19 +77,19 @@ class RuntModuleTest < Test::Unit::TestCase
80
77
 
81
78
  def test_date_class_dprecision
82
79
  date=Date.today
83
- assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
80
+ assert_equal(Runt::DPrecision::DAY,date.date_precision)
84
81
  end
85
82
 
86
83
  def test_datetime_class_dprecision
87
84
  date=DateTime.civil
88
- assert_equal(Runt::DPrecision::DEFAULT,date.date_precision)
85
+ assert_equal(Runt::DPrecision::SEC,date.date_precision)
89
86
  end
90
87
 
91
88
  def test_time_plus
92
89
  time=Time.local(2006, 12, 9, 5, 56, 12)
93
90
  # Default precision is minute
94
91
  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)
92
+ refute_equal(Time.parse("Sat Dec 09 05:56:00 -0500 2006"),time)
96
93
  end
97
94
 
98
95
  end
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'runt'
5
- require 'date'
3
+ require 'minitest_helper'
6
4
 
7
5
  # Unit tests for Schedule classes
8
6
  # Author:: Matthew Lipper
9
- class ScheduleTest < Test::Unit::TestCase
7
+ class ScheduleTest < MiniTest::Unit::TestCase
10
8
 
11
9
  include Runt
12
10
 
@@ -87,14 +85,15 @@ class ScheduleTest < Test::Unit::TestCase
87
85
  @sched=Schedule.new
88
86
  e1=Event.new("e1")
89
87
  assert(!@sched.include?(e1,nil))
90
- range=RSpec.new(DateRange.new(PDate.new(2006,12,3),PDate.new(2007,1,24)))
91
- in_range=PDate.new(2007,1,4)
92
- assert(range.include?(in_range))
93
- out_of_range=PDate.new(2006,1,4)
94
- assert(!range.include?(out_of_range))
95
- @sched.add(e1,range)
96
- assert(@sched.include?(e1,in_range))
97
- assert(!@sched.include?(e1,out_of_range))
88
+ #FIXME: Temporarily comment this out since it hangs JRuby 1.9
89
+ #range=TemporalRange.new(DateRange.new(PDate.new(2006,12,3),PDate.new(2007,1,24)))
90
+ #in_range=PDate.new(2007,1,4)
91
+ #assert(range.include?(in_range))
92
+ #out_of_range=PDate.new(2006,1,4)
93
+ #assert(!range.include?(out_of_range))
94
+ #@sched.add(e1,range)
95
+ #assert(@sched.include?(e1,in_range))
96
+ #assert(!@sched.include?(e1,out_of_range))
98
97
  end
99
98
 
100
99
  def test_dates
@@ -113,10 +112,10 @@ class ScheduleTest < Test::Unit::TestCase
113
112
  def test_using_a_schedule
114
113
 
115
114
  # September 18th - 19th, 2005, 8am - 10am
116
- expr1=RSpec.new(DateRange.new(PDate.day(2005,9,18),PDate.day(2005,9,19))) & REDay.new(8,0,10,0)
115
+ expr1=TemporalRange.new(DateRange.new(PDate.day(2005,9,18),PDate.day(2005,9,19))) & REDay.new(8,0,10,0)
117
116
  assert(expr1.include?(PDate.min(2005,9,18,8,15)))
118
117
  # September 19th - 20th, 2005, 9am - 11am
119
- expr2=RSpec.new(DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))) & REDay.new(9,0,11,0)
118
+ expr2=TemporalRange.new(DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))) & REDay.new(9,0,11,0)
120
119
  # Quick sanuty check
121
120
  assert(expr1.overlap?(expr2))
122
121
  # Setup a @schedule w/first expression
@@ -1,14 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'test/unit'
4
- require 'runt'
5
- require 'runt/sugar'
3
+ require 'minitest_helper'
6
4
 
7
- class SugarTest < Test::Unit::TestCase
5
+ class SugarTest < MiniTest::Unit::TestCase
8
6
  include Runt
9
7
 
10
- def test_build__should_return_nil_when_an_unknown_name_is_given
11
- assert self.build('duh').nil?
8
+ def setup
9
+ @date = PDate.day(2008,7,1)
12
10
  end
13
11
 
14
12
  def test_method_missing_should_be_called_for_invalid_name
@@ -87,6 +85,30 @@ class SugarTest < Test::Unit::TestCase
87
85
  end
88
86
  end
89
87
 
88
+ def test_after_should_define_after_te_with_inclusive_parameter
89
+ result = self.after(@date, true)
90
+ assert_expression AfterTE.new(@date, true), result
91
+ assert result.instance_variable_get("@inclusive")
92
+ end
93
+
94
+ def test_after_should_define_after_te_without_inclusive_parameter
95
+ result = self.after(@date)
96
+ assert_expression AfterTE.new(@date), result
97
+ assert !result.instance_variable_get("@inclusive")
98
+ end
99
+
100
+ def test_before_should_define_before_te_with_inclusive_parameter
101
+ result = self.before(@date, true)
102
+ assert_expression BeforeTE.new(@date, true), result
103
+ assert result.instance_variable_get("@inclusive")
104
+ end
105
+
106
+ def test_before_should_define_before_te_without_inclusive_parameter
107
+ result = self.before(@date)
108
+ assert_expression BeforeTE.new(@date), result
109
+ assert !result.instance_variable_get("@inclusive")
110
+ end
111
+
90
112
  private
91
113
  def assert_expression(expected, actual)
92
114
  assert_equal expected.to_s, actual.to_s, \
@@ -3,19 +3,29 @@
3
3
 
4
4
  require 'baseexpressiontest'
5
5
 
6
- # Unit tests for Spec class
6
+ # Unit tests for TemporalDate class
7
7
  # Author:: Matthew Lipper
8
8
 
9
- class SpecTest < BaseExpressionTest
9
+ class TemporalDateTest < BaseExpressionTest
10
10
 
11
11
  def setup
12
12
  super
13
- @spec = Spec.new(@stub1)
13
+ @spec = TemporalDate.new(@stub1)
14
14
  end
15
15
 
16
16
  def test_initialize
17
17
  assert_same @stub1, @spec.date_expr, "Expected #{@stub1}, instead got #{@spec.date_expr}"
18
18
  end
19
+
20
+ def test_specific_date
21
+ date_spec = TemporalDate.new(Date.new(2006,06,27))
22
+
23
+ assert !date_spec.include?(Date.new(2005,06,27))
24
+ assert !date_spec.include?(Date.new(2006,06,26))
25
+ assert date_spec.include?(Date.new(2006,06,27))
26
+ assert !date_spec.include?(Date.new(2006,06,28))
27
+ assert !date_spec.include?(Date.new(2007,06,27))
28
+ end
19
29
 
20
30
  def test_include_arg_has_include_method
21
31
  assert !@spec.include?(@stub2), "Expression should not include configured stub"
@@ -24,7 +34,7 @@ class SpecTest < BaseExpressionTest
24
34
  end
25
35
 
26
36
  def test_include_arg_without_include_method
27
- @spec = Spec.new(4)
37
+ @spec = TemporalDate.new(4)
28
38
  assert !@spec.include?(3), "Expression #{@spec.to_s} should not include 3"
29
39
  assert @spec.include?(4), "Expression #{@spec.to_s} should include 4"
30
40
  end
@@ -3,13 +3,13 @@
3
3
 
4
4
  require 'baseexpressiontest'
5
5
 
6
- # Unit tests for RSpec class
6
+ # Unit tests for TemporalRange class
7
7
  # Author:: Matthew Lipper
8
8
 
9
- class RSpecTest < BaseExpressionTest
9
+ class TemporalRangeTest < BaseExpressionTest
10
10
 
11
11
  def test_include
12
- rspec = RSpec.new(@stub1)
12
+ rspec = TemporalRange.new(@stub1)
13
13
  assert !rspec.include?("Any Object"), "Expression should not include any given argument"
14
14
  @stub1.match = true
15
15
  assert rspec.include?("Any Object"), "Expression should include any given argument"
@@ -17,7 +17,7 @@ class RSpecTest < BaseExpressionTest
17
17
 
18
18
  def test_overlap
19
19
  range = DateRange.new(@date_20050101, @date_20050109)
20
- rspec = RSpec.new(range)
20
+ rspec = TemporalRange.new(range)
21
21
  assert !rspec.include?(@date_20050116), "Expression #{rspec.to_s} should not include #{@date_20050116.to_s}"
22
22
  assert rspec.include?(@date_20050102), "Expression #{rspec.to_s} should include #{@date_20050102.to_s}"
23
23
  end
@@ -0,0 +1,11 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestRunt < MiniTest::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Runt::VERSION
6
+ end
7
+
8
+ def test_it_does_something_useful
9
+ #assert false
10
+ end
11
+ end