From a84611c9ae04eec8574537e432ee39c0a30df82c Mon Sep 17 00:00:00 2001 From: Joshua Holmer Date: Tue, 3 May 2016 08:03:25 -0400 Subject: [PATCH] Replace appropriate uses of assert! with assert_eq! in test suite --- tests/filters.rs | 12 +++--- tests/flags.rs | 92 ++++++++++++++++++++++----------------------- tests/interlaced.rs | 14 +++---- tests/reduction.rs | 62 +++++++++++++++--------------- 4 files changed, 90 insertions(+), 90 deletions(-) diff --git a/tests/filters.rs b/tests/filters.rs index a159043a..507f865b 100644 --- a/tests/filters.rs +++ b/tests/filters.rs @@ -58,8 +58,8 @@ fn test_it_converts(input: &Path, bit_depth_out: png::BitDepth) { let png = png::PngData::new(input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == color_type_in); - assert!(png.ihdr_data.bit_depth == bit_depth_in); + assert_eq!(png.ihdr_data.color_type, color_type_in); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_in); match oxipng::optimize(input, opts) { Ok(_) => (), @@ -75,15 +75,15 @@ fn test_it_converts(input: &Path, } }; - assert!(png.ihdr_data.color_type == color_type_out); - assert!(png.ihdr_data.bit_depth == bit_depth_out); + assert_eq!(png.ihdr_data.color_type, color_type_out); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_out); let old_png = image::open(input).unwrap(); let new_png = image::open(output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } diff --git a/tests/flags.rs b/tests/flags.rs index 884a3d81..046f2c2c 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -58,8 +58,8 @@ fn test_it_converts(input: &Path, bit_depth_out: png::BitDepth) { let png = png::PngData::new(input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == color_type_in); - assert!(png.ihdr_data.bit_depth == bit_depth_in); + assert_eq!(png.ihdr_data.color_type, color_type_in); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_in); match oxipng::optimize(input, opts) { Ok(_) => (), @@ -75,15 +75,15 @@ fn test_it_converts(input: &Path, } }; - assert!(png.ihdr_data.color_type == color_type_out); - assert!(png.ihdr_data.bit_depth == bit_depth_out); + assert_eq!(png.ihdr_data.color_type, color_type_out); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_out); let old_png = image::open(input).unwrap(); let new_png = image::open(output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -139,8 +139,8 @@ fn strip_headers_list() { let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -180,8 +180,8 @@ fn strip_headers_safe() { let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -221,8 +221,8 @@ fn strip_headers_all() { let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -262,8 +262,8 @@ fn strip_headers_none() { let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -277,7 +277,7 @@ fn interlacing_0_to_1() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.interlaced == 0); + assert_eq!(png.ihdr_data.interlaced, 0); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -293,14 +293,14 @@ fn interlacing_0_to_1() { } }; - assert!(png.ihdr_data.interlaced == 1); + assert_eq!(png.ihdr_data.interlaced, 1); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -314,7 +314,7 @@ fn interlacing_1_to_0() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.interlaced == 1); + assert_eq!(png.ihdr_data.interlaced, 1); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -330,14 +330,14 @@ fn interlacing_1_to_0() { } }; - assert!(png.ihdr_data.interlaced == 0); + assert_eq!(png.ihdr_data.interlaced, 0); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -351,9 +351,9 @@ fn interlacing_0_to_1_small_files() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.interlaced == 0); - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + assert_eq!(png.ihdr_data.interlaced, 0); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -369,16 +369,16 @@ fn interlacing_0_to_1_small_files() { } }; - assert!(png.ihdr_data.interlaced == 1); - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + assert_eq!(png.ihdr_data.interlaced, 1); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::One); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -392,9 +392,9 @@ fn interlacing_1_to_0_small_files() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.interlaced == 1); - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + assert_eq!(png.ihdr_data.interlaced, 1); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -410,16 +410,16 @@ fn interlacing_1_to_0_small_files() { } }; - assert!(png.ihdr_data.interlaced == 0); - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::One); + assert_eq!(png.ihdr_data.interlaced, 0); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::One); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -436,7 +436,7 @@ fn interlaced_0_to_1_other_filter_mode() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.interlaced == 0); + assert_eq!(png.ihdr_data.interlaced, 0); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -452,14 +452,14 @@ fn interlaced_0_to_1_other_filter_mode() { } }; - assert!(png.ihdr_data.interlaced == 1); + assert_eq!(png.ihdr_data.interlaced, 1); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -491,8 +491,8 @@ fn fix_errors() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == png::ColorType::RGBA); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + assert_eq!(png.ihdr_data.color_type, png::ColorType::RGBA); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -508,8 +508,8 @@ fn fix_errors() { } }; - assert!(png.ihdr_data.color_type == png::ColorType::Grayscale); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Grayscale); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); // Cannot check if pixels are equal because image crate cannot read corrupt (input) PNGs remove_file(output).ok(); diff --git a/tests/interlaced.rs b/tests/interlaced.rs index 4803b58b..564db747 100644 --- a/tests/interlaced.rs +++ b/tests/interlaced.rs @@ -58,9 +58,9 @@ fn test_it_converts(input: &Path, bit_depth_out: png::BitDepth) { let png = png::PngData::new(input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == color_type_in); - assert!(png.ihdr_data.bit_depth == bit_depth_in); - assert!(png.ihdr_data.interlaced == 1); + assert_eq!(png.ihdr_data.color_type, color_type_in); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_in); + assert_eq!(png.ihdr_data.interlaced, 1); match oxipng::optimize(input, opts) { Ok(_) => (), @@ -76,15 +76,15 @@ fn test_it_converts(input: &Path, } }; - assert!(png.ihdr_data.color_type == color_type_out); - assert!(png.ihdr_data.bit_depth == bit_depth_out); + assert_eq!(png.ihdr_data.color_type, color_type_out); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_out); let old_png = image::open(input).unwrap(); let new_png = image::open(output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } diff --git a/tests/reduction.rs b/tests/reduction.rs index 72338a79..a694ea48 100644 --- a/tests/reduction.rs +++ b/tests/reduction.rs @@ -58,9 +58,9 @@ fn test_it_converts(input: &Path, bit_depth_out: png::BitDepth) { let png = png::PngData::new(input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == color_type_in); - assert!(png.ihdr_data.bit_depth == bit_depth_in); - assert!(png.ihdr_data.interlaced == 0); + assert_eq!(png.ihdr_data.color_type, color_type_in); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_in); + assert_eq!(png.ihdr_data.interlaced, 0); match oxipng::optimize(input, opts) { Ok(_) => (), @@ -76,15 +76,15 @@ fn test_it_converts(input: &Path, } }; - assert!(png.ihdr_data.color_type == color_type_out); - assert!(png.ihdr_data.bit_depth == bit_depth_out); + assert_eq!(png.ihdr_data.color_type, color_type_out); + assert_eq!(png.ihdr_data.bit_depth, bit_depth_out); let old_png = image::open(input).unwrap(); let new_png = image::open(output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -1283,9 +1283,9 @@ fn palette_should_be_reduced_with_dupes() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - assert!(png.palette.unwrap().len() == 43 * 3); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); + assert_eq!(png.palette.unwrap().len(), 43 * 3); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -1301,16 +1301,16 @@ fn palette_should_be_reduced_with_dupes() { } }; - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - assert!(png.palette.unwrap().len() == 35 * 3); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); + assert_eq!(png.palette.unwrap().len(), 35 * 3); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -1323,9 +1323,9 @@ fn palette_should_be_reduced_with_unused() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - assert!(png.palette.unwrap().len() == 35 * 3); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); + assert_eq!(png.palette.unwrap().len(), 35 * 3); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -1341,16 +1341,16 @@ fn palette_should_be_reduced_with_unused() { } }; - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - assert!(png.palette.unwrap().len() == 33 * 3); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); + assert_eq!(png.palette.unwrap().len(), 33 * 3); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); } @@ -1363,9 +1363,9 @@ fn palette_should_be_reduced_with_both() { let png = png::PngData::new(&input, opts.fix_errors).unwrap(); - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - assert!(png.palette.unwrap().len() == 43 * 3); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); + assert_eq!(png.palette.unwrap().len(), 43 * 3); match oxipng::optimize(&input, &opts) { Ok(_) => (), @@ -1381,16 +1381,16 @@ fn palette_should_be_reduced_with_both() { } }; - assert!(png.ihdr_data.color_type == png::ColorType::Indexed); - assert!(png.ihdr_data.bit_depth == png::BitDepth::Eight); - assert!(png.palette.unwrap().len() == 33 * 3); + assert_eq!(png.ihdr_data.color_type, png::ColorType::Indexed); + assert_eq!(png.ihdr_data.bit_depth, png::BitDepth::Eight); + assert_eq!(png.palette.unwrap().len(), 33 * 3); let old_png = image::open(&input).unwrap(); let new_png = image::open(&output).unwrap(); // Conversion should be lossless - assert!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>() == - new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); + assert_eq!(old_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>(), + new_png.pixels().map(|x| x.2.channels().to_owned()).collect::>>()); remove_file(output).ok(); }