#[macro_export]
macro_rules! log {
( $val:expr $(,)? ) => {{
#[cfg(debug_assertions)]
{
if ::std::stringify!($val).starts_with("\"") {
::std::eprintln!("{}", ::std::stringify!($val).trim_matches('\"'));
} else {
::std::eprintln!("\x1B[32m{}\x1B[0m: {:?}", ::std::stringify!($val), &$val);
}
}
}};
( $($val:expr),+ $(,)? ) => {{
#[cfg(debug_assertions)]
{
$(
$crate::log!($val);
)+
}
}};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn print_string() {
log!("hello"); assert_eq!("hello", "hello.");
}
#[test]
fn print_variable() {
let animals = vec!["cat", "dog"];
log!(animals); assert_eq!("fail", "f");
}
#[test]
fn print_multiple_variables() {
let animals = vec!["cat", "dog"];
let fish = vec!["salmon", "tuna"];
log!(animals, fish);
assert_eq!("fail", "f");
}
}