Add message argument to assert_eq
macro
This commit is contained in:
parent
4ba60aba38
commit
45a63d3ff6
2 changed files with 15 additions and 1 deletions
|
@ -94,7 +94,18 @@ macro_rules! assert_eq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
($left:expr , $right:expr, $($arg:tt)*) => ({
|
||||||
|
match (&($left), &($right)) {
|
||||||
|
(left_val, right_val) => {
|
||||||
|
if !(*left_val == *right_val) {
|
||||||
|
panic!("assertion failed: `(left == right)` \
|
||||||
|
(left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
|
||||||
|
format_args!($($arg)*))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure that a boolean expression is `true` at runtime.
|
/// Ensure that a boolean expression is `true` at runtime.
|
||||||
|
|
|
@ -16,4 +16,7 @@ pub fn main() {
|
||||||
assert_eq!("abc".to_string(),"abc".to_string());
|
assert_eq!("abc".to_string(),"abc".to_string());
|
||||||
assert_eq!(Box::new(Point{x:34}),Box::new(Point{x:34}));
|
assert_eq!(Box::new(Point{x:34}),Box::new(Point{x:34}));
|
||||||
assert_eq!(&Point{x:34},&Point{x:34});
|
assert_eq!(&Point{x:34},&Point{x:34});
|
||||||
|
assert_eq!(42, 42, "foo bar");
|
||||||
|
assert_eq!(42, 42, "a {} c", "b");
|
||||||
|
assert_eq!(42, 42, "{x}, {y}, {z}", x = 1, y = 2, z = 3);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue