File: test_Handler.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 (104 lines) | stat: -rw-r--r-- 3,009 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'helper'

class TestHandler < Test::Unit::TestCase

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

  def test_handler_class_1
    handler = Chronic::Handler.new([:repeater], :handler)

    tokens = [Chronic::Token.new('friday')]
    tokens[0].tag(Chronic::RepeaterDayName.new(:friday))

    assert handler.match(tokens, Chronic.definitions)

    tokens << Chronic::Token.new('afternoon')
    tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))

    assert !handler.match(tokens, Chronic.definitions)
  end

  def test_handler_class_2
    handler = Chronic::Handler.new([:repeater, :repeater?], :handler)

    tokens = [Chronic::Token.new('friday')]
    tokens[0].tag(Chronic::RepeaterDayName.new(:friday))

    assert handler.match(tokens, Chronic.definitions)

    tokens << Chronic::Token.new('afternoon')
    tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))

    assert handler.match(tokens, Chronic.definitions)

    tokens << Chronic::Token.new('afternoon')
    tokens[2].tag(Chronic::RepeaterDayPortion.new(:afternoon))

    assert !handler.match(tokens, Chronic.definitions)
  end

  def test_handler_class_3
    handler = Chronic::Handler.new([:repeater, 'time?'], :handler)

    tokens = [Chronic::Token.new('friday')]
    tokens[0].tag(Chronic::RepeaterDayName.new(:friday))

    assert handler.match(tokens, Chronic.definitions)

    tokens << Chronic::Token.new('afternoon')
    tokens[1].tag(Chronic::RepeaterDayPortion.new(:afternoon))

    assert !handler.match(tokens, Chronic.definitions)
  end

  def test_handler_class_4
    handler = Chronic::Handler.new([:repeater_month_name, :scalar_day, 'time?'], :handler)

    tokens = [Chronic::Token.new('may')]
    tokens[0].tag(Chronic::RepeaterMonthName.new(:may))

    assert !handler.match(tokens, Chronic.definitions)

    tokens << Chronic::Token.new('27')
    tokens[1].tag(Chronic::ScalarDay.new(27))

    assert handler.match(tokens, Chronic.definitions)
  end

  def test_handler_class_5
    handler = Chronic::Handler.new([:repeater, 'time?'], :handler)

    tokens = [Chronic::Token.new('friday')]
    tokens[0].tag(Chronic::RepeaterDayName.new(:friday))

    assert handler.match(tokens, Chronic.definitions)

    tokens << Chronic::Token.new('5:00')
    tokens[1].tag(Chronic::RepeaterTime.new('5:00'))

    assert handler.match(tokens, Chronic.definitions)

    tokens << Chronic::Token.new('pm')
    tokens[2].tag(Chronic::RepeaterDayPortion.new(:pm))

    assert handler.match(tokens, Chronic.definitions)
  end

  def test_handler_class_6
    handler = Chronic::Handler.new([:scalar, :repeater, :pointer], :handler)

    tokens = [Chronic::Token.new('3'),
              Chronic::Token.new('years'),
              Chronic::Token.new('past')]

    tokens[0].tag(Chronic::Scalar.new(3))
    tokens[1].tag(Chronic::RepeaterYear.new(:year))
    tokens[2].tag(Chronic::Pointer.new(:past))

    assert handler.match(tokens, Chronic.definitions)
  end

end