diff options
Diffstat (limited to 'crates/vfs/src')
-rw-r--r-- | crates/vfs/src/file_set.rs | 71 |
1 files 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<'_> { | |||
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | #[test] | 151 | #[cfg(test)] |
152 | fn test_partitioning() { | 152 | mod tests { |
153 | let mut file_set = FileSetConfig::builder(); | 153 | use super::*; |
154 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); | 154 | |
155 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]); | 155 | #[test] |
156 | let file_set = file_set.build(); | 156 | fn path_prefix() { |
157 | 157 | let mut file_set = FileSetConfig::builder(); | |
158 | let mut vfs = Vfs::default(); | 158 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); |
159 | vfs.set_file_contents(VfsPath::new_virtual_path("/foo/src/lib.rs".into()), Some(Vec::new())); | 159 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo/bar/baz".into())]); |
160 | vfs.set_file_contents( | 160 | let file_set = file_set.build(); |
161 | VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()), | 161 | |
162 | Some(Vec::new()), | 162 | let mut vfs = Vfs::default(); |
163 | ); | 163 | vfs.set_file_contents( |
164 | vfs.set_file_contents( | 164 | VfsPath::new_virtual_path("/foo/src/lib.rs".into()), |
165 | VfsPath::new_virtual_path("/foo/bar/baz/lib.rs".into()), | 165 | Some(Vec::new()), |
166 | Some(Vec::new()), | 166 | ); |
167 | ); | 167 | vfs.set_file_contents( |
168 | vfs.set_file_contents(VfsPath::new_virtual_path("/quux/lib.rs".into()), Some(Vec::new())); | 168 | VfsPath::new_virtual_path("/foo/src/bar/baz/lib.rs".into()), |
169 | 169 | Some(Vec::new()), | |
170 | let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); | 170 | ); |
171 | assert_eq!(partition, vec![2, 1, 1]); | 171 | vfs.set_file_contents( |
172 | VfsPath::new_virtual_path("/foo/bar/baz/lib.rs".into()), | ||
173 | Some(Vec::new()), | ||
174 | ); | ||
175 | vfs.set_file_contents(VfsPath::new_virtual_path("/quux/lib.rs".into()), Some(Vec::new())); | ||
176 | |||
177 | let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); | ||
178 | assert_eq!(partition, vec![2, 1, 1]); | ||
179 | } | ||
180 | |||
181 | #[test] | ||
182 | fn name_prefix() { | ||
183 | let mut file_set = FileSetConfig::builder(); | ||
184 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo".into())]); | ||
185 | file_set.add_file_set(vec![VfsPath::new_virtual_path("/foo-things".into())]); | ||
186 | let file_set = file_set.build(); | ||
187 | |||
188 | let mut vfs = Vfs::default(); | ||
189 | vfs.set_file_contents( | ||
190 | VfsPath::new_virtual_path("/foo/src/lib.rs".into()), | ||
191 | Some(Vec::new()), | ||
192 | ); | ||
193 | vfs.set_file_contents( | ||
194 | VfsPath::new_virtual_path("/foo-things/src/lib.rs".into()), | ||
195 | Some(Vec::new()), | ||
196 | ); | ||
197 | |||
198 | let partition = file_set.partition(&vfs).into_iter().map(|it| it.len()).collect::<Vec<_>>(); | ||
199 | assert_eq!(partition, vec![1, 1, 0]); | ||
200 | } | ||
172 | } | 201 | } |