Skip to main content

Handle an uppercase .gif extension

ID
fc4f273
date
2021-11-29 23:23:26+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
5a0c2e7
message
Handle an uppercase .gif extension
changed files
2 files, 16 additions, 11 deletions

Changed files

src/main.rs (7614) → src/main.rs (8278)

diff --git a/src/main.rs b/src/main.rs
index 19b34be..c578100 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -45,7 +45,9 @@ fn main() {
     // See https://github.com/clap-rs/clap/blob/v2.33.1/examples/12_typed_values.rs
     let max_colours = value_t!(matches, "MAX-COLOURS", usize).unwrap_or_else(|e| e.exit());
 
-    let img_bytes = if path.ends_with(".gif") {
+    // There's different code for fetching bytes from GIF images because
+    // GIFs are often animated, and we want a selection of frames.
+    let img_bytes = if path.to_lowercase().ends_with(".gif") {
         get_bytes::get_bytes_for_gif(path)
     } else {
         get_bytes::get_bytes_for_image(path)
@@ -157,6 +159,12 @@ mod tests {
         assert_eq!(output.stdout.matches("\n").count(), 8, "stdout = {:?}", output.stdout);
     }
 
+    // The image created in the next two tests was created with the
+    // following command:
+    //
+    //      convert -delay 200 -loop 10 -dispose previous red.png blue.png red.png blue.png red.png blue.png red.png blue.png animated_squares.gif
+    //
+
     #[test]
     fn it_looks_at_multiple_frames_in_an_animated_gif() {
         let output = get_success(&["./src/tests/animated_squares.gif"]);
@@ -165,6 +173,13 @@ mod tests {
     }
 
     #[test]
+    fn it_looks_at_multiple_frames_in_an_animated_gif_uppercase() {
+        let output = get_success(&["./src/tests/animated_squares.GIF"]);
+
+        assert_eq!(output.stdout.matches("\n").count(), 2, "stdout = {:?}", output.stdout);
+    }
+
+    #[test]
     fn it_fails_if_you_pass_an_invalid_max_colours() {
         let output = get_failure(&["./src/tests/red.png", "--max-colours=NaN"]);
 

src/tests/README.md (403) → src/tests/README.md (0)

diff --git a/src/tests/README.md b/src/tests/README.md
deleted file mode 100644
index 8835520..0000000
--- a/src/tests/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-# test images
-
-The animated GIF was created with the following command:
-
-```console
-$ convert -delay 200 -loop 10 -dispose previous red.png blue.png red.png blue.png red.png blue.png red.png blue.png animated_squares.gif
-```
-
-The 2-second delay is to avoid causing seizures from the flashing.
-I don't expect anyone else to be looking at the gif, but the delay is arbitrary so it's easy enough to avoid.