Skip to content

Commit

Permalink
Merge pull request #3497 from regexident/swap-assert-eq-arg-order
Browse files Browse the repository at this point in the history
Swap inconsistent `assert_eq!` argument order in testing chapter
  • Loading branch information
chriskrycho authored Jun 12, 2024
2 parents 43d198b + 9a01b7c commit 196f72f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ test tests::it_adds_two ... FAILED
failures:

---- tests::it_adds_two stdout ----
thread 'tests::it_adds_two' panicked at src/lib.rs:11:9:
assertion `left == right` failed
left: 4
right: 5
left: 5
right: 4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ mod tests {

#[test]
fn it_adds_two() {
assert_eq!(4, add_two(2));
assert_eq!(add_two(2), 4);
}
}
2 changes: 1 addition & 1 deletion src/ch11-01-writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ assertion functions are called `expected` and `actual`, and the order in which
we specify the arguments matters. However, in Rust, they’re called `left` and
`right`, and the order in which we specify the value we expect and the value
the code produces doesn’t matter. We could write the assertion in this test as
`assert_eq!(add_two(2), 4)`, which would result in the same failure message
`assert_eq!(4, add_two(2))`, which would result in the same failure message
that displays `` assertion failed: `(left == right)` ``.

The `assert_ne!` macro will pass if the two values we give it are not equal and
Expand Down

0 comments on commit 196f72f

Please sign in to comment.