Lines
90.4 %
Functions
100 %
Branches
pub(crate) mod access;
pub mod component;
pub mod object;
pub mod param;
pub mod property;
pub use access::*;
#[cfg(test)]
mod tests {
use crate::common::{LanguageTag, Range, RecurFreq, RelationshipType, TimeTransparency};
use crate::model::component::CalendarComponent;
use crate::model::object::ICalObject;
use crate::model::param::{OtherParamsBuilder, ParticipationStatusEvent};
use crate::model::property::{
Classification, ComponentProperty, Duration, Period, StatusEvent,
};
use time::Date;
#[test]
fn all_cal_props_cal_object() {
let obj = ICalObject::builder()
.add_product_id("-//ABC Corporation//NONSGML My Product//EN")
.add_x_param("x-special-param", "my-value")
.finish_property()
.add_max_version("2.0")
.add_x_param_values(
"x-special-param",
vec!["one-value".to_string(), "another-value".to_string()],
)
.add_calendar_scale("GREGORIAN")
.add_method("REQUEST")
.add_x_property("X-PROP", "X-VALUE")
.add_iana_param("special-param", "my-value")
.add_iana_property("IANA-PARAM", "IANA-VALUE")
.add_iana_param_values(
"iana-special-param",
.build();
assert_eq!(obj.properties.len(), 6);
}
fn x_component_cal_object() {
.add_product_id("x_component_cal_object")
.add_x_component("X-SOME-COMPONENT", |b| {
b.add_x_property("X-SOME-PROP", "X-SOME-VALUE")
})
.add_iana_component("IANA-SOME-COMPONENT", |b| {
b.add_iana_property("IANA-SOME-PROP", "IANA-SOME-VALUE")
assert_eq!(obj.components.len(), 2);
match &obj.components[0] {
CalendarComponent::XComponent(x) => {
assert_eq!(x.properties.len(), 1);
match &x.properties[0] {
ComponentProperty::XProperty(p) => {
assert_eq!(p.params.len(), 2);
_ => panic!("Expected XProperty"),
_ => panic!("Expected XComponent"),
match &obj.components[1] {
CalendarComponent::IanaComponent(x) => {
ComponentProperty::IanaProperty(p) => {
_ => panic!("Expected IanaProperty"),
_ => panic!("Expected IanaComponent"),
fn event_component_cal_object() {
.add_product_id("event_component")
.add_event_component()
.add_date_time_stamp(
time::Date::from_calendar_date(1997, time::Month::September, 1).unwrap(),
time::Time::from_hms(13, 0, 0).unwrap(),
.add_x_param("X-SOME-PROP", "X-SOME-VALUE")
.add_unique_identifier("some-uid")
.add_date_time_start(
Some(time::Time::from_hms(14, 30, 0).unwrap()),
.add_tz_id("America/New_York", true)
.add_classification(Classification::Private)
.add_date_time_created(
.add_description("Event description")
.add_alternate_representation("CID:evt.desc")
.add_language(LanguageTag {
language: "en".to_string(),
region: Some("US".to_string()),
..Default::default()
.add_geographic_position(37.386013, -122.082932)
.add_organizer("mailto:john@local.net")
.add_common_name("John")
.add_directory_entry_reference("ldap://local.net/john")
.add_sent_by("mailto:lilith@local.net")
.add_priority(4)
.add_sequence(10)
.add_request_status(&[200, 4], "Success", None)
.add_time_transparency(TimeTransparency::Transparent)
.add_url("http://local.net/john")
.add_recurrence_id(
Date::from_calendar_date(1997, time::Month::September, 1).unwrap(),
None,
.add_range(Range::ThisAndFuture)
.add_recurrence_rule(RecurFreq::Hourly, |rule| rule.set_by_hour(vec![1, 2, 3]))
.add_date_time_end(
Some(time::Time::from_hms(15, 30, 0).unwrap()),
.add_duration(|| Duration::days_and_time(-1, 10).hours(3).build())
.add_attach_uri("http://local.net/john")
.add_fmt_type("text", "plain")
.add_attendee("mailto:horace@local.net")
.add_members(vec!["mailto:dev-group@local.net"])
.add_participation_status(ParticipationStatusEvent::Accepted)
.add_categories(vec!["MEETING", "PROJECT"])
.add_comment("Event comment")
.add_alternate_representation("CID:evt.comment")
.add_contact("mailto:kevin@local.net")
.add_alternate_representation("CID:evt.contact")
.add_exception_date_times(vec![(
Date::from_calendar_date(1997, time::Month::September, 2).unwrap(),
true,
.into()])
.add_status(StatusEvent::Tentative)
.add_related_to("CID:evt.related")
.add_relationship_type(RelationshipType::Parent)
.add_resources(vec!["EQUIPMENT", "ROOM"])
.add_alternate_representation("CID:evt.resources")
.add_recurrence_date_periods(vec![Period::new_start(
time::Time::from_hms(14, 30, 0).unwrap(),
Duration::hours(1, 1).build(),
)])
.add_last_modified(
.add_summary("Event summary")
.add_alternate_representation("CID:evt.summary")
.add_x_property("X-SOME-PROP", "X-SOME-VALUE")
.add_iana_property("IANA-SOME-PROP", "IANA-SOME-VALUE")
.finish_component()
assert_eq!(obj.components.len(), 1);
CalendarComponent::Event(e) => {
assert_eq!(e.properties.len(), 31);
match &e.properties[0] {
ComponentProperty::DateTimeStamp(p) => {
assert_eq!(p.params.len(), 1);
_ => panic!("Expected DateTimeStamp"),
match &e.properties[1] {
ComponentProperty::UniqueIdentifier(p) => {
_ => panic!("Expected UniqueIdentifier"),
match &e.properties[2] {
ComponentProperty::DateTimeStart(p) => {
_ => panic!("Expected DateTimeStart"),
match &e.properties[3] {
ComponentProperty::Classification(p) => {
_ => panic!("Expected Class"),
match &e.properties[4] {
ComponentProperty::DateTimeCreated(p) => {
_ => panic!("Expected Created"),
match &e.properties[5] {
ComponentProperty::Description(p) => {
assert_eq!(p.params.len(), 3);
_ => panic!("Expected Description"),
match &e.properties[6] {
ComponentProperty::GeographicPosition(p) => {
_ => panic!("Expected GeographicPosition"),
match &e.properties[7] {
ComponentProperty::Organizer(p) => {
assert_eq!(p.params.len(), 5);
_ => panic!("Expected Organizer"),
match &e.properties[8] {
ComponentProperty::Priority(p) => {
_ => panic!("Expected Priority"),
match &e.properties[9] {
ComponentProperty::Sequence(p) => {
_ => panic!("Expected Sequence"),
match &e.properties[10] {
ComponentProperty::RequestStatus(p) => {
_ => panic!("Expected RequestStatus"),
match &e.properties[11] {
ComponentProperty::TimeTransparency(p) => {
_ => panic!("Expected TimeTransparency"),
match &e.properties[12] {
ComponentProperty::Url(p) => {
_ => panic!("Expected Url"),
match &e.properties[13] {
ComponentProperty::RecurrenceId(p) => {
assert_eq!(p.params.len(), 4);
_ => panic!("Expected RecurrenceId"),
match &e.properties[14] {
ComponentProperty::RecurrenceRule(p) => {
_ => panic!("Expected RecurrenceRule"),
match &e.properties[15] {
ComponentProperty::DateTimeEnd(p) => {
_ => panic!("Expected DateTimeEnd"),
match &e.properties[16] {
ComponentProperty::Duration(p) => {
_ => panic!("Expected Duration"),
match &e.properties[17] {
ComponentProperty::Attach(p) => {
_ => panic!("Expected Attach"),
match &e.properties[18] {
ComponentProperty::Attendee(p) => {
_ => panic!("Expected Attendee"),
match &e.properties[19] {
ComponentProperty::Categories(p) => {
_ => panic!("Expected Categories"),
match &e.properties[20] {
ComponentProperty::Comment(p) => {
_ => panic!("Expected Comment"),
match &e.properties[21] {
ComponentProperty::Contact(p) => {
_ => panic!("Expected Contact"),
match &e.properties[22] {
ComponentProperty::ExceptionDateTimes(p) => {
_ => panic!("Expected ExceptionDateTimes"),
match &e.properties[23] {
ComponentProperty::Status(p) => {
_ => panic!("Expected Status"),
match &e.properties[24] {
ComponentProperty::RelatedTo(p) => {
_ => panic!("Expected RelatedTo"),
match &e.properties[25] {
ComponentProperty::Resources(p) => {
_ => panic!("Expected Resources"),
match &e.properties[26] {
ComponentProperty::RecurrenceDateTimes(p) => {
_ => panic!("Expected RecurrenceDateTimes"),
match &e.properties[27] {
ComponentProperty::LastModified(p) => {
_ => panic!("Expected LastModified"),
match &e.properties[28] {
ComponentProperty::Summary(p) => {
_ => panic!("Expected Summary"),
match &e.properties[29] {
match &e.properties[30] {
_ => panic!("Expected EventComponent"),