From 0f42f297f4abdf909fad8cb4e3f79b4ac5be84cf Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 24 Oct 2023 22:18:28 -0400 Subject: [PATCH] bh: Add tests for DirEntry --- src/dir.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/dir.rs b/src/dir.rs index 8f16890e..08c504b1 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -124,3 +124,31 @@ impl DirectoryIndex { std::str::from_utf8(&self.name).unwrap().to_string() } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn no_invalid_dir_entry() { + // just root + let dir = DirEntry { + offset: 0x300, + inode_offset: 0x0, + t: InodeId::BasicDirectory, + name_size: 0x1, + name: b"/".to_vec(), + }; + assert_eq!(Path::new("/"), dir.name().unwrap()); + + // InvalidFilePath + let dir = DirEntry { + offset: 0x300, + inode_offset: 0x0, + t: InodeId::BasicDirectory, + name_size: 0x1, + name: b"/nice/".to_vec(), + }; + assert!(dir.name().is_err()); + } +}