test/test_RepeaterHour.rb in pangel-chronic-0.3.0.3 vs test/test_RepeaterHour.rb in pangel-chronic-0.3.10
- old
+ new
@@ -1,68 +1,65 @@
require 'chronic'
require 'test/unit'
class TestRepeaterHour < Test::Unit::TestCase
+
+ def setup
+ @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
+ end
- def setup
- @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
- end
-
- def test_next_future
- hours = Chronic::RepeaterHour.new(:hour)
- hours.start = @now
-
- next_hour = hours.next(:future)
- assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
- assert_equal Time.local(2006, 8, 16, 16), next_hour.end
-
- next_next_hour = hours.next(:future)
- assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
- assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
- end
-
- def test_next_past
- hours = Chronic::RepeaterHour.new(:hour)
- hours.start = @now
-
- past_hour = hours.next(:past)
- assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
- assert_equal Time.local(2006, 8, 16, 14), past_hour.end
-
- past_past_hour = hours.next(:past)
- assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
- assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
- end
-
- def test_this
- @now = Time.local(2006, 8, 16, 14, 30)
-
- hours = Chronic::RepeaterHour.new(:hour)
- hours.start = @now
-
- this_hour = hours.this(:future)
- assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
- assert_equal Time.local(2006, 8, 16, 15), this_hour.end
-
- this_hour = hours.this(:past)
- assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
- assert_equal Time.local(2006, 8, 16, 14, 30), this_hour.end
- end
-
- def test_offset
- span = Chronic::Span.new(@now, @now + 1)
-
- offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
-
- assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
- assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
-
- offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
-
- assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
- assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
- end
- def test_sanity
- assert_not_nil Chronic.parse '2 hours ago'
- # assert_not_nil Chronic.parse '2 hours' # FIXME: this fails
- end
-end
+ def test_next_future
+ hours = Chronic::RepeaterHour.new(:hour)
+ hours.start = @now
+
+ next_hour = hours.next(:future)
+ assert_equal Time.local(2006, 8, 16, 15), next_hour.begin
+ assert_equal Time.local(2006, 8, 16, 16), next_hour.end
+
+ next_next_hour = hours.next(:future)
+ assert_equal Time.local(2006, 8, 16, 16), next_next_hour.begin
+ assert_equal Time.local(2006, 8, 16, 17), next_next_hour.end
+ end
+
+ def test_next_past
+ hours = Chronic::RepeaterHour.new(:hour)
+ hours.start = @now
+
+ past_hour = hours.next(:past)
+ assert_equal Time.local(2006, 8, 16, 13), past_hour.begin
+ assert_equal Time.local(2006, 8, 16, 14), past_hour.end
+
+ past_past_hour = hours.next(:past)
+ assert_equal Time.local(2006, 8, 16, 12), past_past_hour.begin
+ assert_equal Time.local(2006, 8, 16, 13), past_past_hour.end
+ end
+
+ def test_this
+ @now = Time.local(2006, 8, 16, 14, 30)
+
+ hours = Chronic::RepeaterHour.new(:hour)
+ hours.start = @now
+
+ this_hour = hours.this(:future)
+ assert_equal Time.local(2006, 8, 16, 14, 31), this_hour.begin
+ assert_equal Time.local(2006, 8, 16, 15), this_hour.end
+
+ this_hour = hours.this(:past)
+ assert_equal Time.local(2006, 8, 16, 14), this_hour.begin
+ assert_equal Time.local(2006, 8, 16, 14, 30), this_hour.end
+ end
+
+ def test_offset
+ span = Chronic::Span.new(@now, @now + 1)
+
+ offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 3, :future)
+
+ assert_equal Time.local(2006, 8, 16, 17), offset_span.begin
+ assert_equal Time.local(2006, 8, 16, 17, 0, 1), offset_span.end
+
+ offset_span = Chronic::RepeaterHour.new(:hour).offset(span, 24, :past)
+
+ assert_equal Time.local(2006, 8, 15, 14), offset_span.begin
+ assert_equal Time.local(2006, 8, 15, 14, 0, 1), offset_span.end
+ end
+
+end
\ No newline at end of file