Add tests for range type

This commit is contained in:
Matthias Beyer 2017-06-06 19:36:10 +02:00
parent fb228c65b1
commit 2b3eab31bd
3 changed files with 49 additions and 0 deletions

View file

@ -19,6 +19,9 @@ toml-query = "0.1"
lazy_static = "0.2" lazy_static = "0.2"
toml = "0.4" toml = "0.4"
[dev-dependencies]
is-match = "0.1"
[dependencies.libimagerror] [dependencies.libimagerror]
path = "../libimagerror" path = "../libimagerror"

View file

@ -26,6 +26,9 @@ extern crate toml;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagutil; extern crate libimagutil;
#[cfg(test)]
#[macro_use] extern crate is_match;
pub mod datepath; pub mod datepath;
pub mod datetime; pub mod datetime;
pub mod error; pub mod error;

View file

@ -66,3 +66,46 @@ impl DateTimeRange {
} }
#[cfg(test)]
mod tests {
use chrono::naive::datetime::NaiveDateTime;
use chrono::naive::date::NaiveDate;
use chrono::naive::time::NaiveTime;
use super::DateTimeRange;
#[test]
fn test_new_returns_error_if_start_after_end_date() {
let start = NaiveDateTime::new(
NaiveDate::from_ymd(2000, 02, 02),
NaiveTime::from_hms(12, 00, 02)
);
let end = NaiveDateTime::new(
NaiveDate::from_ymd(2000, 02, 02),
NaiveTime::from_hms(12, 00, 01)
);
let res = DateTimeRange::new(start, end);
assert!(res.is_err());
}
#[test]
fn test_new_returns_ok_if_start_is_before_end() {
let start = NaiveDateTime::new(
NaiveDate::from_ymd(2000, 02, 02),
NaiveTime::from_hms(12, 00, 01)
);
let end = NaiveDateTime::new(
NaiveDate::from_ymd(2000, 02, 02),
NaiveTime::from_hms(12, 00, 02)
);
let res = DateTimeRange::new(start, end);
assert!(res.is_ok());
}
}