File: test_RepeaterWeekend.rb

package info (click to toggle)
ruby-chronic 0.6.7-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 384 kB
  • sloc: ruby: 3,726; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 2,209 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require 'helper'

class TestRepeaterWeekend < Test::Unit::TestCase

  def setup
    # Wed Aug 16 14:00:00 2006
    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
  end

  def test_next_future
    weekend = Chronic::RepeaterWeekend.new(:weekend)
    weekend.start = @now

    next_weekend = weekend.next(:future)
    assert_equal Time.local(2006, 8, 19), next_weekend.begin
    assert_equal Time.local(2006, 8, 21), next_weekend.end
  end

  def test_next_past
    weekend = Chronic::RepeaterWeekend.new(:weekend)
    weekend.start = @now

    next_weekend = weekend.next(:past)
    assert_equal Time.local(2006, 8, 12), next_weekend.begin
    assert_equal Time.local(2006, 8, 14), next_weekend.end
  end

  def test_this_future
    weekend = Chronic::RepeaterWeekend.new(:weekend)
    weekend.start = @now

    next_weekend = weekend.this(:future)
    assert_equal Time.local(2006, 8, 19), next_weekend.begin
    assert_equal Time.local(2006, 8, 21), next_weekend.end
  end

  def test_this_past
    weekend = Chronic::RepeaterWeekend.new(:weekend)
    weekend.start = @now

    next_weekend = weekend.this(:past)
    assert_equal Time.local(2006, 8, 12), next_weekend.begin
    assert_equal Time.local(2006, 8, 14), next_weekend.end
  end

  def test_this_none
    weekend = Chronic::RepeaterWeekend.new(:weekend)
    weekend.start = @now

    next_weekend = weekend.this(:future)
    assert_equal Time.local(2006, 8, 19), next_weekend.begin
    assert_equal Time.local(2006, 8, 21), next_weekend.end
  end

  def test_offset
    span = Chronic::Span.new(@now, @now + 1)

    offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 3, :future)

    assert_equal Time.local(2006, 9, 2), offset_span.begin
    assert_equal Time.local(2006, 9, 2, 0, 0, 1), offset_span.end

    offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 1, :past)

    assert_equal Time.local(2006, 8, 12), offset_span.begin
    assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end

    offset_span = Chronic::RepeaterWeekend.new(:weekend).offset(span, 0, :future)

    assert_equal Time.local(2006, 8, 12), offset_span.begin
    assert_equal Time.local(2006, 8, 12, 0, 0, 1), offset_span.end
  end

end