tilia-vobject 4.0.0.pre.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rubocop.yml +32 -0
- data/.simplecov +4 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.sabre.md +626 -0
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +27 -0
- data/LICENSE.sabre +27 -0
- data/README.md +63 -0
- data/Rakefile +17 -0
- data/bin/vobject +7 -0
- data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
- data/lib/tilia/v_object/cli.rb +582 -0
- data/lib/tilia/v_object/component/available.rb +107 -0
- data/lib/tilia/v_object/component/v_alarm.rb +114 -0
- data/lib/tilia/v_object/component/v_availability.rb +128 -0
- data/lib/tilia/v_object/component/v_calendar.rb +468 -0
- data/lib/tilia/v_object/component/v_card.rb +457 -0
- data/lib/tilia/v_object/component/v_event.rb +127 -0
- data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
- data/lib/tilia/v_object/component/v_journal.rb +75 -0
- data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
- data/lib/tilia/v_object/component/v_todo.rb +147 -0
- data/lib/tilia/v_object/component.rb +591 -0
- data/lib/tilia/v_object/date_time_parser.rb +486 -0
- data/lib/tilia/v_object/document.rb +218 -0
- data/lib/tilia/v_object/element_list.rb +18 -0
- data/lib/tilia/v_object/eof_exception.rb +8 -0
- data/lib/tilia/v_object/free_busy_data.rb +149 -0
- data/lib/tilia/v_object/free_busy_generator.rb +465 -0
- data/lib/tilia/v_object/i_tip/broker.rb +909 -0
- data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
- data/lib/tilia/v_object/i_tip/message.rb +109 -0
- data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
- data/lib/tilia/v_object/i_tip.rb +10 -0
- data/lib/tilia/v_object/node.rb +192 -0
- data/lib/tilia/v_object/parameter.rb +327 -0
- data/lib/tilia/v_object/parse_exception.rb +7 -0
- data/lib/tilia/v_object/parser/json.rb +149 -0
- data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
- data/lib/tilia/v_object/parser/parser.rb +61 -0
- data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
- data/lib/tilia/v_object/parser/xml/element.rb +11 -0
- data/lib/tilia/v_object/parser/xml.rb +322 -0
- data/lib/tilia/v_object/parser.rb +10 -0
- data/lib/tilia/v_object/property/binary.rb +96 -0
- data/lib/tilia/v_object/property/boolean.rb +57 -0
- data/lib/tilia/v_object/property/flat_text.rb +52 -0
- data/lib/tilia/v_object/property/float_value.rb +107 -0
- data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
- data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
- data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
- data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
- data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
- data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
- data/lib/tilia/v_object/property/i_calendar.rb +14 -0
- data/lib/tilia/v_object/property/integer_value.rb +60 -0
- data/lib/tilia/v_object/property/text.rb +352 -0
- data/lib/tilia/v_object/property/time.rb +85 -0
- data/lib/tilia/v_object/property/unknown.rb +30 -0
- data/lib/tilia/v_object/property/uri.rb +78 -0
- data/lib/tilia/v_object/property/utc_offset.rb +56 -0
- data/lib/tilia/v_object/property/v_card/date.rb +31 -0
- data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
- data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
- data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
- data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
- data/lib/tilia/v_object/property/v_card.rb +13 -0
- data/lib/tilia/v_object/property.rb +532 -0
- data/lib/tilia/v_object/reader.rb +73 -0
- data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
- data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
- data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
- data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
- data/lib/tilia/v_object/recur.rb +10 -0
- data/lib/tilia/v_object/settings.rb +32 -0
- data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
- data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
- data/lib/tilia/v_object/splitter/v_card.rb +56 -0
- data/lib/tilia/v_object/splitter.rb +9 -0
- data/lib/tilia/v_object/string_util.rb +58 -0
- data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
- data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
- data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
- data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
- data/lib/tilia/v_object/time_zone_data.rb +10 -0
- data/lib/tilia/v_object/time_zone_util.rb +213 -0
- data/lib/tilia/v_object/uuid_util.rb +51 -0
- data/lib/tilia/v_object/v_card_converter.rb +354 -0
- data/lib/tilia/v_object/version.rb +9 -0
- data/lib/tilia/v_object/writer.rb +56 -0
- data/lib/tilia/v_object.rb +45 -0
- data/lib/tilia/vobject.rb +1 -0
- data/resources/schema/xcal.rng +1192 -0
- data/resources/schema/xcard.rng +388 -0
- data/test/test_helper.rb +56 -0
- data/test/v_object/attach_issue_test.rb +19 -0
- data/test/v_object/birthday_calendar_generator_test.rb +463 -0
- data/test/v_object/cli_mock.rb +19 -0
- data/test/v_object/cli_test.rb +460 -0
- data/test/v_object/component/available_test.rb +59 -0
- data/test/v_object/component/v_alarm_test.rb +160 -0
- data/test/v_object/component/v_availability_test.rb +388 -0
- data/test/v_object/component/v_calendar_test.rb +646 -0
- data/test/v_object/component/v_card_test.rb +258 -0
- data/test/v_object/component/v_event_test.rb +85 -0
- data/test/v_object/component/v_free_busy_test.rb +59 -0
- data/test/v_object/component/v_journal_test.rb +85 -0
- data/test/v_object/component/v_time_zone_test.rb +47 -0
- data/test/v_object/component/v_todo_test.rb +172 -0
- data/test/v_object/component_test.rb +419 -0
- data/test/v_object/date_time_parser_test.rb +526 -0
- data/test/v_object/document_test.rb +71 -0
- data/test/v_object/element_list_test.rb +27 -0
- data/test/v_object/em_client_test.rb +53 -0
- data/test/v_object/empty_parameter_test.rb +65 -0
- data/test/v_object/empty_value_issue_test.rb +25 -0
- data/test/v_object/fake_component.rb +21 -0
- data/test/v_object/free_busy_data_test.rb +285 -0
- data/test/v_object/free_busy_generator_test.rb +637 -0
- data/test/v_object/google_colon_escaping_test.rb +27 -0
- data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
- data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
- data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
- data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
- data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
- data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
- data/test/v_object/i_tip/broker_tester.rb +71 -0
- data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
- data/test/v_object/i_tip/evolution_test.rb +2644 -0
- data/test/v_object/i_tip/message_test.rb +25 -0
- data/test/v_object/issue153.vcf +352 -0
- data/test/v_object/issue153_test.rb +12 -0
- data/test/v_object/issue26_test.rb +25 -0
- data/test/v_object/issue36_work_around_test.rb +37 -0
- data/test/v_object/issue40_test.rb +26 -0
- data/test/v_object/issue64.vcf +351 -0
- data/test/v_object/issue64_test.rb +17 -0
- data/test/v_object/issue96_test.rb +22 -0
- data/test/v_object/issue_undefined_index_test.rb +24 -0
- data/test/v_object/j_cal_test.rb +150 -0
- data/test/v_object/j_card_test.rb +192 -0
- data/test/v_object/line_folding_issue_test.rb +19 -0
- data/test/v_object/mock_document.rb +6 -0
- data/test/v_object/parameter_test.rb +109 -0
- data/test/v_object/parser/json_test.rb +370 -0
- data/test/v_object/parser/mime_dir_test.rb +14 -0
- data/test/v_object/parser/quoted_printable_test.rb +78 -0
- data/test/v_object/parser/xml_test.rb +2563 -0
- data/test/v_object/property/binary_test.rb +12 -0
- data/test/v_object/property/boolean_test.rb +18 -0
- data/test/v_object/property/compound_test.rb +43 -0
- data/test/v_object/property/float_test.rb +20 -0
- data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
- data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
- data/test/v_object/property/i_calendar/duration_test.rb +14 -0
- data/test/v_object/property/i_calendar/recur_test.rb +39 -0
- data/test/v_object/property/text_test.rb +81 -0
- data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
- data/test/v_object/property/v_card/language_tag_test.rb +35 -0
- data/test/v_object/property_test.rb +338 -0
- data/test/v_object/reader_test.rb +403 -0
- data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
- data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
- data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
- data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
- data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
- data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
- data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
- data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
- data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
- data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
- data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
- data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
- data/test/v_object/recur/r_date_iterator_test.rb +44 -0
- data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
- data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
- data/test/v_object/slash_r_test.rb +15 -0
- data/test/v_object/splitter/i_calendar_test.rb +299 -0
- data/test/v_object/splitter/v_card_test.rb +173 -0
- data/test/v_object/string_util_test.rb +37 -0
- data/test/v_object/test_case.rb +42 -0
- data/test/v_object/time_zone_util_test.rb +271 -0
- data/test/v_object/uuid_util_test.rb +18 -0
- data/test/v_object/v_card21_test.rb +43 -0
- data/test/v_object/v_card_converter_test.rb +419 -0
- data/test/v_object/version_test.rb +15 -0
- data/test/v_object/writer_test.rb +33 -0
- data/tilia-vobject.gemspec +17 -0
- metadata +308 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class BooleanTest < Minitest::Test
|
6
|
+
def test_mime_dir
|
7
|
+
input = "BEGIN:VCARD\r\nX-AWESOME;VALUE=BOOLEAN:TRUE\r\nX-SUCKS;VALUE=BOOLEAN:FALSE\r\nEND:VCARD\r\n"
|
8
|
+
|
9
|
+
vcard = Tilia::VObject::Reader.read(input)
|
10
|
+
assert(vcard['X-AWESOME'].value)
|
11
|
+
refute(vcard['X-SUCKS'].value)
|
12
|
+
|
13
|
+
assert_equal('BOOLEAN', vcard['X-AWESOME'].value_type)
|
14
|
+
assert_equal(input, vcard.serialize)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class CompoundTest < Minitest::Test
|
6
|
+
def test_set_parts
|
7
|
+
arr = [
|
8
|
+
'ABC, Inc.',
|
9
|
+
'North American Division',
|
10
|
+
'Marketing;Sales'
|
11
|
+
]
|
12
|
+
|
13
|
+
vcard = Tilia::VObject::Component::VCard.new
|
14
|
+
elem = vcard.create_property('ORG')
|
15
|
+
elem.parts = arr
|
16
|
+
|
17
|
+
assert_equal('ABC\, Inc.;North American Division;Marketing\;Sales', elem.value)
|
18
|
+
assert_equal(3, elem.parts.size)
|
19
|
+
parts = elem.parts
|
20
|
+
assert_equal('Marketing;Sales', parts[2])
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_get_parts
|
24
|
+
str = 'ABC\\, Inc.;North American Division;Marketing\\;Sales'
|
25
|
+
|
26
|
+
vcard = Tilia::VObject::Component::VCard.new
|
27
|
+
elem = vcard.create_property('ORG')
|
28
|
+
elem.raw_mime_dir_value = str
|
29
|
+
|
30
|
+
assert_equal(3, elem.parts.size)
|
31
|
+
parts = elem.parts
|
32
|
+
assert_equal('Marketing;Sales', parts[2])
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_get_parts_null
|
36
|
+
vcard = Tilia::VObject::Component::VCard.new
|
37
|
+
elem = vcard.create_property('ORG', nil)
|
38
|
+
|
39
|
+
assert_equal(0, elem.parts.size)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class FloatTest < Minitest::Test
|
6
|
+
def test_mime_dir
|
7
|
+
input = "BEGIN:VCARD\r\nVERSION:4.0\r\nX-FLOAT;VALUE=FLOAT:0.234;1.245\r\nEND:VCARD\r\n"
|
8
|
+
mime_dir = Tilia::VObject::Parser::MimeDir.new(input)
|
9
|
+
|
10
|
+
result = mime_dir.parse(input)
|
11
|
+
|
12
|
+
assert_kind_of(Tilia::VObject::Property::FloatValue, result['X-FLOAT'])
|
13
|
+
|
14
|
+
assert_equal([0.234, 1.245], result['X-FLOAT'].parts)
|
15
|
+
|
16
|
+
assert_equal(input, result.serialize)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class CalAddressTest < Minitest::Test
|
6
|
+
def values
|
7
|
+
[
|
8
|
+
['mailto:a@b.com', 'mailto:a@b.com'],
|
9
|
+
['mailto:a@b.com', 'MAILTO:a@b.com'],
|
10
|
+
['/foo/bar', '/foo/bar']
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_normalized_value
|
15
|
+
values.each do |data|
|
16
|
+
(expected, input) = data
|
17
|
+
|
18
|
+
vobj = Tilia::VObject::Component::VCalendar.new
|
19
|
+
property = vobj.add('ATTENDEE', input)
|
20
|
+
|
21
|
+
assert_equal(expected, property.normalized_value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,303 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class DateTimeTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@vcal = Tilia::VObject::Component::VCalendar.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_set_date_time
|
11
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
12
|
+
dt = tz.parse('1985-07-04 01:30:00')
|
13
|
+
|
14
|
+
elem = @vcal.create_property('DTSTART')
|
15
|
+
elem.date_time = dt
|
16
|
+
|
17
|
+
assert_equal('19850704T013000', elem.to_s)
|
18
|
+
assert_equal('Europe/Amsterdam', elem['TZID'].to_s)
|
19
|
+
assert_nil(elem['VALUE'])
|
20
|
+
|
21
|
+
assert(elem.time?)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_set_date_time_local
|
25
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
26
|
+
dt = tz.parse('1985-07-04 01:30:00')
|
27
|
+
|
28
|
+
elem = @vcal.create_property('DTSTART')
|
29
|
+
elem.date_time = dt
|
30
|
+
elem.floating = true
|
31
|
+
|
32
|
+
assert_equal('19850704T013000', elem.to_s)
|
33
|
+
assert_nil(elem['TZID'])
|
34
|
+
|
35
|
+
assert(elem.time?)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_set_date_time_utc
|
39
|
+
tz = ActiveSupport::TimeZone.new('GMT')
|
40
|
+
dt = tz.parse('1985-07-04 01:30:00')
|
41
|
+
|
42
|
+
elem = @vcal.create_property('DTSTART')
|
43
|
+
elem.date_time = dt
|
44
|
+
|
45
|
+
assert_equal('19850704T013000Z', elem.to_s)
|
46
|
+
assert_nil(elem['TZID'])
|
47
|
+
|
48
|
+
assert(elem.time?)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_set_date_time_from_unix_timestamp
|
52
|
+
# When initialized from a Unix timestamp, the timezone is set to "+00:00".
|
53
|
+
tz = ActiveSupport::TimeZone.new('GMT')
|
54
|
+
dt = tz.at(489_288_600)
|
55
|
+
|
56
|
+
elem = @vcal.create_property('DTSTART')
|
57
|
+
elem.date_time = dt
|
58
|
+
|
59
|
+
assert_equal('19850704T013000Z', elem.to_s)
|
60
|
+
assert_nil(elem['TZID'])
|
61
|
+
|
62
|
+
assert(elem.time?)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_set_date_time_localtz
|
66
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
67
|
+
dt = tz.parse('1985-07-04 01:30:00')
|
68
|
+
|
69
|
+
elem = @vcal.create_property('DTSTART')
|
70
|
+
elem.date_time = dt
|
71
|
+
|
72
|
+
assert_equal('19850704T013000', elem.to_s)
|
73
|
+
assert_equal('Europe/Amsterdam', elem['TZID'].to_s)
|
74
|
+
|
75
|
+
assert(elem.time?)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_set_date_time_date
|
79
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
80
|
+
dt = tz.parse('1985-07-04 01:30:00')
|
81
|
+
|
82
|
+
elem = @vcal.create_property('DTSTART')
|
83
|
+
elem['VALUE'] = 'DATE'
|
84
|
+
elem.date_time = dt
|
85
|
+
|
86
|
+
assert_equal('19850704', elem.to_s)
|
87
|
+
assert_nil(elem['TZID'])
|
88
|
+
assert_equal('DATE', elem['VALUE'].to_s)
|
89
|
+
|
90
|
+
refute(elem.time?)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_set_value
|
94
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
95
|
+
dt = tz.parse('1985-07-04 01:30:00')
|
96
|
+
|
97
|
+
elem = @vcal.create_property('DTSTART')
|
98
|
+
elem.value = dt
|
99
|
+
|
100
|
+
assert_equal('19850704T013000', elem.to_s)
|
101
|
+
assert_equal('Europe/Amsterdam', elem['TZID'].to_s)
|
102
|
+
assert_nil(elem['VALUE'])
|
103
|
+
|
104
|
+
assert(elem.time?)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_set_value_array
|
108
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
109
|
+
dt1 = tz.parse('1985-07-04 01:30:00')
|
110
|
+
dt2 = tz.parse('1985-07-04 02:30:00')
|
111
|
+
|
112
|
+
elem = @vcal.create_property('DTSTART')
|
113
|
+
elem.value = [dt1, dt2]
|
114
|
+
|
115
|
+
assert_equal('19850704T013000,19850704T023000', elem.to_s)
|
116
|
+
assert_equal('Europe/Amsterdam', elem['TZID'].to_s)
|
117
|
+
assert_nil(elem['VALUE'])
|
118
|
+
|
119
|
+
assert(elem.time?)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_set_parts
|
123
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
124
|
+
dt1 = tz.parse('1985-07-04 01:30:00')
|
125
|
+
dt2 = tz.parse('1985-07-04 02:30:00')
|
126
|
+
|
127
|
+
elem = @vcal.create_property('DTSTART')
|
128
|
+
elem.parts = [dt1, dt2]
|
129
|
+
|
130
|
+
assert_equal('19850704T013000,19850704T023000', elem.to_s)
|
131
|
+
assert_equal('Europe/Amsterdam', elem['TZID'].to_s)
|
132
|
+
assert_nil(elem['VALUE'])
|
133
|
+
|
134
|
+
assert(elem.time?)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_set_parts_strings
|
138
|
+
dt1 = '19850704T013000Z'
|
139
|
+
dt2 = '19850704T023000Z'
|
140
|
+
|
141
|
+
elem = @vcal.create_property('DTSTART')
|
142
|
+
elem.parts = [dt1, dt2]
|
143
|
+
|
144
|
+
assert_equal('19850704T013000Z,19850704T023000Z', elem.to_s)
|
145
|
+
assert_nil(elem['VALUE'])
|
146
|
+
|
147
|
+
assert(elem.time?)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_get_date_time_cached
|
151
|
+
tz = ActiveSupport::TimeZone.new('Europe/Amsterdam')
|
152
|
+
dt = tz.parse('1985-07-04 01:30:00')
|
153
|
+
|
154
|
+
elem = @vcal.create_property('DTSTART')
|
155
|
+
elem.date_time = dt
|
156
|
+
|
157
|
+
assert_equal(elem.date_time, dt)
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_get_date_time_date_null
|
161
|
+
elem = @vcal.create_property('DTSTART')
|
162
|
+
dt = elem.date_time
|
163
|
+
|
164
|
+
assert_nil(dt)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_get_date_time_date_date
|
168
|
+
elem = @vcal.create_property('DTSTART', '19850704')
|
169
|
+
dt = elem.date_time
|
170
|
+
|
171
|
+
assert_kind_of(::Time, dt)
|
172
|
+
assert_equal('1985-07-04 00:00:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_get_date_time_date_date_reference_time_zone
|
176
|
+
elem = @vcal.create_property('DTSTART', '19850704')
|
177
|
+
|
178
|
+
tz = ActiveSupport::TimeZone.new('America/Toronto')
|
179
|
+
dt = elem.date_time(tz)
|
180
|
+
dt = dt.in_time_zone(ActiveSupport::TimeZone.new('UTC'))
|
181
|
+
|
182
|
+
assert_kind_of(::Time, dt)
|
183
|
+
assert_equal('1985-07-04 04:00:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_get_date_time_date_floating
|
187
|
+
elem = @vcal.create_property('DTSTART', '19850704T013000')
|
188
|
+
dt = elem.date_time
|
189
|
+
|
190
|
+
assert_kind_of(::Time, dt)
|
191
|
+
assert_equal('1985-07-04 01:30:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_get_date_time_date_floating_reference_time_zone
|
195
|
+
elem = @vcal.create_property('DTSTART', '19850704T013000')
|
196
|
+
|
197
|
+
tz = ActiveSupport::TimeZone.new('America/Toronto')
|
198
|
+
dt = elem.date_time(tz)
|
199
|
+
dt = dt.in_time_zone(ActiveSupport::TimeZone.new('UTC'))
|
200
|
+
|
201
|
+
assert_kind_of(::Time, dt)
|
202
|
+
assert_equal('1985-07-04 05:30:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_get_date_time_date_utc
|
206
|
+
elem = @vcal.create_property('DTSTART', '19850704T013000Z')
|
207
|
+
dt = elem.date_time
|
208
|
+
|
209
|
+
assert_kind_of(::Time, dt)
|
210
|
+
assert_equal('1985-07-04 01:30:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
211
|
+
assert_equal('UTC', dt.time_zone.name)
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_get_date_time_date_localtz
|
215
|
+
elem = @vcal.create_property('DTSTART', '19850704T013000')
|
216
|
+
elem['TZID'] = 'Europe/Amsterdam'
|
217
|
+
|
218
|
+
dt = elem.date_time
|
219
|
+
|
220
|
+
assert_kind_of(::Time, dt)
|
221
|
+
assert_equal('1985-07-04 01:30:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
222
|
+
assert_equal('Europe/Amsterdam', dt.time_zone.name)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_get_date_time_date_invalid
|
226
|
+
elem = @vcal.create_property('DTSTART', 'bla')
|
227
|
+
assert_raises(RuntimeError) { elem.date_time }
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_get_date_time_weird_tz
|
231
|
+
elem = @vcal.create_property('DTSTART', '19850704T013000')
|
232
|
+
elem['TZID'] = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'
|
233
|
+
|
234
|
+
event = @vcal.create_component('VEVENT')
|
235
|
+
event.add(elem)
|
236
|
+
|
237
|
+
timezone = @vcal.create_component('VTIMEZONE')
|
238
|
+
timezone['TZID'] = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'
|
239
|
+
timezone['X-LIC-LOCATION'] = 'Europe/Amsterdam'
|
240
|
+
|
241
|
+
@vcal.add(event)
|
242
|
+
@vcal.add(timezone)
|
243
|
+
|
244
|
+
dt = elem.date_time
|
245
|
+
|
246
|
+
assert_kind_of(::Time, dt)
|
247
|
+
assert_equal('1985-07-04 01:30:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
248
|
+
assert_equal('Europe/Amsterdam', dt.time_zone.name)
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_get_date_time_bad_time_zone
|
252
|
+
Time.use_zone('Canada/Eastern') do
|
253
|
+
elem = @vcal.create_property('DTSTART', '19850704T013000')
|
254
|
+
elem['TZID'] = 'Moon'
|
255
|
+
|
256
|
+
event = @vcal.create_component('VEVENT')
|
257
|
+
event.add(elem)
|
258
|
+
|
259
|
+
timezone = @vcal.create_component('VTIMEZONE')
|
260
|
+
timezone['TZID'] = 'Moon'
|
261
|
+
timezone['X-LIC-LOCATION'] = 'Moon'
|
262
|
+
|
263
|
+
@vcal.add(event)
|
264
|
+
@vcal.add(timezone)
|
265
|
+
|
266
|
+
dt = elem.date_time
|
267
|
+
|
268
|
+
assert_kind_of(::Time, dt)
|
269
|
+
assert_equal('1985-07-04 01:30:00', dt.strftime('%Y-%m-%d %H:%M:%S'))
|
270
|
+
assert_equal('Canada/Eastern', dt.time_zone.name)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_update_value_parameter
|
275
|
+
dt_start = @vcal.create_property('DTSTART', Time.zone.parse('2013-06-07 15:05:00'))
|
276
|
+
dt_start['VALUE'] = 'DATE'
|
277
|
+
|
278
|
+
assert_equal("DTSTART;VALUE=DATE:20130607\r\n", dt_start.serialize)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_validate
|
282
|
+
ex_date = @vcal.create_property('EXDATE', '-00011130T143000Z')
|
283
|
+
messages = ex_date.validate
|
284
|
+
assert_equal(1, messages.size)
|
285
|
+
assert_equal(3, messages[0]['level'])
|
286
|
+
end
|
287
|
+
|
288
|
+
# This issue was discovered on the sabredav mailing list.
|
289
|
+
def test_create_date_property_through_add
|
290
|
+
vcal = Tilia::VObject::Component::VCalendar.new
|
291
|
+
vevent = vcal.add('VEVENT')
|
292
|
+
|
293
|
+
dtstart = vevent.add(
|
294
|
+
'DTSTART',
|
295
|
+
Time.zone.parse('2014-03-07'),
|
296
|
+
'VALUE' => 'DATE'
|
297
|
+
)
|
298
|
+
|
299
|
+
assert_equal("DTSTART;VALUE=DATE:20140307\r\n", dtstart.serialize)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class DurationTest < Minitest::Test
|
6
|
+
def test_get_date_interval
|
7
|
+
vcal = Tilia::VObject::Component::VCalendar.new
|
8
|
+
event = vcal.add('VEVENT', 'DURATION' => ['PT1H'])
|
9
|
+
|
10
|
+
assert_equal(1.hour, event['DURATION'].date_interval)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class RecurTest < Minitest::Test
|
6
|
+
def test_parts
|
7
|
+
vcal = Tilia::VObject::Component::VCalendar.new
|
8
|
+
recur = vcal.add('RRULE', 'FREQ=Daily')
|
9
|
+
|
10
|
+
assert_kind_of(Tilia::VObject::Property::ICalendar::Recur, recur)
|
11
|
+
|
12
|
+
assert_equal({ 'FREQ' => 'DAILY' }, recur.parts)
|
13
|
+
recur.parts = { 'freq' => 'MONTHLY' }
|
14
|
+
|
15
|
+
assert_equal({ 'FREQ' => 'MONTHLY' }, recur.parts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_set_value_bad_val
|
19
|
+
vcal = Tilia::VObject::Component::VCalendar.new
|
20
|
+
recur = vcal.add('RRULE', 'FREQ=Daily')
|
21
|
+
assert_raises(ArgumentError) { recur.value = Exception.new }
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_set_sub_parts
|
25
|
+
vcal = Tilia::VObject::Component::VCalendar.new
|
26
|
+
recur = vcal.add('RRULE', 'FREQ' => 'DAILY', 'BYDAY' => 'mo,tu', 'BYMONTH' => [0, 1])
|
27
|
+
|
28
|
+
assert_equal(
|
29
|
+
{
|
30
|
+
'FREQ' => 'DAILY',
|
31
|
+
'BYDAY' => ['MO', 'TU'],
|
32
|
+
'BYMONTH' => [0, 1]
|
33
|
+
},
|
34
|
+
recur.parts
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Tilia
|
4
|
+
module VObject
|
5
|
+
class CalAddressTest < Minitest::Test
|
6
|
+
def assert_v_card21_serialization(prop_value, expected)
|
7
|
+
doc = Tilia::VObject::Component::VCard.new(
|
8
|
+
{
|
9
|
+
'VERSION' => '2.1',
|
10
|
+
'PROP' => prop_value
|
11
|
+
},
|
12
|
+
false
|
13
|
+
)
|
14
|
+
|
15
|
+
# Adding quoted-printable, because we're testing if it gets removed
|
16
|
+
# automatically.
|
17
|
+
doc['PROP']['ENCODING'] = 'QUOTED-PRINTABLE'
|
18
|
+
doc['PROP']['P1'] = 'V1'
|
19
|
+
|
20
|
+
output = doc.serialize
|
21
|
+
|
22
|
+
assert_equal("BEGIN:VCARD\r\nVERSION:2.1\r\n#{expected}\r\nEND:VCARD\r\n", output)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_serialize_v_card21
|
26
|
+
assert_v_card21_serialization(
|
27
|
+
'f;oo',
|
28
|
+
'PROP;P1=V1:f;oo'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_serialize_v_card21_array
|
33
|
+
assert_v_card21_serialization(
|
34
|
+
['f;oo', 'bar'],
|
35
|
+
'PROP;P1=V1:f\;oo;bar'
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_serialize_v_card21_fold
|
40
|
+
assert_v_card21_serialization(
|
41
|
+
'x' * 80,
|
42
|
+
'PROP;P1=V1:' + ('x' * 64) + "\r\n " + ('x' * 16)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_serialize_quoted_printable
|
47
|
+
assert_v_card21_serialization(
|
48
|
+
"foo\r\nbar",
|
49
|
+
'PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abar'
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_serialize_quoted_printable_fold
|
54
|
+
assert_v_card21_serialization(
|
55
|
+
"foo\r\nbarxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
56
|
+
"PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abarxxxxxxxxxxxxxxxxxxxxxxxxxx=\r\n xxx"
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_validate_minimum_prop_value
|
61
|
+
vcard = <<IN
|
62
|
+
BEGIN:VCARD
|
63
|
+
VERSION:4.0
|
64
|
+
UID:foo
|
65
|
+
FN:Hi!
|
66
|
+
N:A
|
67
|
+
END:VCARD
|
68
|
+
IN
|
69
|
+
|
70
|
+
vcard = Tilia::VObject::Reader.read(vcard)
|
71
|
+
assert_equal(1, vcard.validate.size)
|
72
|
+
|
73
|
+
assert_equal(1, vcard['N'].parts.size)
|
74
|
+
|
75
|
+
vcard.validate(Tilia::VObject::Node::REPAIR)
|
76
|
+
|
77
|
+
assert_equal(5, vcard['N'].parts.size)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|