From 2730ca7e76353cc7ea962d6db4f5f3b9a6d49adb Mon Sep 17 00:00:00 2001 From: Benjamin Richner Date: Tue, 23 Jun 2020 21:44:26 +0200 Subject: [PATCH] Turned clumsy if statements into matcher clause --- tests/zip_crypto.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/tests/zip_crypto.rs b/tests/zip_crypto.rs index b6a8e93b..da137cec 100644 --- a/tests/zip_crypto.rs +++ b/tests/zip_crypto.rs @@ -46,30 +46,24 @@ fn encrypted_file() { { // No password let file = archive.by_index(0); - assert!(file.is_err()); - if let Err(error) = file { - match error { - zip::result::ZipError::PasswordRequired => (), - _ => panic!( - "Expected PasswordRequired error when opening encrypted file without password" - ), - } - } else { - panic!("Error: Successfully opened encrypted file without password?!"); + match file { + Err(zip::result::ZipError::PasswordRequired) => (), + Err(_) => panic!( + "Expected PasswordRequired error when opening encrypted file without password" + ), + Ok(_) => panic!("Error: Successfully opened encrypted file without password?!"), } } { // Wrong password let file = archive.by_index_decrypt(0, b"wrong password"); - assert!(file.is_err()); - if let Err(error) = file { - match error { - zip::result::ZipError::InvalidPassword => (), - _ => panic!("Expected InvalidPassword error when opening encrypted file with wrong password"), - } - } else { - panic!("Error: Successfully opened encrypted file with wrong password?!"); + match file { + Err(zip::result::ZipError::InvalidPassword) => (), + Err(_) => panic!( + "Expected InvalidPassword error when opening encrypted file with wrong password" + ), + Ok(_) => panic!("Error: Successfully opened encrypted file with wrong password?!"), } }