Skip to content

Commit a8f0471

Browse files
bors[bot]sasurau4
andauthored
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 <[email protected]>
2 parents 14086e3 + 59bd6e2 commit a8f0471

File tree

4 files changed

+74
-82
lines changed

4 files changed

+74
-82
lines changed

crates/vfs/src/file_set.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -158,53 +158,4 @@ impl fst::Automaton for PrefixOf<'_> {
158158
}
159159

160160
#[cfg(test)]
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-
}
161+
mod tests;

crates/vfs/src/file_set/tests.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

crates/vfs/src/vfs_path.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -311,35 +311,4 @@ impl VirtualPath {
311311
}
312312

313313
#[cfg(test)]
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-
}
314+
mod tests;

crates/vfs/src/vfs_path/tests.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)