diff options
Diffstat (limited to 'crates/vfs')
-rw-r--r-- | crates/vfs/src/file_set.rs | 51 | ||||
-rw-r--r-- | crates/vfs/src/file_set/tests.rs | 42 | ||||
-rw-r--r-- | crates/vfs/src/vfs_path.rs | 33 | ||||
-rw-r--r-- | crates/vfs/src/vfs_path/tests.rs | 30 |
4 files changed, 74 insertions, 82 deletions
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<'_> { | |||
158 | } | 158 | } |
159 | 159 | ||
160 | #[cfg(test)] | 160 | #[cfg(test)] |
161 | mod tests { | 161 | mod tests; |
162 | use super::*; | ||
163 | |||
164 | #[test] | ||
165 | fn path_prefix() { | ||
166 | let mut file_set = FileSetConfig::builder(); | ||
167 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); | ||
168 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]); | ||
169 | let file_set = file_set.build(); | ||
170 | |||
171 | let mut vfs = Vfs::default(); | ||
172 | vfs.set_file_contents( | ||
173 | VfsPath::new_virtual_path("/foo/src/lib.rs".into()), | ||
174 | Some(Vec::new()), | ||
175 | ); | ||
176 | vfs.set_file_contents( | ||
177 | VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()), | ||
178 | Some(Vec::new()), | ||
179 | ); | ||
180 | vfs.set_file_contents( | ||
181 | VfsPath::new_virtual_path("/foo/bar/baz/lib.rs".into()), | ||
182 | Some(Vec::new()), | ||
183 | ); | ||
184 | vfs.set_file_contents(VfsPath::new_virtual_path("/quux/lib.rs".into()), Some(Vec::new())); | ||
185 | |||
186 | let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); | ||
187 | assert_eq!(partition, vec![2, 1, 1]); | ||
188 | } | ||
189 | |||
190 | #[test] | ||
191 | fn name_prefix() { | ||
192 | let mut file_set = FileSetConfig::builder(); | ||
193 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); | ||
194 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo-things".into())]); | ||
195 | let file_set = file_set.build(); | ||
196 | |||
197 | let mut vfs = Vfs::default(); | ||
198 | vfs.set_file_contents( | ||
199 | VfsPath::new_virtual_path("/foo/src/lib.rs".into()), | ||
200 | Some(Vec::new()), | ||
201 | ); | ||
202 | vfs.set_file_contents( | ||
203 | VfsPath::new_virtual_path("/foo-things/src/lib.rs".into()), | ||
204 | Some(Vec::new()), | ||
205 | ); | ||
206 | |||
207 | let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); | ||
208 | assert_eq!(partition, vec![1, 1, 0]); | ||
209 | } | ||
210 | } | ||
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 @@ | |||
1 | use super::*; | ||
2 | |||
3 | #[test] | ||
4 | fn path_prefix() { | ||
5 | let mut file_set = FileSetConfig::builder(); | ||
6 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); | ||
7 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]); | ||
8 | let file_set = file_set.build(); | ||
9 | |||
10 | let mut vfs = Vfs::default(); | ||
11 | vfs.set_file_contents(VfsPath::new_virtual_path("/foo/src/lib.rs".into()), Some(Vec::new())); | ||
12 | vfs.set_file_contents( | ||
13 | VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()), | ||
14 | Some(Vec::new()), | ||
15 | ); | ||
16 | vfs.set_file_contents( | ||
17 | VfsPath::new_virtual_path("/foo/bar/baz/lib.rs".into()), | ||
18 | Some(Vec::new()), | ||
19 | ); | ||
20 | vfs.set_file_contents(VfsPath::new_virtual_path("/quux/lib.rs".into()), Some(Vec::new())); | ||
21 | |||
22 | let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); | ||
23 | assert_eq!(partition, vec![2, 1, 1]); | ||
24 | } | ||
25 | |||
26 | #[test] | ||
27 | fn name_prefix() { | ||
28 | let mut file_set = FileSetConfig::builder(); | ||
29 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); | ||
30 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo-things".into())]); | ||
31 | let file_set = file_set.build(); | ||
32 | |||
33 | let mut vfs = Vfs::default(); | ||
34 | vfs.set_file_contents(VfsPath::new_virtual_path("/foo/src/lib.rs".into()), Some(Vec::new())); | ||
35 | vfs.set_file_contents( | ||
36 | VfsPath::new_virtual_path("/foo-things/src/lib.rs".into()), | ||
37 | Some(Vec::new()), | ||
38 | ); | ||
39 | |||
40 | let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); | ||
41 | assert_eq!(partition, vec![1, 1, 0]); | ||
42 | } | ||
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 { | |||
311 | } | 311 | } |
312 | 312 | ||
313 | #[cfg(test)] | 313 | #[cfg(test)] |
314 | mod tests { | 314 | mod tests; |
315 | use super::*; | ||
316 | |||
317 | #[test] | ||
318 | fn virtual_path_extensions() { | ||
319 | assert_eq!(VirtualPath("/".to_string()).name_and_extension(), None); | ||
320 | assert_eq!( | ||
321 | VirtualPath("/directory".to_string()).name_and_extension(), | ||
322 | Some(("directory", None)) | ||
323 | ); | ||
324 | assert_eq!( | ||
325 | VirtualPath("/directory/".to_string()).name_and_extension(), | ||
326 | Some(("directory", None)) | ||
327 | ); | ||
328 | assert_eq!( | ||
329 | VirtualPath("/directory/file".to_string()).name_and_extension(), | ||
330 | Some(("file", None)) | ||
331 | ); | ||
332 | assert_eq!( | ||
333 | VirtualPath("/directory/.file".to_string()).name_and_extension(), | ||
334 | Some((".file", None)) | ||
335 | ); | ||
336 | assert_eq!( | ||
337 | VirtualPath("/directory/.file.rs".to_string()).name_and_extension(), | ||
338 | Some((".file", Some("rs"))) | ||
339 | ); | ||
340 | assert_eq!( | ||
341 | VirtualPath("/directory/file.rs".to_string()).name_and_extension(), | ||
342 | Some(("file", Some("rs"))) | ||
343 | ); | ||
344 | } | ||
345 | } | ||
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 @@ | |||
1 | use super::*; | ||
2 | |||
3 | #[test] | ||
4 | fn virtual_path_extensions() { | ||
5 | assert_eq!(VirtualPath("/".to_string()).name_and_extension(), None); | ||
6 | assert_eq!( | ||
7 | VirtualPath("/directory".to_string()).name_and_extension(), | ||
8 | Some(("directory", None)) | ||
9 | ); | ||
10 | assert_eq!( | ||
11 | VirtualPath("/directory/".to_string()).name_and_extension(), | ||
12 | Some(("directory", None)) | ||
13 | ); | ||
14 | assert_eq!( | ||
15 | VirtualPath("/directory/file".to_string()).name_and_extension(), | ||
16 | Some(("file", None)) | ||
17 | ); | ||
18 | assert_eq!( | ||
19 | VirtualPath("/directory/.file".to_string()).name_and_extension(), | ||
20 | Some((".file", None)) | ||
21 | ); | ||
22 | assert_eq!( | ||
23 | VirtualPath("/directory/.file.rs".to_string()).name_and_extension(), | ||
24 | Some((".file", Some("rs"))) | ||
25 | ); | ||
26 | assert_eq!( | ||
27 | VirtualPath("/directory/file.rs".to_string()).name_and_extension(), | ||
28 | Some(("file", Some("rs"))) | ||
29 | ); | ||
30 | } | ||