summaryrefslogtreecommitdiff
path: root/tests/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tests.rs')
-rw-r--r--tests/tests.rs108
1 files changed, 107 insertions, 1 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index ae1126e..c2eb23a 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1,6 +1,6 @@
#![feature(test)]
extern crate two_timer;
-use two_timer::{parsable, parse, Config};
+use two_timer::{parsable, parse, Config, TimeError};
extern crate chrono;
use chrono::naive::NaiveDate;
use chrono::{Duration, Local};
@@ -422,6 +422,16 @@ fn this_week() {
}
#[test]
+fn the_week() {
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let d1 = NaiveDate::from_ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
+ let (start, end, _) = parse("the week", Some(Config::new().now(now))).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
fn next_week() {
let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
let d1 = NaiveDate::from_ymd(1969, 5, 12).and_hms(0, 0, 0);
@@ -1428,6 +1438,17 @@ fn noon() {
assert!(false, "didn't match");
}
}
+ let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
+ match parse("noon on May 6, 1969", Some(Config::new().now(now))) {
+ Ok((start, end, _)) => {
+ assert_eq!(d1, start, "'noon' is the same as 'noon today'");
+ assert_eq!(d2, end);
+ }
+ Err(e) => {
+ println!("{:?}", e);
+ assert!(false, "didn't match");
+ }
+ }
}
#[test]
@@ -1596,3 +1617,88 @@ fn relative_time_regression() {
parse("24", None).unwrap();
assert!(true, "'24' didn't cause a panic");
}
+
+#[test]
+fn since_yesterday() {
+ let then = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);
+ let now = then + Duration::hours(5);
+ match parse("since yesterday", Some(Config::new().now(now))) {
+ Ok((start, end, two_times)) => {
+ assert!(!two_times, "isn't a two-time expression");
+ assert!(then == start);
+ assert!(now == end);
+ }
+ Err(e) => {
+ println!("{:?}", e);
+ assert!(false, "didn't match");
+ }
+ }
+}
+
+#[test]
+fn since_noon() {
+ let then = NaiveDate::from_ymd(1969, 5, 10).and_hms(12, 0, 0);
+ let now = then + Duration::hours(5);
+ for expr in &[
+ "since noon",
+ "since noon today",
+ "since 12",
+ "since 12am",
+ "since 12am today",
+ "since 12:00",
+ "since 12:00:00",
+ ] {
+ match parse(expr, Some(Config::new().now(now))) {
+ Ok((start, end, two_times)) => {
+ assert!(!two_times, "isn't a two-time expression");
+ assert!(then == start);
+ assert!(now == end);
+ }
+ Err(e) => {
+ println!("{:?}", e);
+ assert!(false, "didn't match");
+ }
+ }
+ }
+}
+
+#[test]
+fn since_may() {
+ let then = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let now = then + Duration::hours(5);
+ for expr in &[
+ "since may",
+ "since the start of may",
+ "since the beginning of may",
+ "after may",
+ "after the start of may",
+ "after the beginning of may",
+ ] {
+ match parse(expr, Some(Config::new().now(now))) {
+ Ok((start, end, two_times)) => {
+ assert!(!two_times, "isn't a two-time expression");
+ assert!(then == start);
+ assert!(now == end);
+ }
+ Err(e) => {
+ println!("{:?}", e);
+ assert!(false, "didn't match");
+ }
+ }
+ }
+}
+
+#[test]
+fn since_the_end_of_may_misordered() {
+ let then = NaiveDate::from_ymd(1969, 5, 1).and_hms(0, 0, 0);
+ let now = then + Duration::hours(5);
+ for expr in &["since the end of may", "after the end of may"] {
+ match parse(expr, Some(Config::new().now(now))) {
+ Ok((..)) => assert!(false, "this should not succeed"),
+ Err(e) => match e {
+ TimeError::Misordered(_) => assert!(true, "correct error"),
+ _ => assert!(false, format!("unexpected error: {:?}", e)),
+ },
+ }
+ }
+}