dedupe animation frames handling

This commit is contained in:
2020-04-29 08:27:35 +01:00
parent 8d8515bb8a
commit 8bd323b8a0
7 changed files with 127 additions and 24 deletions

View File

@@ -45,13 +45,24 @@ impl ToString for Image {
}
}
#[inline]
pub(crate) fn animation_frames_from_string(string: String) -> Vec<Image> {
print!("animation frames: \n{}", string);
let frames: Vec<&str> = string.split(">").collect();
frames.iter().map(|&frame| Image::from(frame.to_string())).collect()
}
#[cfg(test)]
mod test {
use crate::image::Image;
use crate::image::{Image, animation_frames_from_string};
use crate::mock;
#[test]
fn test_image_from_string() {
let output = Image::from(include_str!("test-resources/image").to_string());
let output = Image::from(
include_str!("test-resources/image").to_string()
);
let expected = Image {
pixels: vec![
@@ -71,8 +82,19 @@ mod test {
#[test]
fn test_image_to_string() {
let output = crate::mock::image::chequers_1().to_string();
let output = mock::image::chequers_1().to_string();
let expected = include_str!("test-resources/image-chequers-1").to_string();
assert_eq!(output, expected);
}
#[test]
fn test_animation_frames_from_string() {
let output = animation_frames_from_string(
include_str!("test-resources/animation_frames").to_string()
);
let expected = mock::image::animation_frames();
assert_eq!(output, expected);
}
}