summaryrefslogtreecommitdiff
path: root/tests/tests.rs
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2018-12-28 16:11:08 -0500
committerdfhoughton <dfhoughton@gmail.com>2018-12-28 16:11:08 -0500
commit4641db61c453f7198b24545f72c7d3e068f3f158 (patch)
tree5f087df6f80fd7dc8dac340adc569e0c97e34a0b /tests/tests.rs
parentac258192328402519e40a3717d458f426f0c297c (diff)
downloadtwo-timer-4641db61c453f7198b24545f72c7d3e068f3f158.zip
better relative time handling; added relative days
Diffstat (limited to 'tests/tests.rs')
-rw-r--r--tests/tests.rs132
1 files changed, 131 insertions, 1 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index 7539607..609d381 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -186,7 +186,7 @@ fn at_3_00_00_pm() {
fn at_3_pm_yesterday() {
let now = Utc.ymd(1969, 5, 6).and_hms(14, 0, 0);
let then = Utc.ymd(1969, 5, 5).and_hms(15, 0, 0);
- for phrase in ["3 PM", "3 pm", "15"].iter() {
+ for phrase in ["3 PM yesterday", "3 pm yesterday", "15 yesterday"].iter() {
let (start, end) = parse(phrase, Some(Config::default().now(now))).unwrap();
assert_eq!(then, start);
assert_eq!(then + Duration::hours(1), end);
@@ -651,3 +651,133 @@ fn last_monday() {
assert_eq!(d1, start);
assert_eq!(d2, end);
}
+
+#[test]
+fn dawn_of_time() {
+ let then = chrono::MIN_DATE.and_hms_milli(0, 0, 0, 0);
+ for phrase in [
+ "the beginning",
+ "the beginning of time",
+ "the first moment",
+ "the start",
+ "the very start",
+ "the first instant",
+ "the dawn of time",
+ "the big bang",
+ "the birth of the universe",
+ ]
+ .iter()
+ {
+ let (start, end) = parse(phrase, None).unwrap();
+ assert_eq!(then, start);
+ assert_eq!(then + Duration::minutes(1), end);
+ }
+}
+
+#[test]
+fn the_crack_of_doom() {
+ let then = chrono::MAX_DATE.and_hms_milli(23, 59, 59, 999);
+ for phrase in [
+ "the end",
+ "the end of time",
+ "the very end",
+ "the last moment",
+ "eternity",
+ "infinity",
+ "doomsday",
+ "the crack of doom",
+ "armageddon",
+ "ragnarok",
+ "the big crunch",
+ "the heat death of the universe",
+ "doom",
+ "death",
+ "perdition",
+ "the last hurrah",
+ "ever after",
+ "the last syllable of recorded time",
+ ]
+ .iter()
+ {
+ let (_, end) = parse(phrase, None).unwrap();
+ assert_eq!(then, end);
+ }
+}
+
+#[test]
+fn friday() {
+ let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = Utc.ymd(1969, 5, 2).and_hms(0, 0, 0);
+ let (start, end) = parse(
+ "Friday",
+ Some(Config::default().now(now)),
+ )
+ .unwrap();
+ assert_eq!(then, start);
+ assert_eq!(then + Duration::days(1), end);
+}
+
+#[test]
+fn tuesday() {
+ let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = Utc.ymd(1969, 4, 29).and_hms(0, 0, 0);
+ let (start, end) = parse(
+ "Tuesday",
+ Some(Config::default().now(now)),
+ )
+ .unwrap();
+ assert_eq!(then, start);
+ assert_eq!(then + Duration::days(1), end);
+}
+
+#[test]
+fn monday() {
+ let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = Utc.ymd(1969, 5, 5).and_hms(0, 0, 0);
+ let (start, end) = parse(
+ "Monday",
+ Some(Config::default().now(now)),
+ )
+ .unwrap();
+ assert_eq!(then, start);
+ assert_eq!(then + Duration::days(1), end);
+}
+
+#[test]
+fn friday_at_3_pm() {
+ let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = Utc.ymd(1969, 5, 2).and_hms(15, 0, 0);
+ let (start, end) = parse(
+ "Friday at 3 pm",
+ Some(Config::default().now(now)),
+ )
+ .unwrap();
+ assert_eq!(then, start);
+ assert_eq!(then + Duration::hours(1), end);
+}
+
+#[test]
+fn tuesday_at_3_pm() {
+ let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = Utc.ymd(1969, 4, 29).and_hms(15, 0, 0);
+ let (start, end) = parse(
+ "Tuesday at 3 pm",
+ Some(Config::default().now(now)),
+ )
+ .unwrap();
+ assert_eq!(then, start);
+ assert_eq!(then + Duration::hours(1), end);
+}
+
+#[test]
+fn monday_at_3_pm() {
+ let now = Utc.ymd(1969, 5, 6).and_hms(0, 0, 0);
+ let then = Utc.ymd(1969, 5, 5).and_hms(15, 0, 0);
+ let (start, end) = parse(
+ "Monday at 3 pm",
+ Some(Config::default().now(now)),
+ )
+ .unwrap();
+ assert_eq!(then, start);
+ assert_eq!(then + Duration::hours(1), end);
+} \ No newline at end of file