summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-02 16:12:55 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-02 16:12:55 +0200
commit75f2448d85316ea8e03248592d209549d9ba6ed3 (patch)
tree719a994f00ea77b4599f9c54a5dce81379bdbfab /src
parent430f6d2eded06ef4aca99e563d2f17819b0c2487 (diff)
Add error kinds for add/sub moment from amount
Diffstat (limited to 'src')
-rw-r--r--src/error.rs12
-rw-r--r--src/timetype.rs30
2 files changed, 42 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 116a8eb..075a8ef 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,3 +1,5 @@
+use timetype::TimeType;
+
error_chain! {
types {
KairosError, KairosErrorKind, ResultExt, Result;
@@ -16,6 +18,16 @@ error_chain! {
display("Unknown Error")
}
+ CannotAdd(a: TimeType, b: TimeType) {
+ description("Cannot add")
+ display("Cannot add: {:?} + {:?}", a, b)
+ }
+
+ CannotSub(a: TimeType, b: TimeType) {
+ description("Cannot subtract")
+ display("Cannot subtract: {:?} - {:?}", a, b)
+ }
+
}
}
diff --git a/src/timetype.rs b/src/timetype.rs
index c40b389..3ac88f2 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -98,8 +98,12 @@ fn sub(a: Box<TimeType>, b: Box<TimeType>) -> Result<TimeType> {
#[cfg(test)]
mod tests {
+ use chrono::NaiveDate;
+
use super::TimeType as TT;
+ use error::KairosErrorKind as KEK;
+
#[test]
fn test_addition_of_seconds() {
let a = TT::Seconds(0);
@@ -1028,6 +1032,32 @@ mod tests {
}
}
+ #[test]
+ fn test_add_moment_to_seconds() {
+ let a = TT::Seconds(3);
+ let b = TT::Moment(NaiveDate::from_ymd(2016, 7, 8).and_hms(9, 10, 11));
+
+ let res = (a + b).calculate();
+
+ assert!(res.is_err());
+ let res = res.unwrap_err();
+
+ assert_eq!("Cannot add", res.kind().description());
+ }
+
+ #[test]
+ fn test_subtract_moment_from_seconds() {
+ let a = TT::Seconds(3);
+ let b = TT::Moment(NaiveDate::from_ymd(2016, 7, 8).and_hms(9, 10, 11));
+
+ let res = (a - b).calculate();
+
+ assert!(res.is_err());
+ let res = res.unwrap_err();
+
+ assert_eq!("Cannot subtract", res.kind().description());
+ }
+
}