diff options
Diffstat (limited to 'crates/ra_vfs/tests/vfs.rs')
-rw-r--r-- | crates/ra_vfs/tests/vfs.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/crates/ra_vfs/tests/vfs.rs b/crates/ra_vfs/tests/vfs.rs index bf44e97c5..8562c56b9 100644 --- a/crates/ra_vfs/tests/vfs.rs +++ b/crates/ra_vfs/tests/vfs.rs | |||
@@ -75,27 +75,31 @@ fn test_vfs_works() -> std::io::Result<()> { | |||
75 | } | 75 | } |
76 | 76 | ||
77 | fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap(); | 77 | fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap(); |
78 | // 2 tasks per change, HandleChange and then LoadChange | 78 | process_tasks(&mut vfs, 1); |
79 | process_tasks(&mut vfs, 2); | ||
80 | assert_match!( | 79 | assert_match!( |
81 | vfs.commit_changes().as_slice(), | 80 | vfs.commit_changes().as_slice(), |
82 | [VfsChange::ChangeFile { text, .. }], | 81 | [VfsChange::ChangeFile { text, .. }], |
83 | assert_eq!(text.as_str(), "quux") | 82 | assert_eq!(text.as_str(), "quux") |
84 | ); | 83 | ); |
85 | 84 | ||
86 | vfs.change_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string()); | 85 | vfs.add_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string()); |
87 | assert_match!( | 86 | assert_match!( |
88 | vfs.commit_changes().as_slice(), | 87 | vfs.commit_changes().as_slice(), |
89 | [VfsChange::ChangeFile { text, .. }], | 88 | [VfsChange::ChangeFile { text, .. }], |
90 | assert_eq!(text.as_str(), "m") | 89 | assert_eq!(text.as_str(), "m") |
91 | ); | 90 | ); |
92 | 91 | ||
92 | // changing file on disk while overlayed doesn't generate a VfsChange | ||
93 | fs::write(&dir.path().join("a/b/baz.rs"), "corge").unwrap(); | ||
94 | process_tasks(&mut vfs, 1); | ||
95 | assert_match!(vfs.commit_changes().as_slice(), []); | ||
96 | |||
93 | // removing overlay restores data on disk | 97 | // removing overlay restores data on disk |
94 | vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs")); | 98 | vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs")); |
95 | assert_match!( | 99 | assert_match!( |
96 | vfs.commit_changes().as_slice(), | 100 | vfs.commit_changes().as_slice(), |
97 | [VfsChange::ChangeFile { text, .. }], | 101 | [VfsChange::ChangeFile { text, .. }], |
98 | assert_eq!(text.as_str(), "quux") | 102 | assert_eq!(text.as_str(), "corge") |
99 | ); | 103 | ); |
100 | 104 | ||
101 | vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string()); | 105 | vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string()); |
@@ -117,7 +121,7 @@ fn test_vfs_works() -> std::io::Result<()> { | |||
117 | 121 | ||
118 | fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap(); | 122 | fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap(); |
119 | fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap(); | 123 | fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap(); |
120 | process_tasks(&mut vfs, 3); | 124 | process_tasks(&mut vfs, 1); |
121 | assert_match!( | 125 | assert_match!( |
122 | vfs.commit_changes().as_slice(), | 126 | vfs.commit_changes().as_slice(), |
123 | [VfsChange::AddFile { text, path, .. }], | 127 | [VfsChange::AddFile { text, path, .. }], |
@@ -132,7 +136,7 @@ fn test_vfs_works() -> std::io::Result<()> { | |||
132 | &dir.path().join("a/sub1/sub2/new1.rs"), | 136 | &dir.path().join("a/sub1/sub2/new1.rs"), |
133 | ) | 137 | ) |
134 | .unwrap(); | 138 | .unwrap(); |
135 | process_tasks(&mut vfs, 4); | 139 | process_tasks(&mut vfs, 2); |
136 | assert_match!( | 140 | assert_match!( |
137 | vfs.commit_changes().as_slice(), | 141 | vfs.commit_changes().as_slice(), |
138 | [VfsChange::RemoveFile { | 142 | [VfsChange::RemoveFile { |
@@ -150,17 +154,16 @@ fn test_vfs_works() -> std::io::Result<()> { | |||
150 | ); | 154 | ); |
151 | 155 | ||
152 | fs::remove_file(&dir.path().join("a/sub1/sub2/new1.rs")).unwrap(); | 156 | fs::remove_file(&dir.path().join("a/sub1/sub2/new1.rs")).unwrap(); |
153 | process_tasks(&mut vfs, 2); | 157 | process_tasks(&mut vfs, 1); |
154 | assert_match!( | 158 | assert_match!( |
155 | vfs.commit_changes().as_slice(), | 159 | vfs.commit_changes().as_slice(), |
156 | [VfsChange::RemoveFile { path, .. }], | 160 | [VfsChange::RemoveFile { path, .. }], |
157 | assert_eq!(path, "sub1/sub2/new1.rs") | 161 | assert_eq!(path, "sub1/sub2/new1.rs") |
158 | ); | 162 | ); |
159 | 163 | ||
160 | fs::create_dir_all(dir.path().join("a/target")).unwrap(); | ||
161 | // should be ignored | 164 | // should be ignored |
165 | fs::create_dir_all(dir.path().join("a/target")).unwrap(); | ||
162 | fs::write(&dir.path().join("a/target/new.rs"), "ignore me").unwrap(); | 166 | fs::write(&dir.path().join("a/target/new.rs"), "ignore me").unwrap(); |
163 | process_tasks(&mut vfs, 1); // 1 task because no LoadChange will happen, just HandleChange for dir creation | ||
164 | 167 | ||
165 | assert_match!( | 168 | assert_match!( |
166 | vfs.task_receiver().try_recv(), | 169 | vfs.task_receiver().try_recv(), |