summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md96
-rw-r--r--README.md13
-rw-r--r--src/component.rs12
-rw-r--r--src/duration.rs6
-rw-r--r--src/lib.rs16
-rw-r--r--src/property.rs3
-rw-r--r--src/testing/data.rs (renamed from src/testdata.rs)0
-rw-r--r--src/testing/mod.rs1
-rw-r--r--src/testutils.rs16
-rw-r--r--src/time.rs50
-rw-r--r--src/timezone.rs1
-rw-r--r--src/utils/dateutil.rs23
-rw-r--r--src/utils/fileutil.rs50
-rw-r--r--src/utils/misc.rs18
-rw-r--r--src/vcalendar.rs48
-rw-r--r--src/vevent.rs40
16 files changed, 233 insertions, 160 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..4b4f296
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,96 @@
+# Contributing to libical
+
+So you want to contribute to libical! Thank you, that's awesome!
+
+All contributors agree to the
+[developer certificate of origin](#developer-certificate-of-origin)
+by contributing to libical.
+
+Feel free to contact [us via our mailinglist](http://imag-pim.org/mailinglist/)
+and/or submit patches via mail (use `git format-patch` and
+`git send-email`, always add a cover letter to describe your submission).
+You don't have to send patches via mail, though. As long as I can `git pull`
+your changes (without having to login or register at the remote) or `git am`
+your patchset, I'm fine.
+I'd encourage you, though, to [use git-send-email](https://git-send-email.io)
+or at least [git-request-pull](https://git-scm.org/).
+
+Make sure to test-compile your patchset and run tests if there are any for the
+code you changed.
+
+I will run your patchset through travis CI.
+
+
+## Prerequisites
+
+You'll need libical installed on your system to test-compile this library.
+If you have a `nix` installation, you can issue
+`nix-shell --run "cargo check --tests"`
+to check the library.
+
+
+## Commit guidelines
+
+Make sure your patchset does not contain "Fixup" commits when publishing it, but feel
+free to send "Fixup" commits in the review process. If squashing fails I will
+come back to you.
+
+Also ensure that each commit has
+[a "Signed-off-by: " line](https://stackoverflow.com/questions/1962094/what-is-the-sign-off-feature-in-git-for).
+By adding that line, you agree to our
+[developer certificate of origin](#developer-certificate-of-origin).
+If you do not add the "Signed-off-by: " line, I reserve the right to kindly
+reject your patch.
+
+
+## Code of Conduct
+
+We use the same
+[code of conduct as the rust community does](https://www.rust-lang.org/conduct.html).
+
+Basically: Be kind, encourage others to ask questions - you are encouraged to
+ask questions as well!
+
+
+## Developer Certificate of Origin
+
+```
+Developer Certificate of Origin
+Version 1.1
+
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
+660 York Street, Suite 102,
+San Francisco, CA 94110 USA
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(a) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(b) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(c) The contribution was provided directly to me by some other
+ person who certified (a), (b) or (c) and I have not modified
+ it.
+
+(d) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
+```
+
+
diff --git a/README.md b/README.md
index f7203a3..6e13752 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,18 @@
# libical
-High-level interface for libical-sys.
+This library aims to be a high-level idomatic Rust crate for ical data handling
+and manipulation. It uses the famous
+[libical](https://libical.github.io/libical/) via the
+[libical-sys](https://github.com/Valodim/libical-sys) crate.
-## Status
+## Status / Progress
-**WIP. DO NOT USE.**
+* v0.2.0 is a (pending) refactoring effort to make this library more idomatic
+ for rust development.
+* [v0.1.0](https://crates.io/crates/libical) was published after the codebase
+ was extracted from the [khaleesii](https://github.com/Valodim/khaleesi)
+ project.
## License
diff --git a/src/component.rs b/src/component.rs
index 7de364c..d6e38b8 100644
--- a/src/component.rs
+++ b/src/component.rs
@@ -87,12 +87,12 @@ pub trait IcalComponent {
#[cfg(test)]
mod tests {
use super::*;
- use crate::testdata;
+ use crate::testing;
use crate::IcalVCalendar;
#[test]
fn get_property_test() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
let prop_name = "SUMMARY";
let prop_value: String = event.get_property_by_name(prop_name).unwrap().get_value();
@@ -106,7 +106,7 @@ mod tests {
#[test]
fn get_property_test_lastmodified() {
let cal =
- IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY_LASTMODIFIED, None).unwrap();
+ IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY_LASTMODIFIED, None).unwrap();
let event = cal.get_principal_event();
let prop_name = "LAST-MODIFIED";
let prop_value: String = event.get_property_by_name(prop_name).unwrap().get_value();
@@ -116,7 +116,7 @@ mod tests {
#[test]
fn get_property_test_cal() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let prop_name = "PRODID";
let prop_value: String = cal.get_property_by_name(prop_name).unwrap().get_value();
@@ -128,7 +128,7 @@ mod tests {
#[test]
fn get_property_test_negative() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
let prop_name = "DESCRIPTION";
let prop = event.get_property_by_name(prop_name);
@@ -138,7 +138,7 @@ mod tests {
#[test]
fn get_property_by_name_test() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
let prop_name = "NONSENSE";
let prop = event.get_property_by_name(prop_name);
diff --git a/src/duration.rs b/src/duration.rs
index d080584..6de4c49 100644
--- a/src/duration.rs
+++ b/src/duration.rs
@@ -5,17 +5,23 @@ use std::fmt::{Display, Error, Formatter};
use std::ops::{Add, Deref};
use std::str::FromStr;
+/// Duration type
+///
+/// A type that represents a duration of time
#[derive(Clone, Debug)]
pub struct IcalDuration {
duration: ical::icaldurationtype,
}
impl IcalDuration {
+
+ /// Convert a number of seconds to an IcalDuration
pub fn from_seconds(seconds: i32) -> IcalDuration {
let duration = unsafe { ical::icaldurationtype_from_int(seconds) };
IcalDuration { duration }
}
+ /// Get the number of seconds the IcalDuration represents
pub fn to_seconds(&self) -> i32 {
unsafe { ical::icaldurationtype_as_int(self.duration) }
}
diff --git a/src/lib.rs b/src/lib.rs
index 71579d8..89c64df 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,11 @@
+//! libical high level interface
+//!
+//! This library offers a high-level interface for the widely used libical. It relies upon the
+//! libical-sys crate, which is a thin rust layer over the libical C API.
+//! It provides a safe interface to libical that is rather lower-level, as well as convenience
+//! functionality build on this low-level interface for easy handling of icalendar data.
+//!
+
#![warn(unused_extern_crates)]
#![allow(clippy::redundant_closure)] // disable "redundant closure" lint
@@ -30,15 +38,12 @@ pub mod duration;
pub mod property;
pub mod time;
pub mod timezone;
-pub mod utils;
pub mod vcalendar;
pub mod vevent;
+mod utils;
#[cfg(test)]
-pub mod testdata;
-
-#[cfg(test)]
-pub mod testutils;
+pub mod testing;
pub use crate::component::IcalComponent;
pub use crate::duration::IcalDuration;
@@ -48,3 +53,4 @@ pub use crate::timezone::IcalTimeZone;
pub use crate::vcalendar::IcalEventIter;
pub use crate::vcalendar::IcalVCalendar;
pub use crate::vevent::IcalVEvent;
+
diff --git a/src/property.rs b/src/property.rs
index 55b5914..63e7540 100644
--- a/src/property.rs
+++ b/src/property.rs
@@ -5,6 +5,9 @@ use std::fmt;
use super::component::IcalComponent;
use crate::ical;
+/// A property in the ical data
+///
+/// This type represents a single property (name + value).
pub struct IcalProperty<'a> {
pub ptr: *mut ical::icalproperty,
_parent: &'a dyn IcalComponent,
diff --git a/src/testdata.rs b/src/testing/data.rs
index 9237889..9237889 100644
--- a/src/testdata.rs
+++ b/src/testing/data.rs
diff --git a/src/testing/mod.rs b/src/testing/mod.rs
new file mode 100644
index 0000000..7a345e4
--- /dev/null
+++ b/src/testing/mod.rs
@@ -0,0 +1 @@
+pub mod data;
diff --git a/src/testutils.rs b/src/testutils.rs
deleted file mode 100644
index ade3ea1..0000000
--- a/src/testutils.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use assert_fs::fixture::{ChildPath, FixtureError};
-use assert_fs::prelude::*;
-use assert_fs::TempDir;
-use std::path::{Path, PathBuf};
-
-pub fn path_to(artifact: &str) -> PathBuf {
- [env!("CARGO_MANIFEST_DIR"), "testdata", artifact]
- .iter()
- .collect()
-}
-
-pub fn touch_testfile(testdir: &TempDir, relative_path: &Path) -> Result<ChildPath, FixtureError> {
- let testfile = testdir.child(relative_path);
- testfile.touch()?;
- Ok(testfile)
-}
diff --git a/src/time.rs b/src/time.rs
index 37f0e84..7084b08 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -9,20 +9,27 @@ use std::fmt::{Display, Error, Formatter};
use std::ops::{Add, Deref};
use std::str::FromStr;
+/// Time type
+///
+/// A type representing "time"
#[derive(Clone, Debug)]
pub struct IcalTime {
time: ical::icaltimetype,
}
impl IcalTime {
+
+ /// Get an IcalTime object that represents UTC now
pub fn utc() -> Self {
dateutil::now().into()
}
+ /// Get an IcalTime object that represents the current time in the local timezone.
pub fn local() -> Self {
dateutil::now().with_timezone(&Local).into()
}
+ /// Get an IcalTime object that represents a specific day.
pub fn floating_ymd(year: i32, month: i32, day: i32) -> Self {
let time = ical::icaltimetype {
year,
@@ -35,9 +42,12 @@ impl IcalTime {
is_daylight: 0,
zone: ::std::ptr::null(),
};
+ let time = unsafe { ical::icaltime_normalize(time) };
IcalTime { time }
}
+ /// Get an IcalTime object that is the same as the object this function is called on, but with
+ /// hour, minute and second set
pub fn and_hms(&self, hour: i32, minute: i32, second: i32) -> Self {
let mut time = self.time;
time.hour = hour;
@@ -45,9 +55,12 @@ impl IcalTime {
time.second = second;
time.is_date = 0;
+ let time = unsafe { ical::icaltime_normalize(time) };
+
IcalTime { time }
}
+ /// Get an IcalTime object based on a timestamp
pub fn from_timestamp(timestamp: i64) -> Self {
let _lock = TZ_MUTEX.lock();
let utc = IcalTimeZone::utc();
@@ -56,21 +69,25 @@ impl IcalTime {
IcalTime { time }
}
+ /// Get the timestamp representation of the IcalTime object
pub fn timestamp(&self) -> i64 {
let _lock = TZ_MUTEX.lock();
unsafe { ical::icaltime_as_timet_with_zone(self.time, self.time.zone) }
}
+ /// Get whether the IcalTime object is a date object
pub fn is_date(&self) -> bool {
self.time.is_date != 0
}
+ /// Get the IcalTime object as a date object
pub fn as_date(&self) -> IcalTime {
let mut time = self.time;
time.is_date = 1;
IcalTime { time }
}
+ /// Get the timezone for the IcalTime object
pub fn get_timezone(&self) -> Option<IcalTimeZone> {
if self.time.zone.is_null() {
return None;
@@ -79,6 +96,7 @@ impl IcalTime {
Some(IcalTimeZone::from_ptr_copy(tz_ptr))
}
+ /// Get a new IcalTime object with a different timezone
pub fn with_timezone(&self, timezone: &IcalTimeZone) -> IcalTime {
let _lock = TZ_MUTEX.lock();
let mut time = unsafe { ical::icaltime_convert_to_zone(self.time, **timezone) };
@@ -87,6 +105,7 @@ impl IcalTime {
IcalTime { time }
}
+ /// Get a new IcalTime object with the day before the day of the current object
pub fn pred(&self) -> IcalTime {
let mut time = self.time;
time.day -= 1;
@@ -94,6 +113,7 @@ impl IcalTime {
IcalTime { time }
}
+ /// Get a new IcalTime object with the day after the day of the current object
pub fn succ(&self) -> IcalTime {
let mut time = self.time;
time.day += 1;
@@ -293,4 +313,34 @@ mod tests {
let time = IcalTime::utc();
assert_eq!("20130102T010203Z", time.succ().to_string());
}
+
+ #[test]
+ fn test_invalid_month() {
+ let time = IcalTime::floating_ymd(2000, 13, 1);
+ assert_eq!("20010101", time.to_string());
+ }
+
+ #[test]
+ fn test_invalid_day() {
+ let time = IcalTime::floating_ymd(2000, 12, 32);
+ assert_eq!("20010101", time.to_string());
+ }
+
+ #[test]
+ fn test_invalid_hour() {
+ let time = IcalTime::floating_ymd(2000, 12, 31).and_hms(25, 0, 0);
+ assert_eq!("20010101T010000", time.to_string());
+ }
+
+ #[test]
+ fn test_invalid_minute() {
+ let time = IcalTime::floating_ymd(2000, 12, 31).and_hms(24, 61, 0);
+ assert_eq!("20010101T010100", time.to_string());
+ }
+
+ #[test]
+ fn test_invalid_second() {
+ let time = IcalTime::floating_ymd(2000, 12, 31).and_hms(24, 60, 61);
+ assert_eq!("20010101T010101", time.to_string());
+ }
}
diff --git a/src/timezone.rs b/src/timezone.rs
index 843a1ed..855b9da 100644
--- a/src/timezone.rs
+++ b/src/timezone.rs
@@ -5,6 +5,7 @@ use std::ops::Deref;
use super::IcalTime;
use crate::utils::dateutil;
+/// A type representing a timezone.
pub struct IcalTimeZone {
timezone: *mut ical::icaltimezone,
}
diff --git a/src/utils/dateutil.rs b/src/utils/dateutil.rs
index 0f17971..7d3146a 100644
--- a/src/utils/dateutil.rs
+++ b/src/utils/dateutil.rs
@@ -4,7 +4,7 @@ use crate::utils::fileutil;
use std::env;
use std::path::PathBuf;
-pub fn date_from_str(date_str: &str) -> ParseResult<Date<Local>> {
+fn date_from_str(date_str: &str) -> ParseResult<Date<Local>> {
if date_str == "today" || date_str == "now" {
return Ok(Local::now().date());
}
@@ -20,7 +20,7 @@ pub fn datetime_from_str(datetime_str: &str) -> ParseResult<DateTime<Local>> {
Ok(Local.from_local_datetime(naive_datetime).unwrap())
}
-pub fn week_from_str_begin(date_str: &str) -> Result<Date<Local>, String> {
+fn week_from_str_begin(date_str: &str) -> Result<Date<Local>, String> {
let now = Local::now();
if date_str == "toweek" || date_str == "thisweek" {
return Ok(Local.isoywd(now.year(), now.iso_week().week(), Weekday::Mon));
@@ -56,11 +56,10 @@ pub fn now() -> DateTime<Utc> {
#[cfg(test)]
pub fn now() -> DateTime<Utc> {
- use crate::testdata;
- *testdata::NOW_TEST
+ *crate::testing::data::NOW_TEST
}
-pub fn week_from_str_end(date_str: &str) -> Result<Date<Local>, String> {
+fn week_from_str_end(date_str: &str) -> Result<Date<Local>, String> {
let now = Local::now();
if date_str == "toweek" || date_str == "thisweek" {
return Ok(Local.isoywd(now.year(), now.iso_week().week(), Weekday::Sun));
@@ -76,13 +75,6 @@ pub fn week_from_str_end(date_str: &str) -> Result<Date<Local>, String> {
Err("Could not parse '{}' as week".to_string())
}
-pub fn datetime_from_timestamp(timestamp: &str) -> Option<DateTime<Local>> {
- let timestamp_i64 = timestamp.parse::<i64>().ok()?;
- let naive_datetime = NaiveDateTime::from_timestamp_opt(timestamp_i64, 0)?;
- let utc_time: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
- Some(utc_time.with_timezone(&Local))
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -142,11 +134,4 @@ mod tests {
week_from_str_end("nonsense").unwrap();
}
- #[test]
- fn test_datetime_from_timestamp() {
- let timestamp = "1547234687";
- let dt_from_ts = datetime_from_timestamp(timestamp).unwrap();
- let dt = Utc.ymd(2019, 01, 11).and_hms(19, 24, 47);
- assert_eq!(dt, dt_from_ts);
- }
}
diff --git a/src/utils/fileutil.rs b/src/utils/fileutil.rs
index aac3ab6..052b72f 100644
--- a/src/utils/fileutil.rs
+++ b/src/utils/fileutil.rs
@@ -1,55 +1,7 @@
-use std::fs::OpenOptions;
use std::io::prelude::*;
-use std::io::{BufRead, BufReader};
-use std::path::{Path, PathBuf};
+use std::path::Path;
use std::{fs, io};
-pub fn file_iter(dir: &Path) -> impl Iterator<Item = PathBuf> {
- use walkdir::WalkDir;
-
- WalkDir::new(dir)
- .follow_links(true)
- .into_iter()
- .filter_map(|e| e.ok())
- .filter(|e| e.file_type().is_file())
- .map(|entry| entry.into_path())
-}
-
-pub fn dir_iter(dir: &Path) -> impl Iterator<Item = PathBuf> {
- use walkdir::WalkDir;
-
- let dir = dir.to_path_buf();
- WalkDir::new(&dir)
- .follow_links(true)
- .into_iter()
- .filter_map(|e| e.ok())
- .filter(|e| e.file_type().is_dir())
- .filter(move |f| f.path() != dir)
- .map(|entry| entry.into_path())
-}
-
-pub fn write_file(filepath: &Path, contents: &str) -> io::Result<()> {
- let mut file = fs::File::create(filepath)?;
- file.write_all(contents.as_bytes())
-}
-
-pub fn append_file(filepath: &Path, contents: &str) -> io::Result<()> {
- let mut file = OpenOptions::new()
- .append(true)
- .create(true)
- .open(filepath)?;
- file.write_all(contents.as_bytes())
-}
-
-pub fn read_lines_from_file(
- filepath: &Path,
-) -> io::Result<impl DoubleEndedIterator<Item = String>> {
- let f = fs::File::open(filepath)?;
- let f = BufReader::new(f);
- let lines: Result<Vec<String>, io::Error> = f.lines().collect();
- lines.map(|result| result.into_iter())
-}
-
pub fn read_file_to_string(path: &Path) -> io::Result<String> {
let mut file = fs::File::open(&path)?;
let mut contents = String::new();
diff --git a/src/utils/misc.rs b/src/utils/misc.rs
index f02ddeb..d5b0551 100644
--- a/src/utils/misc.rs
+++ b/src/utils/misc.rs
@@ -1,4 +1,3 @@
-use chrono::prelude::*;
use std::fmt::Display;
use std::time;
@@ -19,23 +18,6 @@ pub fn format_duration(duration: &time::Duration) -> impl Display {
duration.as_millis()
}
-pub fn get_bucket_for_date(date: Date<Local>) -> String {
- date.format("%G-W%V").to_string()
-}
-
-#[cfg(not(test))]
-pub fn make_new_uid() -> String {
- use uuid::Uuid;
-
- let suffix = "@khaleesi";
- format!("{}{}", Uuid::new_v4().to_hyphenated_ref(), suffix)
-}
-
-#[cfg(test)]
-pub fn make_new_uid() -> String {
- "11111111-2222-3333-4444-444444444444@khaleesi".to_string()
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/vcalendar.rs b/src/vcalendar.rs
index 9daf452..f925df3 100644
--- a/src/vcalendar.rs
+++ b/src/vcalendar.rs
@@ -409,7 +409,7 @@ impl Drop for IcalComponentOwner {
#[cfg(test)]
mod tests {
use super::*;
- use crate::testdata;
+ use crate::testing;
#[test]
fn test_from_str_empty() {
@@ -418,39 +418,39 @@ mod tests {
#[test]
fn test_from_str_event() {
- assert!(IcalVCalendar::from_str(testdata::TEST_BARE_EVENT, None).is_err());
+ assert!(IcalVCalendar::from_str(testing::data::TEST_BARE_EVENT, None).is_err());
}
#[test]
fn event_iterator_element_count() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
assert_eq!(cal.events_iter().count(), 1)
}
#[test]
fn event_iterator_element_count_with_other() {
let cal =
- IcalVCalendar::from_str(testdata::TEST_EVENT_WITH_TIMEZONE_COMPONENT, None).unwrap();
+ IcalVCalendar::from_str(testing::data::TEST_EVENT_WITH_TIMEZONE_COMPONENT, None).unwrap();
assert_eq!(cal.events_iter().count(), 1)
}
#[test]
fn load_serialize() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let back = cal.to_string().replace("\r\n", "\n");
- assert_eq!(back.trim(), testdata::TEST_EVENT_MULTIDAY)
+ assert_eq!(back.trim(), testing::data::TEST_EVENT_MULTIDAY)
}
#[test]
fn load_serialize_with_error() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_WITH_X_LIC_ERROR, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_WITH_X_LIC_ERROR, None).unwrap();
let back = cal.to_string().replace("\r\n", "\n");
- assert_eq!(back.trim(), testdata::TEST_EVENT_WITH_X_LIC_ERROR)
+ assert_eq!(back.trim(), testing::data::TEST_EVENT_WITH_X_LIC_ERROR)
}
#[test]
fn with_dtstamp_test() {
- let mut cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let mut cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
cal = cal.with_dtstamp_now();
let event = cal.get_principal_event();
@@ -463,13 +463,13 @@ mod tests {
fn get_calendar_name_test() {
let path = PathBuf::from("calname/event");
let cal =
- IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY_ALLDAY, Some(&path)).unwrap();
+ IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY_ALLDAY, Some(&path)).unwrap();
assert_eq!("calname".to_string(), cal.get_calendar_name().unwrap())
}
#[test]
fn test_get_all_properties_cal() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let props = cal.get_properties_all();
assert_eq!(2, props.len());
@@ -477,7 +477,7 @@ mod tests {
#[test]
fn parse_checker_test_empty_summary() {
- let c_str = CString::new(testdata::TEST_EVENT_EMPTY_SUMMARY).unwrap();
+ let c_str = CString::new(testing::data::TEST_EVENT_EMPTY_SUMMARY).unwrap();
unsafe {
let parsed_cal = ical::icalparser_parse_string(c_str.as_ptr());
assert!(IcalVCalendar::check_icalcomponent(parsed_cal).is_some())
@@ -486,7 +486,7 @@ mod tests {
#[test]
fn parse_checker_test_no_uid() {
- let c_str = CString::new(testdata::TEST_EVENT_NO_UID).unwrap();
+ let c_str = CString::new(testing::data::TEST_EVENT_NO_UID).unwrap();
unsafe {
let parsed_cal = ical::icalparser_parse_string(c_str.as_ptr());
assert!(IcalVCalendar::check_icalcomponent(parsed_cal).is_some())
@@ -495,7 +495,7 @@ mod tests {
#[test]
fn parse_checker_test_no_prodid() {
- let c_str = CString::new(testdata::TEST_EVENT_NO_PRODID).unwrap();
+ let c_str = CString::new(testing::data::TEST_EVENT_NO_PRODID).unwrap();
unsafe {
let parsed_cal = ical::icalparser_parse_string(c_str.as_ptr());
assert!(IcalVCalendar::check_icalcomponent(parsed_cal).is_some())
@@ -505,7 +505,7 @@ mod tests {
#[test]
fn test_with_last_modified_now() {
let cal =
- IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY_LASTMODIFIED, None).unwrap();
+ IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY_LASTMODIFIED, None).unwrap();
let new_cal = cal.with_last_modified_now();
let event = new_cal.get_principal_event();
@@ -519,7 +519,7 @@ mod tests {
#[test]
fn test_with_last_modified_now_added() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let new_cal = cal.with_last_modified_now();
let event = new_cal.get_principal_event();
@@ -533,7 +533,7 @@ mod tests {
#[test]
fn test_with_location() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let location = "test";
let new_cal = cal.with_location(location);
@@ -544,7 +544,7 @@ mod tests {
//#[test]
//fn test_with_internal_timestamp() {
- //let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ //let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
//
//let timestamp = IcalTime::floating_ymd(2018, 1, 1).and_hms(11, 30, 20);
//let new_cal = cal.with_internal_timestamp(&timestamp);
@@ -556,7 +556,7 @@ mod tests {
#[test]
fn with_uid_test() {
let path = PathBuf::from("test/path");
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, Some(&path)).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, Some(&path)).unwrap();
let uid = "my_new_uid";
let new_cal = cal.with_uid(uid).unwrap();
@@ -573,7 +573,7 @@ mod tests {
#[test]
fn with_uid_multiple_test() {
let path = PathBuf::from("test/path");
- let cal = IcalVCalendar::from_str(testdata::TEST_MULTIPLE_EVENTS, Some(&path)).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_MULTIPLE_EVENTS, Some(&path)).unwrap();
let uid = "my_new_uid";
let new_cal = cal.with_uid(uid);
@@ -584,7 +584,7 @@ mod tests {
#[test]
fn with_keep_uid_test() {
let path = PathBuf::from("test/path");
- let cal = IcalVCalendar::from_str(testdata::TEST_MULTIPLE_EVENTS, Some(&path)).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_MULTIPLE_EVENTS, Some(&path)).unwrap();
for uid in &["uid1", "uid2"] {
let new_cal = cal.clone().with_keep_uid(uid);
@@ -598,7 +598,7 @@ mod tests {
#[test]
fn clone_test() {
let path = PathBuf::from("test/path");
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, Some(&path)).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, Some(&path)).unwrap();
let cal2 = cal.clone().with_uid("my_new_uid").unwrap();
assert_ne!(cal.get_uid(), cal2.get_uid());
@@ -606,7 +606,7 @@ mod tests {
#[test]
fn parse_checker_test_negative() {
- let c_str = CString::new(testdata::TEST_EVENT_NO_PRODID).unwrap();
+ let c_str = CString::new(testing::data::TEST_EVENT_NO_PRODID).unwrap();
unsafe {
let parsed_cal = ical::icalparser_parse_string(c_str.as_ptr());
assert!(IcalVCalendar::check_icalcomponent(parsed_cal).is_some())
@@ -615,7 +615,7 @@ mod tests {
#[test]
fn parse_checker_test() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
assert!(cal.check_for_errors().is_none());
}
}
diff --git a/src/vevent.rs b/src/vevent.rs
index 97d4bcc..d8b345f 100644
--- a/src/vevent.rs
+++ b/src/vevent.rs
@@ -205,12 +205,12 @@ extern "C" fn recur_callback(
#[cfg(test)]
mod tests {
use super::*;
- use crate::testdata;
+ use crate::testing;
use chrono::NaiveDate;
#[test]
fn test_get_all_properties() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
let props = event.get_properties_all();
@@ -219,7 +219,7 @@ mod tests {
#[test]
fn test_get_property_get_value() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY_ALLDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY_ALLDAY, None).unwrap();
let event = cal.get_principal_event();
let prop = event.get_properties_by_name("DTSTART");
@@ -234,7 +234,7 @@ mod tests {
#[test]
fn test_get_property_debug() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY_ALLDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY_ALLDAY, None).unwrap();
let event = cal.get_principal_event();
let prop = event
.get_property(ical::icalproperty_kind_ICAL_DTSTART_PROPERTY)
@@ -245,7 +245,7 @@ mod tests {
#[test]
fn test_get_summary() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
assert_eq!(
@@ -256,7 +256,7 @@ mod tests {
#[test]
fn test_get_summary_none() {
- let cal = IcalVCalendar::from_str(testdata::TEST_NO_SUMMARY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_NO_SUMMARY, None).unwrap();
let event = cal.get_principal_event();
assert_eq!(None, event.get_summary());
@@ -264,7 +264,7 @@ mod tests {
#[test]
fn test_get_dtstart() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
assert_eq!(
@@ -275,7 +275,7 @@ mod tests {
#[test]
fn test_get_dtstart_negative() {
- let cal = IcalVCalendar::from_str(testdata::TEST_NO_DTSTART, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_NO_DTSTART, None).unwrap();
let event = cal.get_principal_event();
assert!(event.get_dtstart().is_none());
@@ -283,7 +283,7 @@ mod tests {
#[test]
fn test_get_dtend() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
assert_eq!(
@@ -294,7 +294,7 @@ mod tests {
#[test]
fn test_get_dtend_negative() {
- let cal = IcalVCalendar::from_str(testdata::TEST_NO_DTSTART, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_NO_DTSTART, None).unwrap();
let event = cal.get_principal_event();
assert!(event.get_dtend().is_none());
@@ -302,7 +302,7 @@ mod tests {
#[test]
fn test_get_duration_internal_normal() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
assert_eq!(
@@ -313,7 +313,7 @@ mod tests {
#[test]
fn test_get_duration_normal() {
- let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY, None).unwrap();
+ let cal = IcalVCalendar::from_str(testing::data::TEST_EVENT_MULTIDAY, None).unwrap();
let event = cal.get_principal_event();
assert_eq!(
@@ -324,7 +324,7 @@ mod tests {
#[test]
fn test_get_duration_inernal_startdate_only() {
- let cal = IcalVCalendar::from_str(testdata::TEST_DTSTART_ONLY_DATE, None).unwrap();
+ let cal = Ica