summaryrefslogtreecommitdiffstats
path: root/tests/calendar.rs
blob: 63e91ab2a999de3e547dacf5f2cbc85bd7c16a04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use chrono::prelude::*;
use icalendar::{Calendar, Class, Component, Event, EventStatus, Todo, parser};
use pretty_assertions::assert_eq;

const EXPECTED_CAL_CONTENT: &str = "\
BEGIN:VCALENDAR\r
VERSION:2.0\r
PRODID:ICALENDAR-RS\r
CALSCALE:GREGORIAN\r
BEGIN:VEVENT\r
CLASS:CONFIDENTIAL\r
DESCRIPTION:Description\r
DTEND:20140709T091011Z\r
DTSTAMP:20190307T181159\r
DTSTART:20140708T071011Z\r
LOCATION:Somewhere\r
PRIORITY:10\r
STATUS:TENTATIVE\r
SUMMARY:summary\r
UID:euid\r
END:VEVENT\r
BEGIN:VTODO\r
COMPLETED:20140709T091011Z\r
DTSTAMP:20190307T181159\r
DUE:20140708T091011\r
PERCENT-COMPLETE:95\r
SUMMARY:A Todo\r
UID:todouid\r
END:VTODO\r
END:VCALENDAR\r
";

#[test]
fn test_calendar_to_string() {
    let mut calendar = Calendar::new();
    let cest_date = FixedOffset::east(2 * 3600)
        .ymd(2014, 7, 8)
        .and_hms(9, 10, 11);
    let utc_date = Utc.ymd(2014, 7, 9).and_hms(9, 10, 11);
    let event = Event::new()
        .status(EventStatus::Tentative)
        .starts(cest_date.with_timezone(&Utc))
        .ends(utc_date)
        .priority(11) // converted to 10
        .summary("summary")
        .description("Description")
        .location("Somewhere")
        .uid("euid")
        .class(Class::Confidential)
        .add_property("DTSTAMP", "20190307T181159")
        .done();
    calendar.push(event);
    let todo = Todo::new()
        .percent_complete(95)
        .due(cest_date.naive_local())
        .completed(utc_date)
        .summary("A Todo")
        .uid("todouid")
        .add_property("DTSTAMP", "20190307T181159")
        .done();
    calendar.push(todo);
    assert_eq!(calendar.to_string(), EXPECTED_CAL_CONTENT);
}

#[test]
fn test_string_to_calendar() {
    let cal = parser::parse(EXPECTED_CAL_CONTENT);
    assert!(cal.is_ok());
}