From 6caa81b4ec16978aa80e005fb48e6f6342b1dabd Mon Sep 17 00:00:00 2001 From: Diazepam <77@diazepam.cc> Date: Thu, 29 Aug 2024 16:56:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dch11-01-writing-tests?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E4=B8=AD=E6=97=A0=E6=84=8F=E4=B9=89=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新到 https://github.com/rust-lang/book/commit/024ee9542d5dfa6c5fb85419033ffe7c52bdf05f --- .../no-listing-10-result-in-tests/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs index 6284f4f..c31cdca 100644 --- a/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs @@ -1,11 +1,21 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + + // ANCHOR: here #[test] fn it_works() -> Result<(), String> { - if 2 + 2 == 4 { + let result = add(2, 2); + + if result == 4 { Ok(()) } else { Err(String::from("two plus two does not equal four")) } } + // ANCHOR_END: here }