rustlings/exercises/quiz4.rs
2022-04-24 09:37:34 +08:00

37 lines
713 B
Rust

// quiz4.rs
// This quiz covers the sections:
// - Modules
// - Macros
// Write a macro that passes the quiz! No hints this time, you can do it!
mod m {
#[macro_export]
macro_rules! my_macro {
($val:expr) => {
{
let mut s = String::from("Hello ");
s.push_str($val);
s
}
// format!("Hello {}",$val)
};
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_my_macro_world() {
my_macro!("world!");
assert_eq!(my_macro!("world!"), "Hello world!");
}
#[test]
fn test_my_macro_goodbye() {
assert_eq!(my_macro!("goodbye!"), "Hello goodbye!");
}
}