From 59bd6e2eea151f097a65f2634dc5488b3c272d92 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Tue, 1 Dec 2020 00:10:12 +0900 Subject: Extract tests module to file in vfs crate --- crates/vfs/src/file_set.rs | 51 +--------------------------------------- crates/vfs/src/file_set/tests.rs | 42 +++++++++++++++++++++++++++++++++ crates/vfs/src/vfs_path.rs | 33 +------------------------- crates/vfs/src/vfs_path/tests.rs | 30 +++++++++++++++++++++++ 4 files changed, 74 insertions(+), 82 deletions(-) create mode 100644 crates/vfs/src/file_set/tests.rs create mode 100644 crates/vfs/src/vfs_path/tests.rs (limited to 'crates') diff --git a/crates/vfs/src/file_set.rs b/crates/vfs/src/file_set.rs index 4aa2d6526..9093fbd97 100644 --- a/crates/vfs/src/file_set.rs +++ b/crates/vfs/src/file_set.rs @@ -158,53 +158,4 @@ impl fst::Automaton for PrefixOf<'_> { } #[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]); - } -} +mod tests; diff --git a/crates/vfs/src/file_set/tests.rs b/crates/vfs/src/file_set/tests.rs new file mode 100644 index 000000000..2146df185 --- /dev/null +++ b/crates/vfs/src/file_set/tests.rs @@ -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::>(); + 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]); +} diff --git a/crates/vfs/src/vfs_path.rs b/crates/vfs/src/vfs_path.rs index 815697597..bd14911c9 100644 --- a/crates/vfs/src/vfs_path.rs +++ b/crates/vfs/src/vfs_path.rs @@ -311,35 +311,4 @@ impl VirtualPath { } #[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; diff --git a/crates/vfs/src/vfs_path/tests.rs b/crates/vfs/src/vfs_path/tests.rs new file mode 100644 index 000000000..510e021e8 --- /dev/null +++ b/crates/vfs/src/vfs_path/tests.rs @@ -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"))) + ); +} -- cgit v1.2.3