use chrono::prelude::*; use mj::core::JustDate; #[test] fn parse_today() { let x = JustDate::parse(&"today".to_owned()); assert_eq!(true, x.is_some()); } #[test] fn parse_date() { let data = vec![ ("2019-09-04", Utc.ymd(2019, 9, 4)), ("2000-01-01", Utc.ymd(2000, 1, 1)), ("9999-12-01", Utc.ymd(9999, 12, 1)), ]; for (input, expected) in data { let value = JustDate::parse(&input.to_owned()); assert_eq!(true, value.is_some()); assert_eq!(expected, value.unwrap().date()); } } #[test] fn fail_to_parse_date() { let data = vec![ ("2019-00-00"), ]; for input in data { let value = JustDate::parse(&input.to_owned()); assert_eq!(true, value.is_none()); } } #[test] fn parse_relative_date() { let data = vec![ ("1d"), ("15d"), ("150d"), ("1500d"), ]; for input in data { let value = JustDate::parse(&input.to_owned()); assert_eq!(true, value.is_some()); } }