public
Fork of mojombo/chronic
Description: Chronic is a pure Ruby natural language date parser.
Homepage: http://chronic.rubyforge.org
Clone URL: git://github.com/technoweenie/chronic.git
chronic / test / test_RepeaterDayName.rb
100644 52 lines (37 sloc) 1.384 kb
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
require 'chronic'
require 'test/unit'
 
class TestRepeaterDayName < Test::Unit::TestCase
  
  def setup
    @now = Time.local(2006, 8, 16, 14, 0, 0, 0)
  end
  
  def test_match
    token = Chronic::Token.new('saturday')
    repeater = Chronic::Repeater.scan_for_day_names(token)
    assert_equal Chronic::RepeaterDayName, repeater.class
    assert_equal :saturday, repeater.type
    
    token = Chronic::Token.new('sunday')
    repeater = Chronic::Repeater.scan_for_day_names(token)
    assert_equal Chronic::RepeaterDayName, repeater.class
    assert_equal :sunday, repeater.type
  end
 
  def test_next_future
    mondays = Chronic::RepeaterDayName.new(:monday)
    mondays.start = @now
    
    span = mondays.next(:future)
    
    assert_equal Time.local(2006, 8, 21), span.begin
    assert_equal Time.local(2006, 8, 22), span.end
 
    span = mondays.next(:future)
    
    assert_equal Time.local(2006, 8, 28), span.begin
    assert_equal Time.local(2006, 8, 29), span.end
  end
  
  def test_next_past
    mondays = Chronic::RepeaterDayName.new(:monday)
    mondays.start = @now
    
    span = mondays.next(:past)
    
    assert_equal Time.local(2006, 8, 14), span.begin
    assert_equal Time.local(2006, 8, 15), span.end
 
    span = mondays.next(:past)
    
    assert_equal Time.local(2006, 8, 7), span.begin
    assert_equal Time.local(2006, 8, 8), span.end
  end
  
end