1#[macro_export]
10macro_rules! log {
11 (label: $lbl:expr, $($arg:tt)+) => {
12 $crate::println_label($lbl, std::format!($($arg)+))
13 };
14 ($($arg:tt)+) => {
15 $crate::println_label($crate::OutputLabel::default(), std::format!($($arg)*))
16 };
17}
18
19#[macro_export]
28macro_rules! error {
29 (label: $lbl:tt, $($arg:tt)+) => {
30 $crate::println_label($crate::OutputLabel::Error($lbl), std::format!($($arg)+))
31 };
32 ($($arg:tt)+) => {
33 $crate::println_label($crate::OutputLabel::Error("Error"), std::format!($($arg)+))
34 };
35}
36
37#[macro_export]
46macro_rules! warn {
47 (label: $lbl:expr, $($arg:tt)+) => {
48 $crate::println_label($crate::OutputLabel::Warning($lbl), std::format!($($arg)+))
49 };
50 ($($arg:tt)*) => {
51 $crate::println_label($crate::OutputLabel::Warning("Warn"), std::format!($($arg)*))
52 };
53}
54
55#[macro_export]
64macro_rules! info {
65 (label: $lbl:expr, $($arg:tt)+) => {
66 $crate::println_label($crate::OutputLabel::Info($lbl), std::format!($($arg)+))
67 };
68 ($($arg:tt)+) => {
69 $crate::println_label($crate::OutputLabel::Info("Info"), std::format!($($arg)+))
70 };
71}
72
73#[macro_export]
82macro_rules! success {
83 (label: $lbl:expr, $($arg:tt)+) => {
84 $crate::println_label($crate::OutputLabel::Success($lbl), std::format!($($arg)+))
85 };
86 ($($arg:tt)+) => {
87 $crate::println_label($crate::OutputLabel::Success("Success"), std::format!($($arg)+))
88 };
89}
90
91#[macro_export]
119macro_rules! format_label {
120 (label: $label:expr, $($arg:tt)+) => {
121 $crate::pretty_output($label, std::format!($($arg)+))
122 };
123 ($($arg:tt)+) => {
124 $crate::pretty_output($crate::OutputLabel::default(), std::format!($($arg)+))
125 };
126}
127
128#[cfg(test)]
129mod tests {
130 use crate::OutputLabel;
131
132 #[test]
133 fn log_macro_expand() {
134 log!("Hello, world!");
135
136 log!(label: OutputLabel::Error("Error"), "Hello");
137 }
138
139 #[test]
140 fn error_macro_expand() {
141 error!("Hello, error!");
142
143 error!(label: "Bip Bip", "alert, everything is broken");
144 }
145
146 #[test]
147 fn warn_macro_expand() {
148 warn!("Hello, warn!");
149
150 warn!(label: "Wow", "there is a bug here!");
151 }
152
153 #[test]
154 fn info_macro_expand() {
155 info!("Hello, info!");
156
157 info!(label: "Ping", "new message");
158 }
159
160 #[test]
161 fn success_macro_expand() {
162 success!("Hello, success!");
163
164 success!(label: "Nice", "you succeed!");
165 }
166
167 #[test]
168 fn format_label_macro_expand() {
169 format_label!(label: OutputLabel::Info("Hey"), "Hello, world!");
170 }
171}