tilia-vobject 4.0.0.pre.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +32 -0
  4. data/.simplecov +4 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.sabre.md +626 -0
  7. data/CONTRIBUTING.md +25 -0
  8. data/Gemfile +17 -0
  9. data/Gemfile.lock +68 -0
  10. data/LICENSE +27 -0
  11. data/LICENSE.sabre +27 -0
  12. data/README.md +63 -0
  13. data/Rakefile +17 -0
  14. data/bin/vobject +7 -0
  15. data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
  16. data/lib/tilia/v_object/cli.rb +582 -0
  17. data/lib/tilia/v_object/component/available.rb +107 -0
  18. data/lib/tilia/v_object/component/v_alarm.rb +114 -0
  19. data/lib/tilia/v_object/component/v_availability.rb +128 -0
  20. data/lib/tilia/v_object/component/v_calendar.rb +468 -0
  21. data/lib/tilia/v_object/component/v_card.rb +457 -0
  22. data/lib/tilia/v_object/component/v_event.rb +127 -0
  23. data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
  24. data/lib/tilia/v_object/component/v_journal.rb +75 -0
  25. data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
  26. data/lib/tilia/v_object/component/v_todo.rb +147 -0
  27. data/lib/tilia/v_object/component.rb +591 -0
  28. data/lib/tilia/v_object/date_time_parser.rb +486 -0
  29. data/lib/tilia/v_object/document.rb +218 -0
  30. data/lib/tilia/v_object/element_list.rb +18 -0
  31. data/lib/tilia/v_object/eof_exception.rb +8 -0
  32. data/lib/tilia/v_object/free_busy_data.rb +149 -0
  33. data/lib/tilia/v_object/free_busy_generator.rb +465 -0
  34. data/lib/tilia/v_object/i_tip/broker.rb +909 -0
  35. data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
  36. data/lib/tilia/v_object/i_tip/message.rb +109 -0
  37. data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
  38. data/lib/tilia/v_object/i_tip.rb +10 -0
  39. data/lib/tilia/v_object/node.rb +192 -0
  40. data/lib/tilia/v_object/parameter.rb +327 -0
  41. data/lib/tilia/v_object/parse_exception.rb +7 -0
  42. data/lib/tilia/v_object/parser/json.rb +149 -0
  43. data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
  44. data/lib/tilia/v_object/parser/parser.rb +61 -0
  45. data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
  46. data/lib/tilia/v_object/parser/xml/element.rb +11 -0
  47. data/lib/tilia/v_object/parser/xml.rb +322 -0
  48. data/lib/tilia/v_object/parser.rb +10 -0
  49. data/lib/tilia/v_object/property/binary.rb +96 -0
  50. data/lib/tilia/v_object/property/boolean.rb +57 -0
  51. data/lib/tilia/v_object/property/flat_text.rb +52 -0
  52. data/lib/tilia/v_object/property/float_value.rb +107 -0
  53. data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
  54. data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
  55. data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
  56. data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
  57. data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
  58. data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
  59. data/lib/tilia/v_object/property/i_calendar.rb +14 -0
  60. data/lib/tilia/v_object/property/integer_value.rb +60 -0
  61. data/lib/tilia/v_object/property/text.rb +352 -0
  62. data/lib/tilia/v_object/property/time.rb +85 -0
  63. data/lib/tilia/v_object/property/unknown.rb +30 -0
  64. data/lib/tilia/v_object/property/uri.rb +78 -0
  65. data/lib/tilia/v_object/property/utc_offset.rb +56 -0
  66. data/lib/tilia/v_object/property/v_card/date.rb +31 -0
  67. data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
  68. data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
  69. data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
  70. data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
  71. data/lib/tilia/v_object/property/v_card.rb +13 -0
  72. data/lib/tilia/v_object/property.rb +532 -0
  73. data/lib/tilia/v_object/reader.rb +73 -0
  74. data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
  75. data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
  76. data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
  77. data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
  78. data/lib/tilia/v_object/recur.rb +10 -0
  79. data/lib/tilia/v_object/settings.rb +32 -0
  80. data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
  81. data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
  82. data/lib/tilia/v_object/splitter/v_card.rb +56 -0
  83. data/lib/tilia/v_object/splitter.rb +9 -0
  84. data/lib/tilia/v_object/string_util.rb +58 -0
  85. data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
  86. data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
  87. data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
  88. data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
  89. data/lib/tilia/v_object/time_zone_data.rb +10 -0
  90. data/lib/tilia/v_object/time_zone_util.rb +213 -0
  91. data/lib/tilia/v_object/uuid_util.rb +51 -0
  92. data/lib/tilia/v_object/v_card_converter.rb +354 -0
  93. data/lib/tilia/v_object/version.rb +9 -0
  94. data/lib/tilia/v_object/writer.rb +56 -0
  95. data/lib/tilia/v_object.rb +45 -0
  96. data/lib/tilia/vobject.rb +1 -0
  97. data/resources/schema/xcal.rng +1192 -0
  98. data/resources/schema/xcard.rng +388 -0
  99. data/test/test_helper.rb +56 -0
  100. data/test/v_object/attach_issue_test.rb +19 -0
  101. data/test/v_object/birthday_calendar_generator_test.rb +463 -0
  102. data/test/v_object/cli_mock.rb +19 -0
  103. data/test/v_object/cli_test.rb +460 -0
  104. data/test/v_object/component/available_test.rb +59 -0
  105. data/test/v_object/component/v_alarm_test.rb +160 -0
  106. data/test/v_object/component/v_availability_test.rb +388 -0
  107. data/test/v_object/component/v_calendar_test.rb +646 -0
  108. data/test/v_object/component/v_card_test.rb +258 -0
  109. data/test/v_object/component/v_event_test.rb +85 -0
  110. data/test/v_object/component/v_free_busy_test.rb +59 -0
  111. data/test/v_object/component/v_journal_test.rb +85 -0
  112. data/test/v_object/component/v_time_zone_test.rb +47 -0
  113. data/test/v_object/component/v_todo_test.rb +172 -0
  114. data/test/v_object/component_test.rb +419 -0
  115. data/test/v_object/date_time_parser_test.rb +526 -0
  116. data/test/v_object/document_test.rb +71 -0
  117. data/test/v_object/element_list_test.rb +27 -0
  118. data/test/v_object/em_client_test.rb +53 -0
  119. data/test/v_object/empty_parameter_test.rb +65 -0
  120. data/test/v_object/empty_value_issue_test.rb +25 -0
  121. data/test/v_object/fake_component.rb +21 -0
  122. data/test/v_object/free_busy_data_test.rb +285 -0
  123. data/test/v_object/free_busy_generator_test.rb +637 -0
  124. data/test/v_object/google_colon_escaping_test.rb +27 -0
  125. data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
  126. data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
  127. data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
  128. data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
  129. data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
  130. data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
  131. data/test/v_object/i_tip/broker_tester.rb +71 -0
  132. data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
  133. data/test/v_object/i_tip/evolution_test.rb +2644 -0
  134. data/test/v_object/i_tip/message_test.rb +25 -0
  135. data/test/v_object/issue153.vcf +352 -0
  136. data/test/v_object/issue153_test.rb +12 -0
  137. data/test/v_object/issue26_test.rb +25 -0
  138. data/test/v_object/issue36_work_around_test.rb +37 -0
  139. data/test/v_object/issue40_test.rb +26 -0
  140. data/test/v_object/issue64.vcf +351 -0
  141. data/test/v_object/issue64_test.rb +17 -0
  142. data/test/v_object/issue96_test.rb +22 -0
  143. data/test/v_object/issue_undefined_index_test.rb +24 -0
  144. data/test/v_object/j_cal_test.rb +150 -0
  145. data/test/v_object/j_card_test.rb +192 -0
  146. data/test/v_object/line_folding_issue_test.rb +19 -0
  147. data/test/v_object/mock_document.rb +6 -0
  148. data/test/v_object/parameter_test.rb +109 -0
  149. data/test/v_object/parser/json_test.rb +370 -0
  150. data/test/v_object/parser/mime_dir_test.rb +14 -0
  151. data/test/v_object/parser/quoted_printable_test.rb +78 -0
  152. data/test/v_object/parser/xml_test.rb +2563 -0
  153. data/test/v_object/property/binary_test.rb +12 -0
  154. data/test/v_object/property/boolean_test.rb +18 -0
  155. data/test/v_object/property/compound_test.rb +43 -0
  156. data/test/v_object/property/float_test.rb +20 -0
  157. data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
  158. data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
  159. data/test/v_object/property/i_calendar/duration_test.rb +14 -0
  160. data/test/v_object/property/i_calendar/recur_test.rb +39 -0
  161. data/test/v_object/property/text_test.rb +81 -0
  162. data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
  163. data/test/v_object/property/v_card/language_tag_test.rb +35 -0
  164. data/test/v_object/property_test.rb +338 -0
  165. data/test/v_object/reader_test.rb +403 -0
  166. data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
  167. data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
  168. data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
  169. data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
  170. data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
  171. data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
  172. data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
  173. data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
  174. data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
  175. data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
  176. data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
  177. data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
  178. data/test/v_object/recur/r_date_iterator_test.rb +44 -0
  179. data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
  180. data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
  181. data/test/v_object/slash_r_test.rb +15 -0
  182. data/test/v_object/splitter/i_calendar_test.rb +299 -0
  183. data/test/v_object/splitter/v_card_test.rb +173 -0
  184. data/test/v_object/string_util_test.rb +37 -0
  185. data/test/v_object/test_case.rb +42 -0
  186. data/test/v_object/time_zone_util_test.rb +271 -0
  187. data/test/v_object/uuid_util_test.rb +18 -0
  188. data/test/v_object/v_card21_test.rb +43 -0
  189. data/test/v_object/v_card_converter_test.rb +419 -0
  190. data/test/v_object/version_test.rb +15 -0
  191. data/test/v_object/writer_test.rb +33 -0
  192. data/tilia-vobject.gemspec +17 -0
  193. metadata +308 -0
