2024-11-29 22:55:01 +01:00
|
|
|
use treehouse::vfs::{entries, query, BufferedFile, Content, MemDir, ToDynDir, VPath, VPathBuf};
|
2024-11-08 14:52:32 +01:00
|
|
|
|
2024-11-16 18:33:41 +01:00
|
|
|
const HEWWO: &[u8] = b"hewwo :3";
|
|
|
|
const FWOOFEE: &[u8] = b"fwoofee -w-";
|
|
|
|
const BOOP: &[u8] = b"boop >w<";
|
2024-11-08 14:52:32 +01:00
|
|
|
|
2024-11-17 22:34:43 +01:00
|
|
|
fn vfs() -> MemDir {
|
2025-01-14 23:09:01 +01:00
|
|
|
let file1 = BufferedFile::new(Content::new("text/plain", HEWWO.to_vec()));
|
|
|
|
let file2 = BufferedFile::new(Content::new("text/plain", FWOOFEE.to_vec()));
|
|
|
|
let file3 = BufferedFile::new(Content::new("text/plain", BOOP.to_vec()));
|
2024-11-08 14:52:32 +01:00
|
|
|
|
2024-11-17 22:34:43 +01:00
|
|
|
let mut inner = MemDir::new();
|
|
|
|
inner.add(VPath::new("file3.txt"), file3.to_dyn());
|
2024-11-08 14:52:32 +01:00
|
|
|
|
2024-11-17 22:34:43 +01:00
|
|
|
let mut vfs = MemDir::new();
|
|
|
|
vfs.add(VPath::new("file1.txt"), file1.to_dyn());
|
|
|
|
vfs.add(VPath::new("file2.txt"), file2.to_dyn());
|
|
|
|
vfs.add(VPath::new("inner"), inner.to_dyn());
|
2024-11-08 14:52:32 +01:00
|
|
|
vfs
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dir() {
|
|
|
|
let vfs = vfs();
|
|
|
|
|
2024-11-29 20:03:32 +01:00
|
|
|
let mut dir = entries(&vfs, VPath::ROOT);
|
2024-11-16 18:33:41 +01:00
|
|
|
dir.sort();
|
2024-11-08 14:52:32 +01:00
|
|
|
assert_eq!(
|
2024-11-16 18:33:41 +01:00
|
|
|
dir,
|
2024-11-08 14:52:32 +01:00
|
|
|
vec![
|
2024-11-29 20:03:32 +01:00
|
|
|
VPathBuf::new("file1.txt"),
|
|
|
|
VPathBuf::new("file2.txt"),
|
|
|
|
VPathBuf::new("inner"),
|
2024-11-08 14:52:32 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-11-29 20:03:32 +01:00
|
|
|
assert!(entries(&vfs, VPath::new("file1.txt")).is_empty());
|
|
|
|
assert!(entries(&vfs, VPath::new("file2.txt")).is_empty());
|
2024-11-08 14:52:32 +01:00
|
|
|
assert_eq!(
|
2024-11-29 20:03:32 +01:00
|
|
|
entries(&vfs, VPath::new("inner")),
|
|
|
|
vec![VPathBuf::new("inner/file3.txt")]
|
2024-11-08 14:52:32 +01:00
|
|
|
);
|
|
|
|
}
|
2024-11-16 18:33:41 +01:00
|
|
|
|
|
|
|
#[test]
|
2024-11-29 20:03:32 +01:00
|
|
|
fn content() {
|
2024-11-16 18:33:41 +01:00
|
|
|
let vfs = vfs();
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-29 20:03:32 +01:00
|
|
|
query::<Content>(&vfs, VPath::new("file1.txt"))
|
|
|
|
.map(Content::bytes)
|
|
|
|
.as_deref(),
|
|
|
|
Some(HEWWO)
|
2024-11-16 18:33:41 +01:00
|
|
|
);
|
|
|
|
assert_eq!(
|
2024-11-29 20:03:32 +01:00
|
|
|
query::<Content>(&vfs, VPath::new("file2.txt"))
|
|
|
|
.map(Content::bytes)
|
|
|
|
.as_deref(),
|
2024-11-16 18:33:41 +01:00
|
|
|
Some(FWOOFEE)
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2024-11-29 20:03:32 +01:00
|
|
|
query::<Content>(&vfs, VPath::new("inner/file3.txt"))
|
|
|
|
.map(Content::bytes)
|
|
|
|
.as_deref(),
|
2024-11-16 18:33:41 +01:00
|
|
|
Some(BOOP)
|
|
|
|
);
|
|
|
|
}
|