Created
October 18, 2019 13:43
-
-
Save jcaromiq/4448fb78082184bbc0bba476f786635f to your computer and use it in GitHub Desktop.
Example of a macro to parametrized test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[cfg(test)] | |
mod tests { | |
#[macro_export] | |
macro_rules! parametrized { | |
($($name:ident: $value:expr,)*) => { | |
$( | |
#[test] | |
fn $name() { | |
let (input, expected) = $value; | |
assert_eq!(expected, input); | |
} | |
)* | |
} | |
} | |
parametrized! { | |
one_plus_one_will_be_two: (1+1, 2), | |
two_plus_one_will_be_three: (2+1, 3), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment