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.rs35
1 files changed, 14 insertions, 21 deletions
diff --git a/crates/ra_vfs/tests/vfs.rs b/crates/ra_vfs/tests/vfs.rs
index 21d5633b1..9cde2bed7 100644
--- a/crates/ra_vfs/tests/vfs.rs
+++ b/crates/ra_vfs/tests/vfs.rs
@@ -4,6 +4,13 @@ use 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) {
8 for _ in 0..num_tasks {
9 let task = vfs.task_receiver().recv().unwrap();
10 vfs.handle_task(task);
11 }
12}
13
7#[test] 14#[test]
8fn test_vfs_works() -> std::io::Result<()> { 15fn test_vfs_works() -> std::io::Result<()> {
9 Logger::with_str("debug").start().unwrap(); 16 Logger::with_str("debug").start().unwrap();
@@ -25,10 +32,7 @@ fn test_vfs_works() -> std::io::Result<()> {
25 let b_root = dir.path().join("a/b"); 32 let b_root = dir.path().join("a/b");
26 33
27 let (mut vfs, _) = Vfs::new(vec![a_root, b_root]); 34 let (mut vfs, _) = Vfs::new(vec![a_root, b_root]);
28 for _ in 0..2 { 35 process_tasks(&mut vfs, 2);
29 let task = vfs.task_receiver().recv().unwrap();
30 vfs.handle_task(task);
31 }
32 { 36 {
33 let files = vfs 37 let files = vfs
34 .commit_changes() 38 .commit_changes()
@@ -57,30 +61,26 @@ fn test_vfs_works() -> std::io::Result<()> {
57 assert_eq!(files, expected_files); 61 assert_eq!(files, expected_files);
58 } 62 }
59 63
60 // on disk change
61 fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap(); 64 fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap();
62 let task = vfs.task_receiver().recv().unwrap(); 65 process_tasks(&mut vfs, 1);
63 vfs.handle_task(task);
64 match vfs.commit_changes().as_slice() { 66 match vfs.commit_changes().as_slice() {
65 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"), 67 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"),
66 _ => panic!("unexpected changes"), 68 _ => panic!("unexpected changes"),
67 } 69 }
68 70
69 // in memory change
70 vfs.change_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string()); 71 vfs.change_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string());
71 match vfs.commit_changes().as_slice() { 72 match vfs.commit_changes().as_slice() {
72 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "m"), 73 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "m"),
73 _ => panic!("unexpected changes"), 74 _ => panic!("unexpected changes"),
74 } 75 }
75 76
76 // in memory remove, restores data on disk 77 // removing overlay restores data on disk
77 vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs")); 78 vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs"));
78 match vfs.commit_changes().as_slice() { 79 match vfs.commit_changes().as_slice() {
79 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"), 80 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"),
80 _ => panic!("unexpected changes"), 81 _ => panic!("unexpected changes"),
81 } 82 }
82 83
83 // in memory add
84 vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string()); 84 vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string());
85 match vfs.commit_changes().as_slice() { 85 match vfs.commit_changes().as_slice() {
86 [VfsChange::AddFile { text, path, .. }] => { 86 [VfsChange::AddFile { text, path, .. }] => {
@@ -90,17 +90,14 @@ fn test_vfs_works() -> std::io::Result<()> {
90 _ => panic!("unexpected changes"), 90 _ => panic!("unexpected changes"),
91 } 91 }
92 92
93 // in memory remove
94 vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs")); 93 vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs"));
95 match vfs.commit_changes().as_slice() { 94 match vfs.commit_changes().as_slice() {
96 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "spam.rs"), 95 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "spam.rs"),
97 _ => panic!("unexpected changes"), 96 _ => panic!("unexpected changes"),
98 } 97 }
99 98
100 // on disk add
101 fs::write(&dir.path().join("a/new.rs"), "new hello").unwrap(); 99 fs::write(&dir.path().join("a/new.rs"), "new hello").unwrap();
102 let task = vfs.task_receiver().recv().unwrap(); 100 process_tasks(&mut vfs, 1);
103 vfs.handle_task(task);
104 match vfs.commit_changes().as_slice() { 101 match vfs.commit_changes().as_slice() {
105 [VfsChange::AddFile { text, path, .. }] => { 102 [VfsChange::AddFile { text, path, .. }] => {
106 assert_eq!(text.as_str(), "new hello"); 103 assert_eq!(text.as_str(), "new hello");
@@ -109,10 +106,8 @@ fn test_vfs_works() -> std::io::Result<()> {
109 _ => panic!("unexpected changes"), 106 _ => panic!("unexpected changes"),
110 } 107 }
111 108
112 // on disk rename
113 fs::rename(&dir.path().join("a/new.rs"), &dir.path().join("a/new1.rs")).unwrap(); 109 fs::rename(&dir.path().join("a/new.rs"), &dir.path().join("a/new1.rs")).unwrap();
114 let task = vfs.task_receiver().recv().unwrap(); 110 process_tasks(&mut vfs, 2);
115 vfs.handle_task(task);
116 match vfs.commit_changes().as_slice() { 111 match vfs.commit_changes().as_slice() {
117 [VfsChange::RemoveFile { 112 [VfsChange::RemoveFile {
118 path: removed_path, .. 113 path: removed_path, ..
@@ -125,13 +120,11 @@ fn test_vfs_works() -> std::io::Result<()> {
125 assert_eq!(added_path, "new1.rs"); 120 assert_eq!(added_path, "new1.rs");
126 assert_eq!(text.as_str(), "new hello"); 121 assert_eq!(text.as_str(), "new hello");
127 } 122 }
128 _ => panic!("unexpected changes"), 123 xs => panic!("unexpected changes {:?}", xs),
129 } 124 }
130 125
131 // on disk remove
132 fs::remove_file(&dir.path().join("a/new1.rs")).unwrap(); 126 fs::remove_file(&dir.path().join("a/new1.rs")).unwrap();
133 let task = vfs.task_receiver().recv().unwrap(); 127 process_tasks(&mut vfs, 1);
134 vfs.handle_task(task);
135 match vfs.commit_changes().as_slice() { 128 match vfs.commit_changes().as_slice() {
136 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "new1.rs"), 129 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "new1.rs"),
137 _ => panic!("unexpected changes"), 130 _ => panic!("unexpected changes"),