added str and bytes mode

This commit is contained in:
2025-07-28 20:44:32 +02:00
parent 41ec4d31a4
commit d025c3c120
2 changed files with 79 additions and 24 deletions

View File

@@ -2,27 +2,28 @@ use dir_embed::Embed;
#[derive(Embed)]
#[dir = "./../testdata/"]
#[mode = "bytes"]
pub struct Assets;
#[test]
fn get() {
fn byte_get() {
assert!(Assets::get("file1.txt").is_some());
}
#[test]
fn get_missing() {
fn byte_get_missing() {
assert!(Assets::get("missing.txt").is_none());
}
#[test]
fn read_content() {
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 parse_string() {
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");
@@ -31,14 +32,13 @@ fn parse_string() {
}
#[test]
fn sub_directories_get() {
fn byte_sub_directories_get() {
assert!(Assets::get("sub/file2.txt").is_some());
}
#[test]
fn sub_directories_content() {
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);
}