mumboe-vpim 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/CHANGES +510 -0
  2. data/COPYING +58 -0
  3. data/README +185 -0
  4. data/lib/vpim/address.rb +219 -0
  5. data/lib/vpim/agent/atomize.rb +104 -0
  6. data/lib/vpim/agent/base.rb +73 -0
  7. data/lib/vpim/agent/calendars.rb +173 -0
  8. data/lib/vpim/agent/handler.rb +26 -0
  9. data/lib/vpim/agent/ics.rb +161 -0
  10. data/lib/vpim/attachment.rb +102 -0
  11. data/lib/vpim/date.rb +222 -0
  12. data/lib/vpim/dirinfo.rb +277 -0
  13. data/lib/vpim/duration.rb +119 -0
  14. data/lib/vpim/enumerator.rb +32 -0
  15. data/lib/vpim/field.rb +614 -0
  16. data/lib/vpim/icalendar.rb +384 -0
  17. data/lib/vpim/maker/vcard.rb +16 -0
  18. data/lib/vpim/property/base.rb +193 -0
  19. data/lib/vpim/property/common.rb +315 -0
  20. data/lib/vpim/property/location.rb +38 -0
  21. data/lib/vpim/property/priority.rb +43 -0
  22. data/lib/vpim/property/recurrence.rb +69 -0
  23. data/lib/vpim/property/resources.rb +24 -0
  24. data/lib/vpim/repo.rb +261 -0
  25. data/lib/vpim/rfc2425.rb +367 -0
  26. data/lib/vpim/rrule.rb +591 -0
  27. data/lib/vpim/time.rb +40 -0
  28. data/lib/vpim/vcard.rb +1456 -0
  29. data/lib/vpim/version.rb +18 -0
  30. data/lib/vpim/vevent.rb +187 -0
  31. data/lib/vpim/view.rb +90 -0
  32. data/lib/vpim/vjournal.rb +58 -0
  33. data/lib/vpim/vpim.rb +65 -0
  34. data/lib/vpim/vtodo.rb +103 -0
  35. data/lib/vpim.rb +13 -0
  36. data/samples/README.mutt +93 -0
  37. data/samples/ab-query.rb +57 -0
  38. data/samples/agent.ru +10 -0
  39. data/samples/cmd-itip.rb +156 -0
  40. data/samples/ex_cpvcard.rb +55 -0
  41. data/samples/ex_get_vcard_photo.rb +22 -0
  42. data/samples/ex_mkv21vcard.rb +34 -0
  43. data/samples/ex_mkvcard.rb +64 -0
  44. data/samples/ex_mkyourown.rb +29 -0
  45. data/samples/ics-dump.rb +210 -0
  46. data/samples/ics-to-rss.rb +84 -0
  47. data/samples/mutt-aliases-to-vcf.rb +45 -0
  48. data/samples/osx-wrappers.rb +86 -0
  49. data/samples/reminder.rb +209 -0
  50. data/samples/rrule.rb +71 -0
  51. data/samples/tabbed-file-to-vcf.rb +390 -0
  52. data/samples/vcf-dump.rb +86 -0
  53. data/samples/vcf-lines.rb +61 -0
  54. data/samples/vcf-to-ics.rb +22 -0
  55. data/samples/vcf-to-mutt.rb +121 -0
  56. data/test/test_agent_atomize.rb +84 -0
  57. data/test/test_agent_calendars.rb +128 -0
  58. data/test/test_agent_ics.rb +96 -0
  59. data/test/test_all.rb +17 -0
  60. data/test/test_date.rb +120 -0
  61. data/test/test_dur.rb +41 -0
  62. data/test/test_field.rb +156 -0
  63. data/test/test_ical.rb +437 -0
  64. data/test/test_misc.rb +13 -0
  65. data/test/test_repo.rb +129 -0
  66. data/test/test_rrule.rb +1030 -0
  67. data/test/test_vcard.rb +973 -0
  68. data/test/test_view.rb +79 -0
  69. metadata +140 -0
