Skip to content

Commit

Permalink
docs: add example for test_each macro
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn committed Apr 16, 2024
1 parent b0e51d8 commit 06e6d16
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/utils/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/// ### Example
///
/// ```rust
/// use crate::utils::tests::test_each;
///
/// fn add(a: i8, b: i8) -> i8 { a + b }
///
/// struct TestCase {
/// input: (i8, i8),
/// expected: i8,
/// }
///
/// test_each!(
/// test_add,
/// |case: TestCase| {
/// assert_eq!(
/// add(case.input.0, case.input.1),
/// case.expected
/// );
/// },
/// "1" => TestCase { input: (1, 2), expected: 3, },
/// "2" => TestCase { input: (4, 4), expected: 8, },
/// );
/// ```
#[macro_export]
macro_rules! test_each {
($name:ident, $fn:expr, $($suffix:expr => $case:expr,)*) => {
Expand Down

0 comments on commit 06e6d16

Please sign in to comment.