Add one more test

This commit is contained in:
Aleksey Kladov 2020-07-26 11:05:28 +02:00
parent 48f9a05692
commit da65cff18b

View file

@ -148,15 +148,22 @@ impl fst::Automaton for PrefixOf<'_> {
} }
} }
#[test] #[cfg(test)]
fn test_partitioning() { mod tests {
use super::*;
#[test]
fn path_prefix() {
let mut file_set = FileSetConfig::builder(); 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".into())]);
file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]); file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]);
let file_set = file_set.build(); let file_set = file_set.build();
let mut vfs = Vfs::default(); 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/lib.rs".into()),
Some(Vec::new()),
);
vfs.set_file_contents( vfs.set_file_contents(
VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()), VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()),
Some(Vec::new()), Some(Vec::new()),
@ -169,4 +176,26 @@ fn test_partitioning() {
let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>();
assert_eq!(partition, vec![2, 1, 1]); 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::<Vec<_>>();
assert_eq!(partition, vec![1, 1, 0]);
}
} }