data/test/test_ical.rb ADDED
@@ -0,0 +1,437 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vpim/icalendar'
4
+ require 'test/unit'
5
+
6
+
7
+ # Sorry for the donkey patching...
8
+ module Enumerable
9
+ def first
10
+ find{true}
11
+ end
12
+ def last
13
+ inject{|memo, o| o}
14
+ end
15
+ end
16
+
17
+ include Vpim
18
+
19
+ Req_1 =<<___
20
+ BEGIN:VCALENDAR
21
+ METHOD:REQUEST
22
+ PRODID:-//Lotus Development Corporation//NONSGML Notes 6.0//EN
23
+ VERSION:2.0
24
+ X-LOTUS-CHARSET:UTF-8
25
+ BEGIN:VTIMEZONE
26
+ TZID:Pacific
27
+ BEGIN:STANDARD
28
+ DTSTART:19501029T020000
29
+ TZOFFSETFROM:-0700
30
+ TZOFFSETTO:-0800
31
+ RRULE:FREQ=YEARLY;BYMINUTE=0;BYHOUR=2;BYDAY=-1SU;BYMONTH=10
32
+ END:STANDARD
33
+ BEGIN:DAYLIGHT
34
+ DTSTART:19500402T020000
35
+ TZOFFSETFROM:-0800
36
+ TZOFFSETTO:-0700
37
+ RRULE:FREQ=YEARLY;BYMINUTE=0;BYHOUR=2;BYDAY=1SU;BYMONTH=4
38
+ END:DAYLIGHT
39
+ END:VTIMEZONE
40
+ BEGIN:VEVENT
41
+ ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED;CN="Gary Pope/Certicom"
42
+ ;RSVP=FALSE:mailto:gpope@certicom.com
43
+ ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION
44
+ ;CN="Mike Harvey/Certicom";RSVP=TRUE:mailto:MHarvey@certicom.com
45
+ ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE
46
+ :mailto:rgallant@emilpost.certicom.com
47
+ ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION
48
+ ;CN="Sam Roberts/Certicom";RSVP=TRUE:mailto:SRoberts@certicom.com
49
+ ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION
50
+ ;CN="Tony Walters/Certicom";RSVP=TRUE:mailto:TWalters@certicom.com
51
+ CLASS:PUBLIC
52
+ DTEND;TZID="Pacific":20040415T130000
53
+ DTSTAMP:20040319T205045Z
54
+ DTSTART;TZID="Pacific":20040415T120000
55
+ ORGANIZER;CN="Gary Pope/Certicom":mailto:gpope@certicom.com
56
+ SEQUENCE:0
57
+ SUMMARY:hjold intyel
58
+ TRANSP:OPAQUE
59
+ UID:3E19204063C93D2388256E5C006BF8D9-Lotus_Notes_Generated
60
+ X-LOTUS-BROADCAST:FALSE
61
+ X-LOTUS-CHILD_UID:3E19204063C93D2388256E5C006BF8D9
62
+ X-LOTUS-NOTESVERSION:2
63
+ X-LOTUS-NOTICETYPE:I
64
+ X-LOTUS-UPDATE-SEQ:1
65
+ X-LOTUS-UPDATE-WISL:$S:1;$L:1;$B:1;$R:1;$E:1
66
+ END:VEVENT
67
+ END:VCALENDAR
68
+ ___
69
+
70
+ Rep_1 =<<___
71
+ BEGIN:VCALENDAR
72
+ CALSCALE:GREGORIAN
73
+ PRODID:-//Apple Computer\, Inc//iCal 1.5//EN
74
+ VERSION:2.0
75
+ METHOD:REPLY
76
+ BEGIN:VEVENT
77
+ ATTENDEE;CN="Sam Roberts/Certicom";PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPAN
78
+ T;RSVP=TRUE:mailto:SRoberts@certicom.com
79
+ CLASS:PUBLIC
80
+ DTEND;TZID=Pacific:20040415T130000
81
+ DTSTAMP:20040319T205045Z
82
+ DTSTART;TZID=Pacific:20040415T120000
83
+ ORGANIZER;CN="Gary Pope/Certicom":mailto:gpope@certicom.com
84
+ SEQUENCE:0
85
+ SUMMARY:hjold intyel
86
+ TRANSP:OPAQUE
87
+ UID:3E19204063C93D2388256E5C006BF8D9-Lotus_Notes_Generated
88
+ X-LOTUS-BROADCAST:FALSE
89
+ X-LOTUS-CHILDUID:3E19204063C93D2388256E5C006BF8D9
90
+ X-LOTUS-NOTESVERSION:2
91
+ X-LOTUS-NOTICETYPE:I
92
+ X-LOTUS-UPDATE-SEQ:1
93
+ X-LOTUS-UPDATE-WISL:$S:1\;$L:1\;$B:1\;$R:1\;$E:1
94
+ END:VEVENT
95
+ END:VCALENDAR
96
+ ___
97
+
98
+ class TestIcal < Test::Unit::TestCase
99
+
100
+ def assert_time(expected, actual, msg = nil)
101
+ assert_in_delta(expected, actual, 1, msg)
102
+ end
103
+
104
+ # Reported by Kyle Maxwell
105
+ def test_serialize_todo
106
+ icstodo =<<___
107
+ BEGIN:VCALENDAR
108
+ VERSION:2.0
109
+ BEGIN:VTODO
110
+ END:VTODO
111
+ END:VCALENDAR
112
+ ___
113
+
114
+ cal = Icalendar.decode(icstodo)
115
+ assert_equal(icstodo, cal.to_s)
116
+ end
117
+
118
+ # Tracker #18920
119
+ def test_recurring_todos
120
+ icstodo =<<___
121
+ BEGIN:VCALENDAR
122
+ VERSION:2.0
123
+ BEGIN:VTODO
124
+ SUMMARY:todo
125
+ DTSTART:20040415T120000
126
+ RRULE:FREQ=WEEKLY;COUNT=2
127
+ END:VTODO
128
+ END:VCALENDAR
129
+ ___
130
+
131
+ cal = Icalendar.decode(icstodo).first
132
+ todo = cal.todos.first
133
+ assert(todo)
134
+ assert_equal(todo.occurrences.to_a.size, 2)
135
+ end
136
+
137
+ def test_1
138
+ req = Icalendar.decode(Req_1).first
139
+
140
+ req.components { }
141
+ req.components(Icalendar::Vevent) { }
142
+ req.components(Icalendar::Vjournal) { }
143
+ assert_equal(1, req.components.size)
144
+ assert_equal(1, req.components(Icalendar::Vevent).size)
145
+ assert_equal(0, req.components(Icalendar::Vjournal).size)
146
+
147
+ assert_equal(req.protocol, 'REQUEST')
148
+
149
+ event = req.events.first
150
+
151
+ assert(event)
152
+
153
+ assert( event.attendee?('mailto:sroberts@certicom.com'))
154
+ assert(!event.attendee?('mailto:sroberts@uniserve.com'))
155
+
156
+ me = event.attendees('mailto:sroberts@certicom.com').first
157
+
158
+ assert(me)
159
+ assert(me == 'mailto:sroberts@certicom.com')
160
+
161
+ reply = Icalendar.create_reply
162
+
163
+ reply.push(event.accept(me))
164
+
165
+ # puts "Reply=>"
166
+ # puts reply.to_s
167
+ end
168
+
169
+ def test_hal1
170
+ # Hal was encoding raw strings, here's how to do it with the API.
171
+
172
+ cal = Icalendar.create
173
+
174
+ start = Time.now
175
+
176
+ event = Icalendar::Vevent.create(start,
177
+ 'DTEND' => start + 60 * 60,
178
+ 'SUMMARY' => "this is an event",
179
+ 'RRULE' => 'freq=monthly;byday=2fr,4fr;count=5'
180
+ )
181
+
182
+ cal.push event
183
+
184
+ #puts cal.encode
185
+ end
186
+
187
+ # FIXME - test bad durations, like 'PT1D'
188
+
189
+ def test_event_duration
190
+ now = Time.now
191
+ event = Icalendar::Vevent.create(now)
192
+ assert_time(now, event.dtstart)
193
+ assert_nil(event.duration)
194
+ assert_nil(event.dtend)
195
+
196
+ event = Icalendar::Vevent.create(Date.new(2000, 1, 21),
197
+ 'DURATION' => 'PT1H')
198
+ assert_equal(Time.gm(2000, 1, 21, 1), event.dtend)
199
+
200
+ event = Icalendar::Vevent.create(Date.new(2000, 1, 21),
201
+ 'DTEND' => Date.new(2000, 1, 22))
202
+ assert_equal(24*60*60, event.duration)
203
+ end
204
+
205
+ def test_todo_duration
206
+ todo = Icalendar::Vtodo.create()
207
+ assert_nil(todo.dtstart)
208
+ assert_nil(todo.duration)
209
+ assert_nil(todo.due)
210
+
211
+ todo = Icalendar::Vtodo.create('DTSTART' => Date.new(2000, 1, 21),
212
+ 'DURATION' => 'PT1H')
213
+ assert_equal(Time.gm(2000, 1, 21, 1), todo.due)
214
+
215
+ todo = Icalendar::Vtodo.create('DTSTART' => Date.new(2000, 1, 21),
216
+ 'DUE' => Date.new(2000, 1, 22))
217
+ assert_equal(24*60*60, todo.duration)
218
+ end
219
+
220
+ def test_journal_create
221
+ vj = Icalendar::Vjournal.create('DESCRIPTION' => "description")
222
+ assert_equal("description", vj.description)
223
+ end
224
+
225
+ def TODO_test_occurrence_with_date_start
226
+ d = Date.new(2000, 1, 21)
227
+ event = Icalendar::Vevent.create(d)
228
+ d1 = event.occurences.to_a.first
229
+ assert_equal(d.class, d1.class)
230
+ end
231
+
232
+ def test_decode_duration_four_weeks
233
+ assert_equal 4*7*86400, Icalendar.decode_duration('P4W')
234
+ end
235
+
236
+ def test_decode_duration_negative_two_weeks
237
+ assert_equal(-2*7*86400, Icalendar.decode_duration('-P2W'))
238
+ end
239
+
240
+ def test_decode_duration_five_days
241
+ assert_equal 5*86400, Icalendar.decode_duration('P5D')
242
+ end
243
+
244
+ def test_decode_duration_one_hour
245
+ assert_equal 3600, Icalendar.decode_duration('PT1H')
246
+ end
247
+
248
+ def test_decode_duration_five_minutes
249
+ assert_equal 5*60, Icalendar.decode_duration('PT5M')
250
+ end
251
+
252
+ def test_decode_duration_ten_seconds
253
+ assert_equal 10, Icalendar.decode_duration('PT10S')
254
+ end
255
+
256
+ def test_decode_duration_with_leading_plus
257
+ assert_equal 10, Icalendar.decode_duration('+PT10S')
258
+ end
259
+
260
+ def test_decode_duration_with_composite_duration
261
+ assert_equal((15*86400+5*3600+20), Icalendar.decode_duration('P15DT5H0M20S'))
262
+ end
263
+
264
+ def test_create_with_prodid
265
+ prodid = "me//here/non-sgml"
266
+ cal = Icalendar.create2(prodid) do |cal|
267
+ assert_respond_to(cal, :push)
268
+ end
269
+ assert_equal(prodid, cal.producer)
270
+ end
271
+
272
+ def test_occurences
273
+ t0 = Time.now
274
+ vc = Icalendar.create2 do |vc|
275
+ vc.add_event do |ve|
276
+ ve.dtstart t0
277
+ end
278
+ end
279
+ ve = vc.components(Icalendar::Vevent).first
280
+ assert_time(t0, ve.occurences.select{true}.first)
281
+ ve.occurences do |t|
282
+ assert_time(t0, t)
283
+ end
284
+
285
+ vc = Icalendar.decode(<<__).first
286
+ BEGIN:VCALENDAR
287
+ BEGIN:VEVENT
288
+ END:VEVENT
289
+ END:VCALENDAR
290
+ __
291
+ ve = vc.components(Icalendar::Vevent).first
292
+ assert_raises(ArgumentError) { ve.occurences }
293
+ end
294
+
295
+ def test_each
296
+ vc = Icalendar.decode(<<__).first
297
+ BEGIN:VCALENDAR
298
+ BEGIN:VEVENT
299
+ END:VEVENT
300
+ BEGIN:VTODO
301
+ END:VTODO
302
+ BEGIN:VJOURNAL
303
+ END:VJOURNAL
304
+ BEGIN:VTIMEZONE
305
+ END:VTIMEZONE
306
+ BEGIN:X-UNKNOWN
307
+ END:X-UNKNOWN
308
+ END:VCALENDAR
309
+ __
310
+ count = Hash.new(0)
311
+
312
+ vc.each do |c| count[c.class] += 1 end
313
+
314
+ assert_equal(3, count.size)
315
+ count.each do |_,v| assert_equal(1, v) end
316
+
317
+ count = Hash.new(0)
318
+ vc.events do |c| count[c.class] += 1 end
319
+ vc.todos do |c| count[c.class] += 1 end
320
+ vc.journals do |c| count[c.class] += 1 end
321
+ assert_equal(3, count.size)
322
+ count.each do |_,v| assert_equal(1, v) end
323
+
324
+ assert_equal(3, vc.each.to_a.size)
325
+ assert_equal(1, vc.each.select{|c| Vpim::Icalendar::Vevent === c}.size)
326
+ assert_equal(1, vc.each.select{|c| Vpim::Icalendar::Vtodo === c}.size)
327
+ assert_equal(1, vc.each.select{|c| Vpim::Icalendar::Vjournal === c}.size)
328
+
329
+ assert_equal(1, vc.events.to_a.size)
330
+ assert_equal(1, vc.todos.to_a.size)
331
+ assert_equal(1, vc.journals.to_a.size)
332
+
333
+ vc.to_s # Shouldn't raise...
334
+ # TODO - encode isn't round-tripping, unknown components are lost, which is
335
+ # not good.
336
+ end
337
+
338
+ def test_calscale
339
+ req = Icalendar.decode(<<__).first
340
+ BEGIN:VCALENDAR
341
+ END:VCALENDAR
342
+ __
343
+ assert_equal("GREGORIAN", req.calscale)
344
+ req = Icalendar.decode(<<__).first
345
+ BEGIN:VCALENDAR
346
+ CALSCALE:GREGORIAN
347
+ END:VCALENDAR
348
+ __
349
+ assert_equal("GREGORIAN", req.calscale)
350
+ end
351
+
352
+ def test_version
353
+ req = Icalendar.decode(<<__).first
354
+ BEGIN:VCALENDAR
355
+ END:VCALENDAR
356
+ __
357
+ assert_raises(InvalidEncodingError) { req.version }
358
+
359
+ req = Icalendar.decode(<<__).first
360
+ BEGIN:VCALENDAR
361
+ VERSION:2.0
362
+ END:VCALENDAR
363
+ __
364
+ assert_equal(20, req.version)
365
+ end
366
+
367
+ def test_protocol
368
+ req = Icalendar.decode(<<__).first
369
+ BEGIN:VCALENDAR
370
+ METHOD:GET
371
+ END:VCALENDAR
372
+ __
373
+ assert(req.protocol?("get"))
374
+ assert(!req.protocol?("set"))
375
+ end
376
+
377
+ def test_transparency
378
+ transparency = Icalendar.decode(<<__).first.to_a.first.transparency
379
+ BEGIN:VCALENDAR
380
+ BEGIN:VEVENT
381
+ END:VEVENT
382
+ END:VCALENDAR
383
+ __
384
+ assert_equal("OPAQUE", transparency, "check default")
385
+
386
+ transparency = Icalendar.decode(<<__).first.to_a.first.transparency
387
+ BEGIN:VCALENDAR
388
+ BEGIN:VEVENT
389
+ TRANSP:Opaque
390
+ END:VEVENT
391
+ END:VCALENDAR
392
+ __
393
+ assert_equal("OPAQUE", transparency, "check opaque")
394
+
395
+ transparency = Icalendar.decode(<<__).first.to_a.first.transparency
396
+ BEGIN:VCALENDAR
397
+ BEGIN:VEVENT
398
+ TRANSP:TrANSPARENT
399
+ END:VEVENT
400
+ END:VCALENDAR
401
+ __
402
+ assert_equal("TRANSPARENT", transparency, "check transparent")
403
+
404
+ end
405
+
406
+ def test_location
407
+ cal = Icalendar.decode(<<__).first
408
+ BEGIN:VCALENDAR
409
+ BEGIN:VEVENT
410
+ LOCATION:bien located
411
+ END:VEVENT
412
+ BEGIN:VTODO
413
+ LOCATION:
414
+ END:VTODO
415
+ BEGIN:VEVENT
416
+ END:VEVENT
417
+ END:VCALENDAR
418
+ __
419
+ assert_equal(cal.events.first.location, "bien located")
420
+ assert_equal(cal.todos.first.location, "")
421
+ assert_equal(cal.events.last.location, nil)
422
+ end
423
+
424
+
425
+ def test_event_maker_w_rrule
426
+ vc = Icalendar.create2 do |vc|
427
+ vc.add_event do |m|
428
+ m.add_rrule("freq=monthly")
429
+ m.set_rrule do |_| _.frequency = "daily" end
430
+ end
431
+ end
432
+ assert_no_match(/RRULE:FREQ=MONTHLY/, vc.to_s)
433
+ assert_match(/RRULE:FREQ=DAILY/, vc.to_s)
434
+ end
435
+
436
+ end
437
+
data/test/test_misc.rb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'vpim/version'
5
+
6
+ class TestVpimMisc < Test::Unit::TestCase
7
+
8
+ def test_version
9
+ assert_match(/0.\d+/, Vpim.version)
10
+ end
11
+
12
+ end
13
+
data/test/test_repo.rb ADDED
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vpim/repo'
4
+ require 'test/common'
5
+
6
+ class TestRepo < Test::Unit::TestCase
7
+ Apple3 = Vpim::Repo::Apple3
8
+ Directory = Vpim::Repo::Directory
9
+ Uri = Vpim::Repo::Uri
10
+
11
+ def setup
12
+ @testdir = Dir.getwd + "/test" #File.dirname($0) doesn't work with rcov :-(
13
+ @caldir = @testdir + "/calendars"
14
+ @eventsz = Dir[@caldir + "/**/*.ics"].size
15
+ assert(@testdir)
16
+ assert(test(?d, @caldir), "no caldir "+@caldir)
17
+ end
18
+
19
+ def _test_each(repo, eventsz)
20
+ repo.each do |cal|
21
+ assert_equal(eventsz, cal.events.count, cal.name)
22
+ assert("", File.extname(cal.name))
23
+ assert_equal(cal.displayed, true)
24
+ cal.events do |c|
25
+ assert_instance_of(Vpim::Icalendar::Vevent, c)
26
+ end
27
+ cal.events.each do |c|
28
+ assert_instance_of(Vpim::Icalendar::Vevent, c)
29
+ end
30
+ assert_equal(0, cal.todos.count)
31
+ assert(cal.encode)
32
+ end
33
+ end
34
+
35
+ def test_apple3
36
+ repo = Apple3.new(@caldir)
37
+
38
+ assert_equal(1, repo.count)
39
+
40
+ _test_each(repo, @eventsz)
41
+ end
42
+
43
+ def test_dir
44
+ assert(test(?d, @caldir))
45
+
46
+ repo = Directory.new(@caldir)
47
+
48
+ assert_equal(@eventsz, repo.count)
49
+
50
+ _test_each(repo, 1)
51
+ end
52
+
53
+ def test_uri_http
54
+ caldata = open('test/calendars/weather.calendar/Events/1205042405-0-0.ics').read
55
+
56
+ server = data_on_port(caldata, 9876)
57
+ begin
58
+ c = Uri::Calendar.new("http://localhost:9876")
59
+ assert_equal(caldata, c.encode)
60
+
61
+ repo = Uri.new("http://localhost:9876")
62
+
63
+ assert_equal(1, repo.count)
64
+
65
+ _test_each(repo, 1)
66
+ ensure
67
+ server.kill
68
+ end
69
+ end
70
+
71
+ def test_uri_webcal
72
+ caldata = open('test/calendars/weather.calendar/Events/1205042405-0-0.ics').read
73
+
74
+ server = data_on_port(caldata, 9876)
75
+ begin
76
+ c = Uri::Calendar.new("webcal://localhost:9876")
77
+ assert_equal(caldata, c.encode)
78
+
79
+ repo = Uri.new("webcal://localhost:9876")
80
+
81
+ assert_equal(1, repo.count)
82
+
83
+ _test_each(repo, 1)
84
+ ensure
85
+ server.kill
86
+ end
87
+ end
88
+
89
+
90
+ def test_uri_invalid
91
+ assert_raises(ArgumentError) do
92
+ Uri.new("url")
93
+ end
94
+ assert_raises(ArgumentError) do
95
+ c = Uri::Calendar.new("url://localhost")
96
+ end
97
+ assert_raises(ArgumentError) do
98
+ c = Uri::Calendar.new("https://localhost")
99
+ end
100
+ end
101
+
102
+ def test_uri_unreachable
103
+ assert_raises(SocketError) do
104
+ r = Uri.new("http://example.example")
105
+ c = r.find{true}
106
+ c.events{}
107
+ end
108
+ assert_raises(Errno::ECONNREFUSED) do
109
+ r = Uri.new("http://rubyforge.org:81")
110
+ c = r.find{true}
111
+ c.events{}
112
+ end
113
+ assert_raises(StandardError, Vpim::InvalidEncodingError) do
114
+ r = Uri.new("http://rubyforge.org/lua-rocks-my-world")
115
+ c = r.find{true}
116
+ c.events{}
117
+ end
118
+ end
119
+
120
+ def test_uri_unparseable
121
+ assert_raises(Vpim::InvalidEncodingError) do
122
+ r = Uri.new("http://example.com:80")
123
+ c = r.find{true}
124
+ c.events{}
125
+ end
126
+ end
127
+
128
+ end
129
+