From b1c17aba624a771de855f48164edb20defec7959 Mon Sep 17 00:00:00 2001 From: Chris Simpkins Date: Wed, 28 Jul 2021 11:10:52 -0400 Subject: [PATCH] [font] update unit test approach to use matches! macro tests on Error types --- src/font.rs | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/font.rs b/src/font.rs index a2edbb82..af0b0d0d 100644 --- a/src/font.rs +++ b/src/font.rs @@ -449,11 +449,7 @@ mod tests { fn loading_invalid_ufo_dir_path() { let path = "totally/bogus/filepath/font.ufo"; let font_load_res = Font::load(path); - match font_load_res { - Ok(_) => panic!("unxpected Ok result"), - Err(Error::MissingUfoDir(_)) => (), // expected value - _ => panic!("incorrect error type returned"), - } + assert!(matches!(font_load_res, Err(Error::MissingUfoDir(_)))); } #[test] @@ -462,11 +458,7 @@ mod tests { // This should raise an error let path = "testdata/ufo/Tester-MissingMetaInfo.ufo"; let font_load_res = Font::load(path); - match font_load_res { - Ok(_) => panic!("unxpected Ok result"), - Err(Error::MissingFile(_)) => (), // expected value - _ => panic!("incorrect error type returned"), - } + assert!(matches!(font_load_res, Err(Error::MissingFile(_)))); } #[test] @@ -475,11 +467,7 @@ mod tests { // This should raise an error let path = "testdata/ufo/Tester-MissingLayerContents.ufo"; let font_load_res = Font::load(path); - match font_load_res { - Ok(_) => panic!("unxpected Ok result"), - Err(Error::MissingFile(_)) => (), // expected value - _ => panic!("incorrect error type returned"), - } + assert!(matches!(font_load_res, Err(Error::MissingFile(_)))); } #[test] @@ -488,11 +476,7 @@ mod tests { // directory. This should raise an error let path = "testdata/ufo/Tester-MissingGlyphsContents.ufo"; let font_load_res = Font::load(path); - match font_load_res { - Ok(_) => panic!("unxpected Ok result"), - Err(Error::MissingFile(_)) => (), // expected value - _ => panic!("incorrect error type returned"), - } + assert!(matches!(font_load_res, Err(Error::MissingFile(_)))); } #[test] @@ -501,11 +485,7 @@ mod tests { // but not in the glyphs.background directory. This should raise an error let path = "testdata/ufo/Tester-MissingGlyphsContents-BackgroundLayer.ufo"; let font_load_res = Font::load(path); - match font_load_res { - Ok(_) => panic!("unxpected Ok result"), - Err(Error::MissingFile(_)) => (), // expected value - _ => panic!("incorrect error type returned"), - } + assert!(matches!(font_load_res, Err(Error::MissingFile(_)))); } #[test]