#![cfg(feature = "bake")]
use crcbl_sprite::{SampleMode, bake, crpix};
const EXAMPLE: &str = include_str!("spec_example.crpix");
#[test]
fn the_specs_worked_example_parses_and_bakes_as_documented() {
let art = match crpix::parse(EXAMPLE) {
Ok(art) => art,
Err(error) => panic!("the spec's own example does not parse: {error}"),
};
assert_eq!(art.header.width, 8);
assert_eq!(art.header.height, 6);
assert_eq!(art.header.frames, 3);
assert_eq!(art.header.colours, 5);
assert_eq!(art.header.chars, 1);
assert_eq!(art.frames.len(), 3);
assert_eq!(art.sample, SampleMode::Pixel);
let baked = bake::bake(&art, "bird.png", 60).expect("this bakes");
let decoder = png::Decoder::new(std::io::Cursor::new(&baked.png));
let mut reader = decoder.read_info().expect("a readable PNG");
let mut buffer = vec![0; reader.output_buffer_size().expect("a known size")];
let info = reader.next_frame(&mut buffer).expect("one image");
assert_eq!(
(info.width, info.height),
(24, 6),
"three 8-wide frames in a strip"
);
let json = baked.json.expect("three frames and a clip need a sidecar");
assert!(
json.contains("\"name\": \"flap\", \"from\": 0, \"to\": 2, \"direction\": \"forward\""),
"{json}"
);
assert!(
!json.contains("\"repeat\""),
"a looping clip repeats forever, which Aseprite spells as no field at all"
);
assert_eq!(
json.matches("\"duration\": 100").count(),
3,
"six ticks at 60 Hz is 100 ms, on every frame: {json}"
);
assert!(art.needs_metadata());
}