Skip to main content

Add tests for a variety of static image formats

ID
49681cc
date
2024-08-20 09:15:19+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
af54866
message
Add tests for a variety of static image formats
changed files
5 files, 57 additions, 4 deletions

Changed files

README.md (489) → README.md (466)

diff --git a/README.md b/README.md
index 71d20f6..75f4d7a 100644
--- a/README.md
+++ b/README.md
@@ -7,11 +7,8 @@ focusing on a small piece of code makes it better
     -> height only
 
 * happy path:
-    -> PNG
-    -> JPEG
-    -> TIF
-    -> WebP
     -> small file
+    -> test dimensions
 
 * errors:
     -> creates thumbnail directory

src/main.rs (6144) → src/main.rs (7928)

diff --git a/src/main.rs b/src/main.rs
index 812fb63..392c8a1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -75,6 +75,62 @@ mod test_create_thumbnail {
         assert_eq!(thumbnail_path, out_dir.join("yellow.gif"));
         assert!(thumbnail_path.exists());
     }
+
+    #[test]
+    fn creates_a_png_thumbnail() {
+        let gif_path = PathBuf::from("src/tests/red.png");
+        let out_dir = test_dir();
+        let target_width = Some(16);
+        let target_height = None;
+
+        let thumbnail_path =
+            create_thumbnail(&gif_path, &out_dir, target_width, target_height).unwrap();
+
+        assert_eq!(thumbnail_path, out_dir.join("red.png"));
+        assert!(thumbnail_path.exists());
+    }
+
+    #[test]
+    fn creates_a_jpeg_thumbnail() {
+        let gif_path = PathBuf::from("src/tests/noise.jpg");
+        let out_dir = test_dir();
+        let target_width = Some(16);
+        let target_height = None;
+
+        let thumbnail_path =
+            create_thumbnail(&gif_path, &out_dir, target_width, target_height).unwrap();
+
+        assert_eq!(thumbnail_path, out_dir.join("noise.jpg"));
+        assert!(thumbnail_path.exists());
+    }
+
+    #[test]
+    fn creates_a_tif_thumbnail() {
+        let gif_path = PathBuf::from("src/tests/green.tiff");
+        let out_dir = test_dir();
+        let target_width = Some(16);
+        let target_height = None;
+
+        let thumbnail_path =
+            create_thumbnail(&gif_path, &out_dir, target_width, target_height).unwrap();
+
+        assert_eq!(thumbnail_path, out_dir.join("green.tiff"));
+        assert!(thumbnail_path.exists());
+    }
+
+    #[test]
+    fn creates_a_webp_thumbnail() {
+        let gif_path = PathBuf::from("src/tests/purple.webp");
+        let out_dir = test_dir();
+        let target_width = Some(16);
+        let target_height = None;
+
+        let thumbnail_path =
+            create_thumbnail(&gif_path, &out_dir, target_width, target_height).unwrap();
+
+        assert_eq!(thumbnail_path, out_dir.join("purple.webp"));
+        assert!(thumbnail_path.exists());
+    }
 }
 
 #[derive(Debug, Parser)]

src/tests/green.tiff (0) → src/tests/green.tiff (3574)

diff --git a/src/tests/green.tiff b/src/tests/green.tiff
new file mode 100644
index 0000000..6cd0dcf
Binary files /dev/null and b/src/tests/green.tiff differ

src/tests/noise.jpg (0) → src/tests/noise.jpg (25175)

diff --git a/src/tests/noise.jpg b/src/tests/noise.jpg
new file mode 100644
index 0000000..0998e82
Binary files /dev/null and b/src/tests/noise.jpg differ

src/tests/purple.webp (0) → src/tests/purple.webp (252)

diff --git a/src/tests/purple.webp b/src/tests/purple.webp
new file mode 100644
index 0000000..6f152ec
Binary files /dev/null and b/src/tests/purple.webp differ