#[macro_export]
macro_rules! hint {
($($arg:tt)*) => {
$crate::hints::add(|| format!($($arg)*));
}
}
#[macro_export]
macro_rules! hint_debug {
($arg:tt) => {
$crate::hints::add(|| format!("{} = {:?}", stringify!($arg), $arg));
};
}
#[macro_export]
macro_rules! hint_section {
() => {
let _block_ident = $crate::hints::Section::start();
};
($($arg:tt)*) => {
$crate::hints::add(|| format!($($arg)*));
let _block_ident = $crate::hints::Section::start();
}
}
#[macro_export]
macro_rules! stat {
($key:tt, $($arg:tt)*) => {
$crate::stats::inc($key, || format!($($arg)*))
}
}
#[macro_export]
macro_rules! stat_debug {
($arg:tt) => {
$crate::stats::inc(stringify!($arg), || format!("{:?}", $arg))
};
}
#[cfg(test)]
mod tests {
#[test]
fn macro_hint_produces_valid_code() {
if false {
hint!("foo");
hint!("bar {}", 42);
}
}
#[test]
fn macro_hint_debug_produces_valid_code() {
if false {
hint_debug!(42);
hint_debug!((0 < 20));
hint_debug!((if true { 1 } else { 2 }));
}
}
#[test]
fn macro_hint_section_produces_valid_code() {
if false {
hint_section!();
hint_section!("foo");
hint_section!("bar {}", 42);
}
}
#[test]
#[cfg(feature = "hints")]
fn macro_hint_section_produces_correct_indent() {
let (_, actual_hints) = crate::hints::collect(|| {
{
hint!("foo1");
hint_section!();
hint!("foo2");
hint_section!("bar");
hint!("foo3");
};
hint!("foo4");
});
let expected_hints = crate::hints::Hints(vec![
crate::hints::Hint {
indent: 0,
text: "foo1".to_owned(),
},
crate::hints::Hint {
indent: 1,
text: "foo2".to_owned(),
},
crate::hints::Hint {
indent: 1,
text: "bar".to_owned(),
},
crate::hints::Hint {
indent: 2,
text: "foo3".to_owned(),
},
crate::hints::Hint {
indent: 0,
text: "foo4".to_owned(),
},
]);
assert_eq!(expected_hints, actual_hints)
}
#[test]
fn macro_stat_produces_valid_code() {
if false {
stat!("A", "foo");
stat!("B", "bar {}", 42);
}
}
#[test]
fn macro_stat_debug_produces_valid_code() {
if false {
stat_debug!(42);
stat_debug!((0 < 20));
stat_debug!((if true { 1 } else { 2 }));
}
}
}