Skip to content

Instantly share code, notes, and snippets.

@jcaromiq
Created October 18, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcaromiq/4448fb78082184bbc0bba476f786635f to your computer and use it in GitHub Desktop.
Save jcaromiq/4448fb78082184bbc0bba476f786635f to your computer and use it in GitHub Desktop.
Example of a macro to parametrized test
#[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