Skip to content

Commit 2cd72c6

Browse files
committed
tests: add sprite validation tests
1 parent abb1e01 commit 2cd72c6

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

martin-core/src/resources/sprites/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,51 @@ mod tests {
366366
insta::assert_binary_snapshot!(&format!("{filename}.png"), png);
367367
}
368368
}
369+
370+
#[tokio::test]
371+
async fn test_directory_not_found() {
372+
let mut sprites = SpriteSources::default();
373+
let result = sprites.add_source("nothere".to_string(), PathBuf::from("/path/to/nowhere"));
374+
assert!(matches!(result, Err(SpriteError::DirectoryNotFound(..))));
375+
}
376+
377+
#[tokio::test]
378+
async fn test_not_a_directory() {
379+
let mut sprites = SpriteSources::default();
380+
let result = sprites.add_source(
381+
"notadir".to_string(),
382+
PathBuf::from("../tests/fixtures/sprites/notsrc2/ferris.png"),
383+
);
384+
assert!(matches!(result, Err(SpriteError::NotADirectory(..))));
385+
}
386+
387+
#[tokio::test]
388+
async fn test_empty_directory() {
389+
let sprites = SpriteSources::default();
390+
let result = sprites
391+
.validate_source_directory(&PathBuf::from("../tests/fixtures/sprites/notsrc1"))
392+
.await;
393+
assert!(matches!(result, Err(SpriteError::EmptyDirectory(..))));
394+
}
395+
396+
#[tokio::test]
397+
async fn test_sprite_source_scan() {
398+
use crate::sprites::SpriteSources;
399+
let result =
400+
SpriteSources::scan_directory_files(&PathBuf::from("../tests/fixtures/sprites/notsrc2"))
401+
.await;
402+
assert_eq!(result.as_ref().unwrap().0, 2);
403+
assert_eq!(result.unwrap().1, 0);
404+
}
405+
406+
#[tokio::test]
407+
async fn test_empty_file() {
408+
use crate::sprites::SpriteSources;
409+
let sprites = SpriteSources::default();
410+
let result = SpriteSources::validate_svg_file(
411+
&sprites,
412+
&PathBuf::from("../tests/fixtures/sprites/notsrc2/notasprite.txt"),
413+
)
414+
.await;
415+
assert!(matches!(result, Err(SpriteError::EmptyFile(..))));
416+
}
59.9 KB
Loading

tests/fixtures/sprites/notsrc2/notasprite.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)