diff --git a/src/dir.rs b/src/dir.rs index c7a6d72..845ea2d 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -610,3 +610,23 @@ impl<'a> Iterator for LfnEntriesGenerator<'a> { // name_parts_iter is ExactSizeIterator so size_hint returns one limit #[cfg(feature = "alloc")] impl<'a> ExactSizeIterator for LfnEntriesGenerator<'a> {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_split_path() { + assert_eq!(split_path("aaa/bbb/ccc"), ("aaa", Some("bbb/ccc"))); + assert_eq!(split_path("aaa/bbb"), ("aaa", Some("bbb"))); + assert_eq!(split_path("aaa"), ("aaa", None)); + } + + #[test] + fn test_generate_short_name() { + assert_eq!(&generate_short_name("Foo"), "FOO ".as_bytes()); + assert_eq!(&generate_short_name("Foo.b"), "FOO B ".as_bytes()); + assert_eq!(&generate_short_name("Foo.baR"), "FOO BAR".as_bytes()); + assert_eq!(&generate_short_name("Foo+1.baR"), "FOO?1 BAR".as_bytes()); + } +} diff --git a/src/dir_entry.rs b/src/dir_entry.rs index d27852a..4842878 100644 --- a/src/dir_entry.rs +++ b/src/dir_entry.rs @@ -707,3 +707,22 @@ impl <'a, 'b> fmt::Debug for DirEntry<'a, 'b> { self.data.fmt(f) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn short_name_with_ext() { + let mut raw_short_name = [0u8;11]; + raw_short_name.copy_from_slice("FOO BAR".as_bytes()); + assert_eq!(ShortName::new(&raw_short_name).to_str(), "FOO.BAR"); + } + + #[test] + fn short_name_without_ext() { + let mut raw_short_name = [0u8;11]; + raw_short_name.copy_from_slice("FOO ".as_bytes()); + assert_eq!(ShortName::new(&raw_short_name).to_str(), "FOO"); + } +}