embed-dir/tests/byte.rs

44 lines
956 B
Rust

use dir_embed::Embed;
#[derive(Embed)]
#[dir = "./../testdata/"]
#[mode = "bytes"]
pub struct Assets;
#[test]
fn byte_get() {
assert!(Assets::get("file1.txt").is_some());
}
#[test]
fn byte_get_missing() {
assert!(Assets::get("missing.txt").is_none());
}
#[test]
fn byte_read_content() {
let content_should = "file1".as_bytes();
let content_is = Assets::get("file1.txt").unwrap();
assert_eq!(*content_is, *content_should);
}
#[test]
fn byte_parse_string() {
let file: &[u8] = Assets::get("file1.txt").expect("Can't find file");
let string = str::from_utf8(file).expect("Failed to parse file");
assert_eq!(string, "file1");
}
#[test]
fn byte_sub_directories_get() {
assert!(Assets::get("sub/file2.txt").is_some());
}
#[test]
fn byte_sub_directories_content() {
let content_should = "file2".as_bytes();
let content_is = Assets::get("sub/file2.txt").unwrap();
assert_eq!(*content_is, *content_should);
}