dedupe animation frames handling
This commit is contained in:
28
src/image.rs
28
src/image.rs
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user