aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_vfs/tests/vfs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_vfs/tests/vfs.rs')
-rw-r--r--crates/ra_vfs/tests/vfs.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/ra_vfs/tests/vfs.rs b/crates/ra_vfs/tests/vfs.rs
index b18ea74a3..d3271570a 100644
--- a/crates/ra_vfs/tests/vfs.rs
+++ b/crates/ra_vfs/tests/vfs.rs
@@ -1,12 +1,13 @@
1use std::{collections::HashSet, fs}; 1use std::{collections::HashSet, fs};
2 2
3// use flexi_logger::Logger; 3use flexi_logger::Logger;
4use ra_vfs::{Vfs, VfsChange}; 4use ra_vfs::{Vfs, VfsChange};
5use tempfile::tempdir; 5use tempfile::tempdir;
6 6
7fn process_tasks(vfs: &mut Vfs, num_tasks: u32) { 7fn process_tasks(vfs: &mut Vfs, num_tasks: u32) {
8 for _ in 0..num_tasks { 8 for _ in 0..num_tasks {
9 let task = vfs.task_receiver().recv().unwrap(); 9 let task = vfs.task_receiver().recv().unwrap();
10 log::debug!("{:?}", task);
10 vfs.handle_task(task); 11 vfs.handle_task(task);
11 } 12 }
12} 13}
@@ -25,7 +26,7 @@ macro_rules! assert_match {
25 26
26#[test] 27#[test]
27fn test_vfs_works() -> std::io::Result<()> { 28fn test_vfs_works() -> std::io::Result<()> {
28 // Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap(); 29 Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();
29 30
30 let files = [ 31 let files = [
31 ("a/foo.rs", "hello"), 32 ("a/foo.rs", "hello"),
@@ -114,21 +115,21 @@ fn test_vfs_works() -> std::io::Result<()> {
114 assert_eq!(path, "spam.rs") 115 assert_eq!(path, "spam.rs")
115 ); 116 );
116 117
117 fs::create_dir_all(dir.path().join("a/c")).unwrap(); 118 fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap();
118 fs::write(dir.path().join("a/c/new.rs"), "new hello").unwrap(); 119 fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap();
119 process_tasks(&mut vfs, 4); 120 process_tasks(&mut vfs, 4);
120 assert_match!( 121 assert_match!(
121 vfs.commit_changes().as_slice(), 122 vfs.commit_changes().as_slice(),
122 [VfsChange::AddFile { text, path, .. }], 123 [VfsChange::AddFile { text, path, .. }],
123 { 124 {
124 assert_eq!(text.as_str(), "new hello"); 125 assert_eq!(text.as_str(), "new hello");
125 assert_eq!(path, "c/new.rs"); 126 assert_eq!(path, "sub1/sub2/new.rs");
126 } 127 }
127 ); 128 );
128 129
129 fs::rename( 130 fs::rename(
130 &dir.path().join("a/c/new.rs"), 131 &dir.path().join("a/sub1/sub2/new.rs"),
131 &dir.path().join("a/c/new1.rs"), 132 &dir.path().join("a/sub1/sub2/new1.rs"),
132 ) 133 )
133 .unwrap(); 134 .unwrap();
134 process_tasks(&mut vfs, 4); 135 process_tasks(&mut vfs, 4);
@@ -142,18 +143,18 @@ fn test_vfs_works() -> std::io::Result<()> {
142 .. 143 ..
143 }], 144 }],
144 { 145 {
145 assert_eq!(removed_path, "c/new.rs"); 146 assert_eq!(removed_path, "sub1/sub2/new.rs");
146 assert_eq!(added_path, "c/new1.rs"); 147 assert_eq!(added_path, "sub1/sub2/new1.rs");
147 assert_eq!(text.as_str(), "new hello"); 148 assert_eq!(text.as_str(), "new hello");
148 } 149 }
149 ); 150 );
150 151
151 fs::remove_file(&dir.path().join("a/c/new1.rs")).unwrap(); 152 fs::remove_file(&dir.path().join("a/sub1/sub2/new1.rs")).unwrap();
152 process_tasks(&mut vfs, 2); 153 process_tasks(&mut vfs, 2);
153 assert_match!( 154 assert_match!(
154 vfs.commit_changes().as_slice(), 155 vfs.commit_changes().as_slice(),
155 [VfsChange::RemoveFile { path, .. }], 156 [VfsChange::RemoveFile { path, .. }],
156 assert_eq!(path, "c/new1.rs") 157 assert_eq!(path, "sub1/sub2/new1.rs")
157 ); 158 );
158 159
159 fs::create_dir_all(dir.path().join("a/target")).unwrap(); 160 fs::create_dir_all(dir.path().join("a/target")).unwrap();