Merge #6679
6679: Extract tests module to file in vfs crate r=matklad a=sasurau4 Helps with #6522 - [x] passed `cargo test` Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
This commit is contained in:
commit
a8f04712d6
@ -158,53 +158,4 @@ fn accept(&self, &state: &usize, byte: u8) -> usize {
|
||||
}
|
||||
|
||||
#[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::<Vec<_>>();
|
||||
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]);
|
||||
}
|
||||
}
|
||||
mod tests;
|
||||
|
42
crates/vfs/src/file_set/tests.rs
Normal file
42
crates/vfs/src/file_set/tests.rs
Normal file
@ -0,0 +1,42 @@
|
||||
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::<Vec<_>>();
|
||||
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]);
|
||||
}
|
@ -311,35 +311,4 @@ pub(crate) fn name_and_extension(&self) -> Option<(&str, Option<&str>)> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn virtual_path_extensions() {
|
||||
assert_eq!(VirtualPath("/".to_string()).name_and_extension(), None);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory".to_string()).name_and_extension(),
|
||||
Some(("directory", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/".to_string()).name_and_extension(),
|
||||
Some(("directory", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/file".to_string()).name_and_extension(),
|
||||
Some(("file", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/.file".to_string()).name_and_extension(),
|
||||
Some((".file", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/.file.rs".to_string()).name_and_extension(),
|
||||
Some((".file", Some("rs")))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/file.rs".to_string()).name_and_extension(),
|
||||
Some(("file", Some("rs")))
|
||||
);
|
||||
}
|
||||
}
|
||||
mod tests;
|
||||
|
30
crates/vfs/src/vfs_path/tests.rs
Normal file
30
crates/vfs/src/vfs_path/tests.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn virtual_path_extensions() {
|
||||
assert_eq!(VirtualPath("/".to_string()).name_and_extension(), None);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory".to_string()).name_and_extension(),
|
||||
Some(("directory", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/".to_string()).name_and_extension(),
|
||||
Some(("directory", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/file".to_string()).name_and_extension(),
|
||||
Some(("file", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/.file".to_string()).name_and_extension(),
|
||||
Some((".file", None))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/.file.rs".to_string()).name_and_extension(),
|
||||
Some((".file", Some("rs")))
|
||||
);
|
||||
assert_eq!(
|
||||
VirtualPath("/directory/file.rs".to_string()).name_and_extension(),
|
||||
Some(("file", Some("rs")))
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user