File: test_view.rb

package info (click to toggle)
vpim 0.695-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 584 kB
  • ctags: 964
  • sloc: ruby: 8,431; makefile: 69; sh: 4
file content (79 lines) | stat: -rw-r--r-- 1,608 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env ruby

require 'test/unit'

require 'vpim/repo'
require 'vpim/view'

class TestView < Test::Unit::TestCase
  View = Vpim::View
  Icalendar = Vpim::Icalendar

  def _test_week_events(vc, kind)
    vc = Icalendar.decode(vc.to_s.gsub("EVENT", kind)).first

    vv = View.week vc

    reader = kind.downcase + "s"

    kind = "check against kind=" + kind + "<\n" + vv.to_s + ">\n"

    assert_no_match(/yesterday/, vv.to_s, kind)
    assert_no_match(/nextweek/, vv.to_s, kind)

    assert_equal(["starts tomorrow"], vv.send(reader).map{|ve| ve.summary}, kind)
  end

  def test_week_single
    now = Time.now
    yesterday = now - View::SECSPERDAY
    tomorrow  = now + View::SECSPERDAY
    nextweek  = now + View::SECSPERDAY * 8

    vc = Icalendar.create2 do |vc|
      %w{yesterday tomorrow nextweek}.each do |dtstart|
        vc.add_event do |ve|
          ve.dtstart eval(dtstart)
          ve.summary "starts #{dtstart}"
        end
      end
    end

    _test_week_events(vc, "EVENT")
    _test_week_events(vc, "TODO")
    _test_week_events(vc, "JOURNAL")
  end

  def test_week_recurring
    now = Time.now
    ago = now - View::SECSPERDAY * 2

    vc = Icalendar.create2 do |vc|
      vc.add_event do |ve|
        ve.dtstart ago
        ve.dtend   ago + View::SECSPERDAY / 2
        ve.add_rrule do |r|
          r.frequency = "daily"
        end
      end
    end

    vv = View.week vc

    assert_equal(1, vv.events.to_a.size)

    ve = vv.events{|e| break e}

    #p ve

    #puts "now=" + now.to_s

    ve.occurrences() do |t|
      p [now, t, t + ve.duration]
    end



  end
end