kali 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -0
- data/examples/calendar.rb +48 -0
- data/lib/kali.rb +16 -0
- data/lib/kali/component.rb +128 -0
- data/lib/kali/component/calendar.rb +23 -0
- data/lib/kali/component/event.rb +33 -0
- data/lib/kali/key_value_pair.rb +62 -0
- data/lib/kali/parameter.rb +14 -0
- data/lib/kali/parameters.rb +146 -0
- data/lib/kali/properties.rb +207 -0
- data/lib/kali/property.rb +93 -0
- data/lib/kali/type.rb +118 -0
- data/lib/kali/type/boolean.rb +18 -0
- data/lib/kali/type/cal_address.rb +28 -0
- data/lib/kali/type/date.rb +16 -0
- data/lib/kali/type/date_time.rb +35 -0
- data/lib/kali/type/duration.rb +41 -0
- data/lib/kali/type/float.rb +14 -0
- data/lib/kali/type/geo.rb +21 -0
- data/lib/kali/type/integer.rb +14 -0
- data/lib/kali/type/list.rb +37 -0
- data/lib/kali/type/quoted.rb +18 -0
- data/lib/kali/type/text.rb +31 -0
- data/lib/kali/type/time.rb +17 -0
- data/lib/kali/type/uri.rb +16 -0
- data/lib/kali/typed_list.rb +52 -0
- data/lib/kali/utils.rb +6 -0
- data/lib/kali/utils/named.rb +17 -0
- data/lib/kali/utils/text.rb +42 -0
- data/lib/kali/version.rb +3 -0
- data/test/component/calendar_test.rb +20 -0
- data/test/component/event_test.rb +17 -0
- data/test/property/calendar_properties_test.rb +43 -0
- data/test/property/calendar_property_test.rb +45 -0
- data/test/property/component_properties_test.rb +31 -0
- data/test/test_helper.rb +2 -0
- data/test/type_test.rb +120 -0
- data/test/utils/text_test.rb +42 -0
- metadata +83 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CalendarPropertiesTest < MiniTest::Unit::TestCase
|
4
|
+
def test_prodid
|
5
|
+
prop = Kali::Property::ProductIdentifier.new("-//ABC Corporation//NONSGML My Product//EN")
|
6
|
+
assert_equal "PRODID:-//ABC Corporation//NONSGML My Product//EN", prop.to_ics
|
7
|
+
|
8
|
+
default = Kali::Property::ProductIdentifier.new
|
9
|
+
assert_equal "PRODID:Kali/#{Kali::VERSION}", default.to_ics
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_version
|
13
|
+
assert_raises ArgumentError do
|
14
|
+
Kali::Property::Version.new("2.5").to_ics
|
15
|
+
end
|
16
|
+
|
17
|
+
prop = Kali::Property::Version.new("2.0")
|
18
|
+
assert_equal "VERSION:2.0", prop.to_ics
|
19
|
+
|
20
|
+
default = Kali::Property::Version.new
|
21
|
+
assert_equal "VERSION:2.0", default.to_ics
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_calscale
|
25
|
+
assert_raises ArgumentError do
|
26
|
+
Kali::Property::CalendarScale.new("JULIAN").to_ics
|
27
|
+
end
|
28
|
+
|
29
|
+
prop = Kali::Property::CalendarScale.new("GREGORIAN")
|
30
|
+
assert_equal "CALSCALE:GREGORIAN", prop.to_ics
|
31
|
+
|
32
|
+
default = Kali::Property::CalendarScale.new
|
33
|
+
assert_equal "CALSCALE:GREGORIAN", default.to_ics
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_method
|
37
|
+
prop = Kali::Property::Method.new("REQUEST")
|
38
|
+
assert_equal "METHOD:REQUEST", prop.to_ics
|
39
|
+
|
40
|
+
default = Kali::Property::Method.new
|
41
|
+
assert_raises(ArgumentError) { default.to_ics }
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CalendarPropertiesTest < MiniTest::Unit::TestCase
|
4
|
+
def test_prodid
|
5
|
+
prop = Kali::Property::ProductIdentifier.new("-//ABC Corporation//NONSGML My Product//EN")
|
6
|
+
assert_equal "PRODID:-//ABC Corporation//NONSGML My Product//EN", prop.to_ics
|
7
|
+
|
8
|
+
default = Kali::Property::ProductIdentifier.new
|
9
|
+
assert_equal "PRODID:Kali/#{Kali::VERSION}", default.to_ics
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_version
|
13
|
+
assert_raises ArgumentError do
|
14
|
+
prop = Kali::Property::Version.new("2.5")
|
15
|
+
assert_equal "VERSION:2.5", prop.to_ics
|
16
|
+
end
|
17
|
+
|
18
|
+
prop = Kali::Property::Version.new("2.0")
|
19
|
+
assert_equal "VERSION:2.0", prop.to_ics
|
20
|
+
|
21
|
+
default = Kali::Property::Version.new
|
22
|
+
assert_equal "VERSION:2.0", default.to_ics
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_calscale
|
26
|
+
assert_raises ArgumentError do
|
27
|
+
prop = Kali::Property::CalendarScale.new("JULIAN")
|
28
|
+
assert_equal "CALSCALE:JULIAN", prop.to_ics
|
29
|
+
end
|
30
|
+
|
31
|
+
prop = Kali::Property::CalendarScale.new("GREGORIAN")
|
32
|
+
assert_equal "CALSCALE:GREGORIAN", prop.to_ics
|
33
|
+
|
34
|
+
default = Kali::Property::CalendarScale.new
|
35
|
+
assert_equal "CALSCALE:GREGORIAN", default.to_ics
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_method
|
39
|
+
prop = Kali::Property::Method.new("REQUEST")
|
40
|
+
assert_equal "METHOD:REQUEST", prop.to_ics
|
41
|
+
|
42
|
+
default = Kali::Property::Method.new
|
43
|
+
assert_raises(ArgumentError) { default.to_ics }
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ComponentPropertiesTest < MiniTest::Unit::TestCase
|
4
|
+
def test_uid
|
5
|
+
prop = Kali::Property::UniqueIdentifier.new("event-1")
|
6
|
+
assert_equal "UID:event-1", prop.to_ics
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_sequence
|
10
|
+
prop = Kali::Property::SequenceNumber.new(1)
|
11
|
+
assert_equal "SEQUENCE:1", prop.to_ics
|
12
|
+
|
13
|
+
default = Kali::Property::SequenceNumber.new
|
14
|
+
assert_equal "SEQUENCE:0", default.to_ics
|
15
|
+
|
16
|
+
assert_raises ArgumentError do
|
17
|
+
prop = Kali::Property::SequenceNumber.new(-1)
|
18
|
+
prop.to_ics
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_description
|
23
|
+
prop = Kali::Property::Description.new("Some, long, description")
|
24
|
+
assert_equal "DESCRIPTION:Some\\, long\\, description", prop.to_ics
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_geo
|
28
|
+
prop = Kali::Property::GeographicPosition.new([-54.00, -34.00])
|
29
|
+
assert_equal "GEO:-54.0;-34.0", prop.to_ics
|
30
|
+
end
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/type_test.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TypeTest < MiniTest::Unit::TestCase
|
4
|
+
def test_text
|
5
|
+
type = Kali::Type::Text.new
|
6
|
+
assert_equal "plain", type.encode("plain")
|
7
|
+
assert_equal "escaped\\, characters", type.encode("escaped, characters")
|
8
|
+
assert_equal "escaped\\ncharacters", type.encode("escaped\ncharacters")
|
9
|
+
assert_equal "escaped\\;characters", type.encode("escaped;characters")
|
10
|
+
assert_idempotent type, "idempotent;idempotent,idempotent\nidempotent"
|
11
|
+
|
12
|
+
type = Kali::Type::Text.new(/[aeiou]/)
|
13
|
+
assert_equal "a", type.encode("a")
|
14
|
+
assert_equal "a", type.decode("a")
|
15
|
+
assert_raises(ArgumentError) { type.encode("b") }
|
16
|
+
assert_raises(ArgumentError) { type.decode("b") }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_integer
|
20
|
+
type = Kali::Type::Integer.new
|
21
|
+
assert_equal "0", type.encode(0)
|
22
|
+
assert_equal "1", type.encode(1.3)
|
23
|
+
assert_raises(ArgumentError) { type.encode("nope") }
|
24
|
+
assert_idempotent type, 1
|
25
|
+
|
26
|
+
type = Kali::Type::Integer.new(0..9)
|
27
|
+
assert_equal "3", type.encode(3)
|
28
|
+
assert_equal 5, type.decode("5")
|
29
|
+
assert_raises(ArgumentError) { type.encode(15) }
|
30
|
+
assert_raises(ArgumentError) { type.decode("10") }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_float
|
34
|
+
type = Kali::Type::Float.new
|
35
|
+
assert_equal "1.3", type.encode(1.3)
|
36
|
+
assert_equal "0.0", type.encode(0)
|
37
|
+
assert_raises(ArgumentError) { type.encode("nope") }
|
38
|
+
assert_idempotent type, 1.5
|
39
|
+
|
40
|
+
type = Kali::Type::Float.new(->(i) { i.between?(5.5, 10.0) })
|
41
|
+
assert_equal "8.0", type.encode(8.0)
|
42
|
+
assert_equal 9.2, type.decode("9.2")
|
43
|
+
assert_raises(ArgumentError) { type.encode(5.0) }
|
44
|
+
assert_raises(ArgumentError) { type.decode("10.1") }
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_geo
|
48
|
+
type = Kali::Type::Geo.new
|
49
|
+
assert_equal "10.0;-3.0", type.encode([10.0, -3.0])
|
50
|
+
assert_equal [-90.0, 180.0], type.decode("-90.000000;180.000000")
|
51
|
+
assert_idempotent type, [-15.0001, -18.3456]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_list
|
55
|
+
type = Kali::Type::List.new(Kali::Type::Text.new)
|
56
|
+
assert_equal "a,b,c,d,e", type.encode(["a", "b", "c", "d", "e"])
|
57
|
+
assert_equal ["x", "y", "z"], type.decode("x,y,z")
|
58
|
+
assert_equal "test,with\\, one comma,with\\, two\\, commas",
|
59
|
+
type.encode(["test", "with, one comma", "with, two, commas"])
|
60
|
+
assert_idempotent type, ["test", "with, one comma", "with, two, commas"]
|
61
|
+
|
62
|
+
type = Kali::Type::List.new(Kali::Type::Integer.new(0..9))
|
63
|
+
assert_equal "1,2,3", type.encode([1, 2, 3])
|
64
|
+
assert_equal [5, 6, 7], type.decode("5,6,7")
|
65
|
+
assert_raises(ArgumentError) { type.encode([1, 2, 30]) }
|
66
|
+
assert_raises(ArgumentError) { type.decode("10,5,1") }
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_duration
|
70
|
+
type = Kali::Type::Duration.new
|
71
|
+
assert_equal("-PT15M", type.encode({ negative: true, minute: 15 }))
|
72
|
+
assert_equal({ minute: 15, negative: true }, type.decode("-PT15M"))
|
73
|
+
assert_equal("P3DT2H15M", type.encode({ day: 3, hour: 2, minute: 15 }))
|
74
|
+
assert_equal({ minute: 0, hour: 3, week: 1 }, type.decode("P1WT3H0M"))
|
75
|
+
assert_idempotent type, { week: 1, hour: 4, day: 2, minute: 5 }
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_cal_address
|
79
|
+
type = Kali::Type::CalAddress.new
|
80
|
+
assert_equal "mailto:john@example.org", type.encode(URI("mailto:john@example.org"))
|
81
|
+
assert_equal URI("mailto:jane@example.org"), type.decode("mailto:jane@example.org")
|
82
|
+
assert_raises(ArgumentError) { type.encode(URI("https://example.org")) }
|
83
|
+
assert_raises(ArgumentError) { type.decode("https://example.org") }
|
84
|
+
assert_idempotent type, URI("mailto:jane@example.org")
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_time
|
88
|
+
type = Kali::Type::Time.new
|
89
|
+
assert_equal "103000", type.encode(Time.parse("10:30"))
|
90
|
+
assert_equal Time.parse("10:45:30"), type.decode("104530")
|
91
|
+
|
92
|
+
assert_equal "103000Z", type.encode(Time.parse("10:30 UTC"))
|
93
|
+
assert_equal Time.parse("10:45:30 UTC"), type.decode("104530Z")
|
94
|
+
|
95
|
+
assert_idempotent type, Time.parse("13:10:05")
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_date
|
99
|
+
type = Kali::Type::Date.new
|
100
|
+
assert_equal "20130731", type.encode(Date.parse("2013-07-31"))
|
101
|
+
assert_equal Date.parse("2012-02-29"), type.decode("20120229")
|
102
|
+
|
103
|
+
assert_idempotent type, Date.parse("2013-04-30")
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_date_time
|
107
|
+
type = Kali::Type::DateTime.new
|
108
|
+
assert_equal "20130731T103000", type.encode(DateTime.parse("2013-07-31 10:30:00 +02:00"))
|
109
|
+
assert_equal DateTime.parse("1985-03-27 20:23:15"), type.decode("19850327T202315")
|
110
|
+
|
111
|
+
assert_equal "20130731T103000Z", type.encode(DateTime.parse("2013-07-31 10:30:00 UTC"))
|
112
|
+
assert_equal DateTime.parse("1985-03-27 20:23:15 UTC"), type.decode("19850327T202315Z")
|
113
|
+
|
114
|
+
assert_idempotent type, DateTime.parse("2000-01-01 00:00:00")
|
115
|
+
end
|
116
|
+
|
117
|
+
def assert_idempotent(type, test_value)
|
118
|
+
assert_equal test_value, type.decode(type.encode(test_value))
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class Kali::Utils::TextTest < MiniTest::Unit::TestCase
|
4
|
+
def test_fold_lines_shorter_than_75_chars
|
5
|
+
line = "a" * 60
|
6
|
+
folded = Kali::Utils::Text.fold_line(line)
|
7
|
+
assert_equal line, folded
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_fold_lines_exactly_75_chars_long
|
11
|
+
line = "a" * 75
|
12
|
+
folded = Kali::Utils::Text.fold_line(line)
|
13
|
+
assert_equal line, folded
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_fold_line_into_two_line_string
|
17
|
+
line = "a" * 120
|
18
|
+
folded = Kali::Utils::Text.fold_line(line)
|
19
|
+
expected = "#{"a" * 75}\r\n #{"a" * 45}"
|
20
|
+
assert_equal expected, folded
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_fold_line_into_three_line_string
|
24
|
+
line = "a" * 200
|
25
|
+
folded = Kali::Utils::Text.fold_line(line)
|
26
|
+
expected = "#{"a" * 75}\r\n #{"a" * 74}\r\n #{"a" * 51}"
|
27
|
+
assert_equal expected, folded
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_unfold_long_line
|
31
|
+
lines = "#{"a" * 75}\r\n #{"a" * 74}\r\n #{"a" * 51}"
|
32
|
+
actual = Kali::Utils::Text.unfold_line(lines)
|
33
|
+
expected = "a" * 200
|
34
|
+
assert_equal expected, actual
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_fold_unfold_is_idempotent
|
38
|
+
expected = "a" * 200
|
39
|
+
actual = Kali::Utils::Text.unfold_line(Kali::Utils::Text.fold_line(expected))
|
40
|
+
assert_equal expected, actual
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kali
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicolas Sanguinetti
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Extensible implementation of RFC5545. Also known as 'iCalendar'
|
15
|
+
email:
|
16
|
+
- hi@nicolassanguinetti.info
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- examples/calendar.rb
|
23
|
+
- lib/kali.rb
|
24
|
+
- lib/kali/component.rb
|
25
|
+
- lib/kali/component/calendar.rb
|
26
|
+
- lib/kali/component/event.rb
|
27
|
+
- lib/kali/key_value_pair.rb
|
28
|
+
- lib/kali/parameter.rb
|
29
|
+
- lib/kali/parameters.rb
|
30
|
+
- lib/kali/properties.rb
|
31
|
+
- lib/kali/property.rb
|
32
|
+
- lib/kali/type.rb
|
33
|
+
- lib/kali/type/boolean.rb
|
34
|
+
- lib/kali/type/cal_address.rb
|
35
|
+
- lib/kali/type/date.rb
|
36
|
+
- lib/kali/type/date_time.rb
|
37
|
+
- lib/kali/type/duration.rb
|
38
|
+
- lib/kali/type/float.rb
|
39
|
+
- lib/kali/type/geo.rb
|
40
|
+
- lib/kali/type/integer.rb
|
41
|
+
- lib/kali/type/list.rb
|
42
|
+
- lib/kali/type/quoted.rb
|
43
|
+
- lib/kali/type/text.rb
|
44
|
+
- lib/kali/type/time.rb
|
45
|
+
- lib/kali/type/uri.rb
|
46
|
+
- lib/kali/typed_list.rb
|
47
|
+
- lib/kali/utils.rb
|
48
|
+
- lib/kali/utils/named.rb
|
49
|
+
- lib/kali/utils/text.rb
|
50
|
+
- lib/kali/version.rb
|
51
|
+
- test/component/calendar_test.rb
|
52
|
+
- test/component/event_test.rb
|
53
|
+
- test/property/calendar_properties_test.rb
|
54
|
+
- test/property/calendar_property_test.rb
|
55
|
+
- test/property/component_properties_test.rb
|
56
|
+
- test/test_helper.rb
|
57
|
+
- test/type_test.rb
|
58
|
+
- test/utils/text_test.rb
|
59
|
+
homepage: https://github.com/foca/kali
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.23
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Implementation of the iCalendar standard
|
83
|
+
test_files: []
|