#[macro_export]
macro_rules! log {
(label: $lbl:expr, $($arg:tt)+) => {
$crate::println_label($lbl, std::format!($($arg)+))
};
($($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::default(), std::format!($($arg)*))
};
}
#[macro_export]
macro_rules! error {
(label: $lbl:tt, $($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::Error($lbl), std::format!($($arg)+))
};
($($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::Error("Error"), std::format!($($arg)+))
};
}
#[macro_export]
macro_rules! warn {
(label: $lbl:expr, $($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::Warning($lbl), std::format!($($arg)+))
};
($($arg:tt)*) => {
$crate::println_label($crate::OutputLabel::Warning("Warn"), std::format!($($arg)*))
};
}
#[macro_export]
macro_rules! info {
(label: $lbl:expr, $($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::Info($lbl), std::format!($($arg)+))
};
($($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::Info("Info"), std::format!($($arg)+))
};
}
#[macro_export]
macro_rules! success {
(label: $lbl:expr, $($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::Success($lbl), std::format!($($arg)+))
};
($($arg:tt)+) => {
$crate::println_label($crate::OutputLabel::Success("Success"), std::format!($($arg)+))
};
}
#[macro_export]
macro_rules! format_label {
(label: $label:expr, $($arg:tt)+) => {
$crate::pretty_output($label, std::format!($($arg)+))
};
($($arg:tt)+) => {
$crate::pretty_output($crate::OutputLabel::default(), std::format!($($arg)+))
};
}
#[cfg(test)]
mod tests {
use crate::OutputLabel;
#[test]
fn log_macro_expand() {
log!("Hello, world!");
log!(label: OutputLabel::Error("Error"), "Hello");
}
#[test]
fn error_macro_expand() {
error!("Hello, error!");
error!(label: "Bip Bip", "alert, everything is broken");
}
#[test]
fn warn_macro_expand() {
warn!("Hello, warn!");
warn!(label: "Wow", "there is a bug here!");
}
#[test]
fn info_macro_expand() {
info!("Hello, info!");
info!(label: "Ping", "new message");
}
#[test]
fn success_macro_expand() {
success!("Hello, success!");
success!(label: "Nice", "you succeed!");
}
#[test]
fn format_label_macro_expand() {
format_label!(label: OutputLabel::Info("Hey"), "Hello, world!");
}
}