From da65cff18bbdf72be64525e639590dce41f6ff14 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 26 Jul 2020 11:05:28 +0200 Subject: Add one more test --- crates/vfs/src/file_set.rs | 71 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs index e5e2ef530..e9196fcd2 100644 --- a/crates/vfs/src/file_set.rs +++ b/crates/vfs/src/file_set.rs @@ -148,25 +148,54 @@ impl fst::Automaton for PrefixOf<'_> { } } -#[test] -fn test_partitioning() { - let mut file_set = FileSetConfig::builder(); - file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); - file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]); - let file_set = file_set.build(); - - let mut vfs = Vfs::default(); - vfs.set_file_contents(VfsPath::new_virtual_path("/foo/src/lib.rs".into()), Some(Vec::new())); - vfs.set_file_contents( - VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()), - Some(Vec::new()), - ); - vfs.set_file_contents( - VfsPath::new_virtual_path("/foo/bar/baz/lib.rs".into()), - Some(Vec::new()), - ); - vfs.set_file_contents(VfsPath::new_virtual_path("/quux/lib.rs".into()), Some(Vec::new())); - - let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::>(); - assert_eq!(partition, vec![2, 1, 1]); +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn path_prefix() { + let mut file_set = FileSetConfig::builder(); + file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); + file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]); + let file_set = file_set.build(); + + let mut vfs = Vfs::default(); + vfs.set_file_contents( + VfsPath::new_virtual_path("/foo/src/lib.rs".into()), + Some(Vec::new()), + ); + vfs.set_file_contents( + VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()), + Some(Vec::new()), + ); + vfs.set_file_contents( + VfsPath::new_virtual_path("/foo/bar/baz/lib.rs".into()), + Some(Vec::new()), + ); + vfs.set_file_contents(VfsPath::new_virtual_path("/quux/lib.rs".into()), Some(Vec::new())); + + let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::>(); + assert_eq!(partition, vec![2, 1, 1]); + } + + #[test] + fn name_prefix() { + let mut file_set = FileSetConfig::builder(); + file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); + file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo-things".into())]); + let file_set = file_set.build(); + + let mut vfs = Vfs::default(); + vfs.set_file_contents( + VfsPath::new_virtual_path("/foo/src/lib.rs".into()), + Some(Vec::new()), + ); + vfs.set_file_contents( + VfsPath::new_virtual_path("/foo-things/src/lib.rs".into()), + Some(Vec::new()), + ); + + let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::>(); + assert_eq!(partition, vec![1, 1, 0]); + } } -- cgit v1.2.3