summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-09 13:27:07 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-12 18:06:48 +0200
commitb0b7986cb5fce14c70fb60ae3bdf29f19953e68f (patch)
treed6ac20a3d8a21b36a5220ad599306d9af8897c01 /src
parent0371df23f690c77fd9d5e97896b9b518542019b4 (diff)
Add more convenience to the macros in the tests
Diffstat (limited to 'src')
-rw-r--r--src/timetype.rs47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/timetype.rs b/src/timetype.rs
index bcd7126..46f5cb6 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -1276,26 +1276,65 @@ mod moment_plus_amount_tests {
use chrono::Timelike;
use chrono::Datelike;
- macro_rules! generate_test_moment_plus_amount {
+ macro_rules! generate_test_moment_operator_amount{
{
name = $name:ident;
base = $base:expr;
amount = $amount:expr;
expected = $exp:expr;
+ operator = $op:expr;
} => {
#[test]
fn $name() {
let base = TT::moment($base);
- let result = (base + ($amount)).calculate();
- assert!(result.is_ok(), "Adding failed: {:?}", result);
+ let result = $op(base, $amount).calculate();
+ assert!(result.is_ok(), "Operation failed: {:?}", result);
let result = result.unwrap();
- let expected = ($exp);
+ let expected = $exp;
assert_eq!(expected, *result.get_moment().unwrap());
}
}
}
+ macro_rules! generate_test_moment_plus_amount {
+ {
+ name = $name:ident;
+ base = $base:expr;
+ amount = $amount:expr;
+ expected = $exp:expr;
+ } => {
+ generate_test_moment_operator_amount! {
+ name = $name;
+ base = $base;
+ amount = $amount;
+ expected = $exp;
+ operator = |base, amount| base + amount;
+ }
+ }
+ }
+
+ macro_rules! generate_test_moment_minus_amount {
+ {
+ name = $name:ident;
+ base = $base:expr;
+ amount = $amount:expr;
+ expected = $exp:expr;
+ } => {
+ generate_test_moment_operator_amount! {
+ name = $name;
+ base = $base;
+ amount = $amount;
+ expected = $exp;
+ operator = |base, amount| base - amount;
+ }
+ }
+ }
+
+ //
+ // tests
+ //
+
generate_test_moment_plus_amount! {
name = test_moment_plus_zero_seconds;
base = NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0);