@@ -0,0 +1,460 @@
1
+ require 'test_helper'
2
+ require 'tempfile'
3
+ require 'v_object/cli_mock'
4
+ require 'stringio'
5
+
6
+ module Tilia
7
+ module VObject
8
+ # Tests the cli.
9
+ #
10
+ # Warning: these tests are very rudimentary.
11
+ class CliTest < Minitest::Test
12
+ def setup
13
+ @cli = Tilia::VObject::CliMock.new
14
+ @cli.stderr = StringIO.new
15
+ @cli.stdout = StringIO.new
16
+ end
17
+
18
+ def test_invalid_arg
19
+ assert_equal(1, @cli.main(['--hi']))
20
+ @cli.stderr.rewind
21
+ assert(@cli.stderr.size > 100)
22
+ end
23
+
24
+ def test_quiet
25
+ assert_equal(1, @cli.main(['-q']))
26
+ assert(@cli.quiet)
27
+
28
+ @cli.stderr.rewind
29
+ assert_equal(0, @cli.stderr.size)
30
+ end
31
+
32
+ def test_help
33
+ assert_equal(0, @cli.main(['-h']))
34
+ @cli.stderr.rewind
35
+ assert(@cli.stderr.size > 100)
36
+ end
37
+
38
+ def test_format
39
+ assert_equal(1, @cli.main(['--format=jcard']))
40
+ @cli.stderr.rewind
41
+ assert(@cli.stderr.size > 100)
42
+
43
+ assert_equal('jcard', @cli.format)
44
+ end
45
+
46
+ def test_format_invalid
47
+ assert_equal(1, @cli.main(['--format=foo']))
48
+ @cli.stderr.rewind
49
+ assert(@cli.stderr.size > 100)
50
+ assert_nil(@cli.format)
51
+ end
52
+
53
+ def test_input_format_invalid
54
+ assert_equal(1, @cli.main(['--inputformat=foo']))
55
+ @cli.stderr.rewind
56
+ assert(@cli.stderr.size > 100)
57
+ assert_nil(@cli.format)
58
+ end
59
+
60
+ def test_no_input_file
61
+ assert_equal(1, @cli.main(['color']))
62
+ @cli.stderr.rewind
63
+ assert(@cli.stderr.size > 100)
64
+ end
65
+
66
+ def test_too_many_args
67
+ assert_equal(1, @cli.main(['color', 'a', 'b', 'c']))
68
+ end
69
+
70
+ def test_unknown_command
71
+ assert_equal(1, @cli.main(['foo', '-']))
72
+ end
73
+
74
+ def test_convert_json
75
+ input_stream = StringIO.new
76
+
77
+ input_stream.write(
78
+ <<ICS
79
+ BEGIN:VCARD
80
+ VERSION:3.0
81
+ FN:Cowboy Henk
82
+ END:VCARD
83
+ ICS
84
+ )
85
+ input_stream.rewind
86
+ @cli.stdin = input_stream
87
+
88
+ assert_equal(0, @cli.main(['convert', '--format=json', '-']))
89
+
90
+ @cli.stdout.rewind
91
+ version = Tilia::VObject::Version::VERSION
92
+ assert_equal(
93
+ '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-//Tilia//Tilia VObject ' + version + '//EN"],["fn",{},"text","Cowboy Henk"]]]',
94
+ @cli.stdout.readlines.join('')
95
+ )
96
+ end
97
+
98
+ def test_convert_j_card_pretty
99
+ input_stream = StringIO.new
100
+
101
+ input_stream.write(
102
+ <<ICS
103
+ BEGIN:VCARD
104
+ VERSION:3.0
105
+ FN:Cowboy Henk
106
+ END:VCARD
107
+ ICS
108
+ )
109
+ input_stream.rewind
110
+ @cli.stdin = input_stream
111
+
112
+ assert_equal(0, @cli.main(['convert', '--format=jcard', '--pretty', '-']))
113
+
114
+ @cli.stdout.rewind
115
+
116
+ expected = <<JCARD
117
+ [
118
+ "vcard",
119
+ [
120
+ [
121
+ "version",
122
+ JCARD
123
+
124
+ assert_equal(expected, @cli.stdout.readlines.join('')[0..39])
125
+ end
126
+
127
+ def test_convert_j_cal_fail
128
+ input_stream = StringIO.new
129
+
130
+ input_stream.write(
131
+ <<ICS
132
+ BEGIN:VCARD
133
+ VERSION:3.0
134
+ FN:Cowboy Henk
135
+ END:VCARD
136
+ ICS
137
+ )
138
+ input_stream.rewind
139
+ @cli.stdin = input_stream
140
+
141
+ assert_equal(2, @cli.main(['convert', '--format=jcal', '--inputformat=mimedir', '-']))
142
+ end
143
+
144
+ def test_convert_mime_dir
145
+ input_stream = StringIO.new
146
+
147
+ input_stream.write(
148
+ <<JCARD
149
+ [
150
+ "vcard",
151
+ [
152
+ [
153
+ "version",
154
+ {
155
+
156
+ },
157
+ "text",
158
+ "4.0"
159
+ ],
160
+ [
161
+ "prodid",
162
+ {
163
+
164
+ },
165
+ "text",
166
+ "-//Tilia//Tilia VObject 3.1.0//EN"
167
+ ],
168
+ [
169
+ "fn",
170
+ {
171
+
172
+ },
173
+ "text",
174
+ "Cowboy Henk"
175
+ ]
176
+ ]
177
+ ]
178
+ JCARD
179
+ )
180
+ input_stream.rewind
181
+ @cli.stdin = input_stream
182
+
183
+ assert_equal(0, @cli.main(['convert', '--format=mimedir', '--inputformat=json', '--pretty', '-']))
184
+
185
+ @cli.stdout.rewind
186
+ expected = <<VCF
187
+ BEGIN:VCARD
188
+ VERSION:4.0
189
+ PRODID:-//Tilia//Tilia VObject 3.1.0//EN
190
+ FN:Cowboy Henk
191
+ END:VCARD
192
+ VCF
193
+
194
+ assert_equal(expected, @cli.stdout.readlines.join('').gsub("\r\n", "\n"))
195
+ end
196
+
197
+ def test_convert_default_formats
198
+ output_file = File.join(Dir.tmpdir, 'bar.json')
199
+
200
+ assert_equal(2, @cli.main(['convert', 'foo.json', output_file]))
201
+
202
+ assert_equal('json', @cli.input_format)
203
+ assert_equal('json', @cli.format)
204
+ end
205
+
206
+ def test_convert_default_formats2
207
+ output_file = File.join(Dir.tmpdir, 'bar.ics')
208
+
209
+ assert_equal(2, @cli.main(['convert', 'foo.ics', output_file]))
210
+ assert_equal('mimedir', @cli.input_format)
211
+ assert_equal('mimedir', @cli.format)
212
+ end
213
+
214
+ def test_v_card3040
215
+ input_stream = StringIO.new
216
+
217
+ input_stream.write(
218
+ <<VCF
219
+ BEGIN:VCARD
220
+ VERSION:3.0
221
+ PRODID:-//Tilia//Tilia VObject 3.1.0//EN
222
+ FN:Cowboy Henk
223
+ END:VCARD
224
+ VCF
225
+ )
226
+ input_stream.rewind
227
+ @cli.stdin = input_stream
228
+
229
+ assert_equal(0, @cli.main(['convert', '--format=vcard40', '--pretty', '-']))
230
+
231
+ @cli.stdout.rewind
232
+
233
+ version = Tilia::VObject::Version::VERSION
234
+ expected = <<VCF
235
+ BEGIN:VCARD
236
+ VERSION:4.0
237
+ PRODID:-//Tilia//Tilia VObject #{version}//EN
238
+ FN:Cowboy Henk
239
+ END:VCARD
240
+ VCF
241
+
242
+ assert_equal(expected, @cli.stdout.readlines.join('').gsub("\r\n", "\n"))
243
+ end
244
+
245
+ def test_v_card4030
246
+ input_stream = StringIO.new
247
+
248
+ input_stream.write(
249
+ <<VCF
250
+ BEGIN:VCARD
251
+ VERSION:4.0
252
+ PRODID:-//Tilia//Tilia VObject 3.1.0//EN
253
+ FN:Cowboy Henk
254
+ END:VCARD
255
+ VCF
256
+ )
257
+ input_stream.rewind
258
+ @cli.stdin = input_stream
259
+
260
+ assert_equal(0, @cli.main(['convert', '--format=vcard30', '--pretty', '-']))
261
+
262
+ version = Tilia::VObject::Version::VERSION
263
+
264
+ @cli.stdout.rewind
265
+ expected = <<VCF
266
+ BEGIN:VCARD
267
+ VERSION:3.0
268
+ PRODID:-//Tilia//Tilia VObject #{version}//EN
269
+ FN:Cowboy Henk
270
+ END:VCARD
271
+ VCF
272
+
273
+ assert_equal(expected, @cli.stdout.readlines.join('').gsub("\r\n", "\n"))
274
+ end
275
+
276
+ def test_v_card4021
277
+ input_stream = StringIO.new
278
+
279
+ input_stream.write(
280
+ <<VCF
281
+ BEGIN:VCARD
282
+ VERSION:4.0
283
+ PRODID:-//Tilia//Tilia VObject 3.1.0//EN
284
+ FN:Cowboy Henk
285
+ END:VCARD
286
+ VCF
287
+ )
288
+ input_stream.rewind
289
+ @cli.stdin = input_stream
290
+
291
+ assert_equal(2, @cli.main(['convert', '--format=vcard21', '--pretty', '-']))
292
+ end
293
+
294
+ def test_validate
295
+ input_stream = StringIO.new
296
+
297
+ input_stream.write(
298
+ <<VCF
299
+ BEGIN:VCARD
300
+ VERSION:4.0
301
+ PRODID:-//Tilia//Tilia VObject 3.1.0//EN
302
+ UID:foo
303
+ FN:Cowboy Henk
304
+ END:VCARD
305
+ VCF
306
+ )
307
+ input_stream.rewind
308
+ @cli.stdin = input_stream
309
+ result = @cli.main(['validate', '-'])
310
+
311
+ assert_equal(0, result)
312
+ end
313
+
314
+ def test_validate_fail
315
+ input_stream = StringIO.new
316
+
317
+ input_stream.write(
318
+ <<VCF
319
+ BEGIN:VCALENDAR
320
+ VERSION:2.0
321
+ END:VCARD
322
+ VCF
323
+ )
324
+ input_stream.rewind
325
+ @cli.stdin = input_stream
326
+ # vCard 2.0 is not supported yet, so this returns a failure.
327
+ assert_equal(2, @cli.main(['validate', '-']))
328
+ end
329
+
330
+ def test_validate_fail2
331
+ input_stream = StringIO.new
332
+
333
+ input_stream.write(
334
+ <<VCF
335
+ BEGIN:VCALENDAR
336
+ VERSION:5.0
337
+ END:VCALENDAR
338
+ VCF
339
+ )
340
+ input_stream.rewind
341
+ @cli.stdin = input_stream
342
+ assert_equal(2, @cli.main(['validate', '-']))
343
+ end
344
+
345
+ def test_repair
346
+ input_stream = StringIO.new
347
+
348
+ input_stream.write(
349
+ <<VCF
350
+ BEGIN:VCARD
351
+ VERSION:5.0
352
+ END:VCARD
353
+ VCF
354
+ )
355
+ input_stream.rewind
356
+ @cli.stdin = input_stream
357
+ assert_equal(2, @cli.main(['repair', '-']))
358
+
359
+ @cli.stdout.rewind
360
+ assert(@cli.stdout.readlines.join('') =~ /BEGIN:VCARD\r\nVERSION:2.1\r\nUID:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\r\nEND:VCARD\r\n$/)
361
+ end
362
+
363
+ def test_repair_nothing
364
+ input_stream = StringIO.new
365
+
366
+ input_stream.write(
367
+ <<VCF
368
+ BEGIN:VCALENDAR
369
+ VERSION:2.0
370
+ PRODID:-//Tilia//Tilia VObject 3.1.0//EN
371
+ BEGIN:VEVENT
372
+ UID:foo
373
+ DTSTAMP:20140122T233226Z
374
+ DTSTART:20140101T120000Z
375
+ END:VEVENT
376
+ END:VCALENDAR
377
+ VCF
378
+ )
379
+ input_stream.rewind
380
+ @cli.stdin = input_stream
381
+
382
+ result = @cli.main(['repair', '-'])
383
+
384
+ @cli.stderr.rewind
385
+ error = @cli.stderr.readlines.join('')
386
+
387
+ assert_equal(0, result, "This should have been error free. stderr output:\n#{error}")
388
+ end
389
+
390
+ # Note: this is a very shallow test, doesn't dig into the actual output,
391
+ # but just makes sure there's no errors thrown.
392
+ #
393
+ # The colorizer is not a critical component, it's mostly a debugging tool.
394
+ def test_color_calendar
395
+ input_stream = StringIO.new
396
+
397
+ version = Tilia::VObject::Version::VERSION
398
+
399
+ # This object is not valid, but it's designed to hit every part of the
400
+ # colorizer source.
401
+ input_stream.write(
402
+ <<VCF
403
+ BEGIN:VCALENDAR
404
+ VERSION:2.0
405
+ PRODID:-//Tilia//Tilia VObject #{version}//EN
406
+ BEGIN:VTIMEZONE
407
+ END:VTIMEZONE
408
+ BEGIN:VEVENT
409
+ ATTENDEE;RSVP=TRUE:mailto:foo@example.org
410
+ REQUEST-STATUS:5;foo
411
+ ATTACH:blabla
412
+ END:VEVENT
413
+ END:VCALENDAR
414
+ VCF
415
+ )
416
+ input_stream.rewind
417
+ @cli.stdin = input_stream
418
+
419
+ result = @cli.main(['color', '-'])
420
+
421
+ @cli.stderr.rewind
422
+ error = @cli.stderr.readlines.join('')
423
+
424
+ assert_equal(0, result, "This should have been error free. stderr output:\n#{error}")
425
+ end
426
+
427
+ # Note: this is a very shallow test, doesn't dig into the actual output,
428
+ # but just makes sure there's no errors thrown.
429
+ #
430
+ # The colorizer is not a critical component, it's mostly a debugging tool.
431
+ def test_color_v_card
432
+ input_stream = StringIO.new
433
+
434
+ version = Tilia::VObject::Version::VERSION
435
+
436
+ # This object is not valid, but it's designed to hit every part of the
437
+ # colorizer source.
438
+ input_stream.write(
439
+ <<VCF
440
+ BEGIN:VCARD
441
+ VERSION:4.0
442
+ PRODID:-//Tilia//Tilia VObject #{version}//EN
443
+ ADR:1;2;3;4a,4b;5;6
444
+ group.TEL:123454768
445
+ END:VCARD
446
+ VCF
447
+ )
448
+ input_stream.rewind
449
+ @cli.stdin = input_stream
450
+
451
+ result = @cli.main(['color', '-'])
452
+
453
+ @cli.stderr.rewind
454
+ error = @cli.stderr.readlines.join('')
455
+
456
+ assert_equal(0, result, "This should have been error free. stderr output:\n#{error}")
457
+ end
458
+ end
459
+ end
460
+ end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+
3
+ module Tilia
4
+ module VObject
5
+ class AvailableTest < Minitest::Test
6
+ def test_available_component
7
+ vcal = <<VCAL
8
+ BEGIN:VCALENDAR
9
+ BEGIN:AVAILABLE
10
+ END:AVAILABLE
11
+ END:VCALENDAR
12
+ VCAL
13
+ document = Tilia::VObject::Reader.read(vcal)
14
+ assert_kind_of(Tilia::VObject::Component::Available, document['AVAILABLE'])
15
+ end
16
+
17
+ def test_get_effective_start_end
18
+ vcal = <<VCAL
19
+ BEGIN:VCALENDAR
20
+ BEGIN:AVAILABLE
21
+ DTSTART:20150717T162200Z
22
+ DTEND:20150717T172200Z
23
+ END:AVAILABLE
24
+ END:VCALENDAR
25
+ VCAL
26
+ document = Tilia::VObject::Reader.read(vcal)
27
+ tz = ActiveSupport::TimeZone.new('UTC')
28
+ assert_equal(
29
+ [
30
+ tz.parse('2015-07-17 16:22:00'),
31
+ tz.parse('2015-07-17 17:22:00')
32
+ ],
33
+ document['AVAILABLE'].effective_start_end
34
+ )
35
+ end
36
+
37
+ def test_get_effective_start_end_duration
38
+ vcal = <<VCAL
39
+ BEGIN:VCALENDAR
40
+ BEGIN:AVAILABLE
41
+ DTSTART:20150717T162200Z
42
+ DURATION:PT1H
43
+ END:AVAILABLE
44
+ END:VCALENDAR
45
+ VCAL
46
+
47
+ document = Tilia::VObject::Reader.read(vcal)
48
+ tz = ActiveSupport::TimeZone.new('UTC')
49
+ assert_equal(
50
+ [
51
+ tz.parse('2015-07-17 16:22:00'),
52
+ tz.parse('2015-07-17 17:22:00')
53
+ ],
54
+ document['AVAILABLE'].effective_start_end
55
+ )
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,160 @@
1
+ require 'test_helper'
2
+
3
+ module Tilia
4
+ module VObject
5
+ class VAlarmTest < Minitest::Test
6
+ def time_range_test_data
7
+ tests = []
8
+
9
+ calendar = Tilia::VObject::Component::VCalendar.new
10
+
11
+ # Hard date and time
12
+ valarm1 = calendar.create_component('VALARM')
13
+ valarm1.add(
14
+ calendar.create_property('TRIGGER', '20120312T130000Z', 'VALUE' => 'DATE-TIME')
15
+ )
16
+
17
+ tests << [valarm1, Time.zone.parse('2012-03-01 01:00:00'), Time.zone.parse('2012-04-01 01:00:00'), true]
18
+ tests << [valarm1, Time.zone.parse('2012-03-01 01:00:00'), Time.zone.parse('2012-03-10 01:00:00'), false]
19
+
20
+ # Relation to start time of event
21
+ valarm2 = calendar.create_component('VALARM')
22
+ valarm2.add(
23
+ calendar.create_property('TRIGGER', '-P1D', 'VALUE' => 'DURATION')
24
+ )
25
+
26
+ vevent2 = calendar.create_component('VEVENT')
27
+ vevent2['DTSTART'] = '20120313T130000Z'
28
+ vevent2.add(valarm2)
29
+
30
+ tests << [valarm2, Time.zone.parse('2012-03-01 01:00:00'), Time.zone.parse('2012-04-01 01:00:00'), true]
31
+ tests << [valarm2, Time.zone.parse('2012-03-01 01:00:00'), Time.zone.parse('2012-03-10 01:00:00'), false]
32
+
33
+ # Relation to end time of event
34
+ valarm3 = calendar.create_component('VALARM')
35
+ valarm3.add(calendar.create_property('TRIGGER', '-P1D', 'VALUE' => 'DURATION', 'RELATED' => 'END'))
36
+
37
+ vevent3 = calendar.create_component('VEVENT')
38
+ vevent3['DTSTART'] = '20120301T130000Z'
39
+ vevent3['DTEND'] = '20120401T130000Z'
40
+ vevent3.add(valarm3)
41
+
42
+ tests << [valarm3, Time.zone.parse('2012-02-25 01:00:00'), Time.zone.parse('2012-03-05 01:00:00'), false]
43
+ tests << [valarm3, Time.zone.parse('2012-03-25 01:00:00'), Time.zone.parse('2012-04-05 01:00:00'), true]
44
+
45
+ # Relation to end time of todo
46
+ valarm4 = calendar.create_component('VALARM')
47
+ valarm4['TRIGGER'] = '-P1D'
48
+ valarm4['TRIGGER']['VALUE'] = 'DURATION'
49
+ valarm4['TRIGGER']['RELATED'] = 'END'
50
+
51
+ vtodo4 = calendar.create_component('VTODO')
52
+ vtodo4['DTSTART'] = '20120301T130000Z'
53
+ vtodo4['DUE'] = '20120401T130000Z'
54
+ vtodo4.add(valarm4)
55
+
56
+ tests << [valarm4, Time.zone.parse('2012-02-25 01:00:00'), Time.zone.parse('2012-03-05 01:00:00'), false]
57
+ tests << [valarm4, Time.zone.parse('2012-03-25 01:00:00'), Time.zone.parse('2012-04-05 01:00:00'), true]
58
+
59
+ # Relation to start time of event + repeat
60
+ valarm5 = calendar.create_component('VALARM')
61
+ valarm5['TRIGGER'] = '-P1D'
62
+ valarm5['TRIGGER']['VALUE'] = 'DURATION'
63
+ valarm5['REPEAT'] = 10
64
+ valarm5['DURATION'] = 'P1D'
65
+
66
+ vevent5 = calendar.create_component('VEVENT')
67
+ vevent5['DTSTART'] = '20120301T130000Z'
68
+ vevent5.add(valarm5)
69
+
70
+ tests << [valarm5, Time.zone.parse('2012-03-09 01:00:00'), Time.zone.parse('2012-03-10 01:00:00'), true]
71
+
72
+ # Relation to start time of event + duration, but no repeat
73
+ valarm6 = calendar.create_component('VALARM')
74
+ valarm6['TRIGGER'] = '-P1D'
75
+ valarm6['TRIGGER']['VALUE'] = 'DURATION'
76
+ valarm6['DURATION'] = 'P1D'
77
+
78
+ vevent6 = calendar.create_component('VEVENT')
79
+ vevent6['DTSTART'] = '20120313T130000Z'
80
+ vevent6.add(valarm6)
81
+
82
+ tests << [valarm6, Time.zone.parse('2012-03-01 01:00:00'), Time.zone.parse('2012-04-01 01:00:00'), true]
83
+ tests << [valarm6, Time.zone.parse('2012-03-01 01:00:00'), Time.zone.parse('2012-03-10 01:00:00'), false]
84
+
85
+ # Relation to end time of event (DURATION instead of DTEND)
86
+ valarm7 = calendar.create_component('VALARM')
87
+ valarm7['TRIGGER'] = '-P1D'
88
+ valarm7['TRIGGER']['VALUE'] = 'DURATION'
89
+ valarm7['TRIGGER']['RELATED'] = 'END'
90
+
91
+ vevent7 = calendar.create_component('VEVENT')
92
+ vevent7['DTSTART'] = '20120301T130000Z'
93
+ vevent7['DURATION'] = 'P30D'
94
+ vevent7.add(valarm7)
95
+
96
+ tests << [valarm7, Time.zone.parse('2012-02-25 01:00:00'), Time.zone.parse('2012-03-05 01:00:00'), false]
97
+ tests << [valarm7, Time.zone.parse('2012-03-25 01:00:00'), Time.zone.parse('2012-04-05 01:00:00'), true]
98
+
99
+ # Relation to end time of event (No DTEND or DURATION)
100
+ valarm7 = calendar.create_component('VALARM')
101
+ valarm7['TRIGGER'] = '-P1D'
102
+ valarm7['TRIGGER']['VALUE'] = 'DURATION'
103
+ valarm7['TRIGGER']['RELATED'] = 'END'
104
+
105
+ vevent7 = calendar.create_component('VEVENT')
106
+ vevent7['DTSTART'] = '20120301T130000Z'
107
+ vevent7.add(valarm7)
108
+
109
+ tests << [valarm7, Time.zone.parse('2012-02-25 01:00:00'), Time.zone.parse('2012-03-05 01:00:00'), true]
110
+ tests << [valarm7, Time.zone.parse('2012-03-25 01:00:00'), Time.zone.parse('2012-04-05 01:00:00'), false]
111
+
112
+ tests
113
+ end
114
+
115
+ def test_in_time_range
116
+ time_range_test_data.each do |data|
117
+ (valarm, start, ending, outcome) = data
118
+ assert_equal(outcome, valarm.in_time_range?(start, ending))
119
+ end
120
+ end
121
+
122
+ def test_in_time_range_invalid_component
123
+ calendar = Tilia::VObject::Component::VCalendar.new
124
+ valarm = calendar.create_component('VALARM')
125
+ valarm['TRIGGER'] = '-P1D'
126
+ valarm['TRIGGER']['RELATED'] = 'END'
127
+
128
+ vjournal = calendar.create_component('VJOURNAL')
129
+ vjournal.add(valarm)
130
+
131
+ assert_raises(RuntimeError) { valarm.in_time_range?(Time.zone.parse('2012-02-25 01:00:00'), Time.zone.parse('2012-03-05 01:00:00')) }
132
+ end
133
+
134
+ # This bug was found and reported on the mailing list.
135
+ def test_in_time_range_buggy
136
+ input = <<BLA
137
+ BEGIN:VCALENDAR
138
+ BEGIN:VTODO
139
+ DTSTAMP:20121003T064931Z
140
+ UID:b848cb9a7bb16e464a06c222ca1f8102@examle.com
141
+ STATUS:NEEDS-ACTION
142
+ DUE:20121005T000000Z
143
+ SUMMARY:Task 1
144
+ CATEGORIES:AlarmCategory
145
+ BEGIN:VALARM
146
+ TRIGGER:-PT10M
147
+ ACTION:DISPLAY
148
+ DESCRIPTION:Task 1
149
+ END:VALARM
150
+ END:VTODO
151
+ END:VCALENDAR
152
+ BLA
153
+
154
+ vobj = Tilia::VObject::Reader.read(input)
155
+
156
+ assert(vobj['VTODO']['VALARM'].in_time_range?(Time.zone.parse('2012-10-01 00:00:00'), Time.zone.parse('2012-11-01 00:00:00')))
157
+ end
158
+ end
159
+ end
160
+ end