diff options
Diffstat (limited to 'crates/ra_vfs/tests')
-rw-r--r-- | crates/ra_vfs/tests/vfs.rs | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/crates/ra_vfs/tests/vfs.rs b/crates/ra_vfs/tests/vfs.rs index 545e1dbdd..649ef96c9 100644 --- a/crates/ra_vfs/tests/vfs.rs +++ b/crates/ra_vfs/tests/vfs.rs | |||
@@ -7,10 +7,7 @@ use tempfile::tempdir; | |||
7 | 7 | ||
8 | fn process_tasks(vfs: &mut Vfs, num_tasks: u32) { | 8 | fn process_tasks(vfs: &mut Vfs, num_tasks: u32) { |
9 | for _ in 0..num_tasks { | 9 | for _ in 0..num_tasks { |
10 | let task = vfs | 10 | let task = vfs.task_receiver().recv_timeout(Duration::from_secs(3)).unwrap(); |
11 | .task_receiver() | ||
12 | .recv_timeout(Duration::from_secs(3)) | ||
13 | .unwrap(); | ||
14 | log::debug!("{:?}", task); | 11 | log::debug!("{:?}", task); |
15 | vfs.handle_task(task); | 12 | vfs.handle_task(task); |
16 | } | 13 | } |
@@ -32,11 +29,7 @@ macro_rules! assert_match { | |||
32 | fn test_vfs_works() -> std::io::Result<()> { | 29 | fn test_vfs_works() -> std::io::Result<()> { |
33 | // Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap(); | 30 | // Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap(); |
34 | 31 | ||
35 | let files = [ | 32 | let files = [("a/foo.rs", "hello"), ("a/bar.rs", "world"), ("a/b/baz.rs", "nested hello")]; |
36 | ("a/foo.rs", "hello"), | ||
37 | ("a/bar.rs", "world"), | ||
38 | ("a/b/baz.rs", "nested hello"), | ||
39 | ]; | ||
40 | 33 | ||
41 | let dir = tempdir().unwrap(); | 34 | let dir = tempdir().unwrap(); |
42 | for (path, text) in files.iter() { | 35 | for (path, text) in files.iter() { |
@@ -66,14 +59,10 @@ fn test_vfs_works() -> std::io::Result<()> { | |||
66 | }) | 59 | }) |
67 | .collect::<HashSet<_>>(); | 60 | .collect::<HashSet<_>>(); |
68 | 61 | ||
69 | let expected_files = [ | 62 | let expected_files = [("foo.rs", "hello"), ("bar.rs", "world"), ("baz.rs", "nested hello")] |
70 | ("foo.rs", "hello"), | 63 | .iter() |
71 | ("bar.rs", "world"), | 64 | .map(|(path, text)| (path.to_string(), text.to_string())) |
72 | ("baz.rs", "nested hello"), | 65 | .collect::<HashSet<_>>(); |
73 | ] | ||
74 | .iter() | ||
75 | .map(|(path, text)| (path.to_string(), text.to_string())) | ||
76 | .collect::<HashSet<_>>(); | ||
77 | 66 | ||
78 | assert_eq!(files, expected_files); | 67 | assert_eq!(files, expected_files); |
79 | } | 68 | } |
@@ -107,14 +96,10 @@ fn test_vfs_works() -> std::io::Result<()> { | |||
107 | ); | 96 | ); |
108 | 97 | ||
109 | vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string()); | 98 | vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string()); |
110 | assert_match!( | 99 | assert_match!(vfs.commit_changes().as_slice(), [VfsChange::AddFile { text, path, .. }], { |
111 | vfs.commit_changes().as_slice(), | 100 | assert_eq!(text.as_str(), "spam"); |
112 | [VfsChange::AddFile { text, path, .. }], | 101 | assert_eq!(path, "spam.rs"); |
113 | { | 102 | }); |
114 | assert_eq!(text.as_str(), "spam"); | ||
115 | assert_eq!(path, "spam.rs"); | ||
116 | } | ||
117 | ); | ||
118 | 103 | ||
119 | vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs")); | 104 | vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs")); |
120 | assert_match!( | 105 | assert_match!( |
@@ -126,30 +111,17 @@ fn test_vfs_works() -> std::io::Result<()> { | |||
126 | fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap(); | 111 | fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap(); |
127 | fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap(); | 112 | fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap(); |
128 | process_tasks(&mut vfs, 1); | 113 | process_tasks(&mut vfs, 1); |
129 | assert_match!( | 114 | assert_match!(vfs.commit_changes().as_slice(), [VfsChange::AddFile { text, path, .. }], { |
130 | vfs.commit_changes().as_slice(), | 115 | assert_eq!(text.as_str(), "new hello"); |
131 | [VfsChange::AddFile { text, path, .. }], | 116 | assert_eq!(path, "sub1/sub2/new.rs"); |
132 | { | 117 | }); |
133 | assert_eq!(text.as_str(), "new hello"); | ||
134 | assert_eq!(path, "sub1/sub2/new.rs"); | ||
135 | } | ||
136 | ); | ||
137 | 118 | ||
138 | fs::rename( | 119 | fs::rename(&dir.path().join("a/sub1/sub2/new.rs"), &dir.path().join("a/sub1/sub2/new1.rs")) |
139 | &dir.path().join("a/sub1/sub2/new.rs"), | 120 | .unwrap(); |
140 | &dir.path().join("a/sub1/sub2/new1.rs"), | ||
141 | ) | ||
142 | .unwrap(); | ||
143 | process_tasks(&mut vfs, 2); | 121 | process_tasks(&mut vfs, 2); |
144 | assert_match!( | 122 | assert_match!( |
145 | vfs.commit_changes().as_slice(), | 123 | vfs.commit_changes().as_slice(), |
146 | [VfsChange::RemoveFile { | 124 | [VfsChange::RemoveFile { path: removed_path, .. }, VfsChange::AddFile { text, path: added_path, .. }], |
147 | path: removed_path, .. | ||
148 | }, VfsChange::AddFile { | ||
149 | text, | ||
150 | path: added_path, | ||
151 | .. | ||
152 | }], | ||
153 | { | 125 | { |
154 | assert_eq!(removed_path, "sub1/sub2/new.rs"); | 126 | assert_eq!(removed_path, "sub1/sub2/new.rs"); |
155 | assert_eq!(added_path, "sub1/sub2/new1.rs"); | 127 | assert_eq!(added_path, "sub1/sub2/new1.rs"); |