aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_lsp_server/Cargo.toml1
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs29
-rw-r--r--crates/test_utils/src/lib.rs42
4 files changed, 51 insertions, 22 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 76391eff4..bf937d205 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -661,6 +661,7 @@ dependencies = [
661 "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", 661 "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
662 "smol_str 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 662 "smol_str 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
663 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", 663 "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
664 "test_utils 0.1.0",
664 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 665 "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
665 "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 666 "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
666 "walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 667 "walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 2bf073074..f29dafc17 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -32,3 +32,4 @@ gen_lsp_server = { path = "../gen_lsp_server" }
32 32
33[dev-dependencies] 33[dev-dependencies]
34tempdir = "0.3.7" 34tempdir = "0.3.7"
35test_utils = { path = "../test_utils" }
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 004d7e8ad..b90d21135 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -17,6 +17,7 @@ use languageserver_types::{
17use serde::Serialize; 17use serde::Serialize;
18use serde_json::{from_str, to_string_pretty, Value}; 18use serde_json::{from_str, to_string_pretty, Value};
19use tempdir::TempDir; 19use tempdir::TempDir;
20use test_utils::parse_fixture;
20 21
21use ra_lsp_server::{ 22use ra_lsp_server::{
22 main_loop, req, 23 main_loop, req,
@@ -28,30 +29,14 @@ pub fn project(fixture: &str) -> Server {
28 INIT.call_once(|| Logger::with_env_or_str(crate::LOG).start().unwrap()); 29 INIT.call_once(|| Logger::with_env_or_str(crate::LOG).start().unwrap());
29 30
30 let tmp_dir = TempDir::new("test-project").unwrap(); 31 let tmp_dir = TempDir::new("test-project").unwrap();
31 let mut buf = String::new();
32 let mut file_name = None;
33 let mut paths = vec![]; 32 let mut paths = vec![];
34 macro_rules! flush { 33
35 () => { 34 for entry in parse_fixture(fixture) {
36 if let Some(file_name) = file_name { 35 let path = tmp_dir.path().join(entry.meta);
37 let path = tmp_dir.path().join(file_name); 36 fs::create_dir_all(path.parent().unwrap()).unwrap();
38 fs::create_dir_all(path.parent().unwrap()).unwrap(); 37 fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
39 fs::write(path.as_path(), buf.as_bytes()).unwrap(); 38 paths.push((path, entry.text));
40 paths.push((path, buf.clone()));
41 }
42 };
43 };
44 for line in fixture.lines() {
45 if line.starts_with("//-") {
46 flush!();
47 buf.clear();
48 file_name = Some(line["//-".len()..].trim());
49 continue;
50 }
51 buf.push_str(line);
52 buf.push('\n');
53 } 39 }
54 flush!();
55 Server::new(tmp_dir, paths) 40 Server::new(tmp_dir, paths)
56} 41}
57 42
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index dbe2997eb..562dbcbb3 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -87,3 +87,45 @@ pub fn add_cursor(text: &str, offset: TextUnit) -> String {
87 res.push_str(&text[offset..]); 87 res.push_str(&text[offset..]);
88 res 88 res
89} 89}
90
91
92#[derive(Debug)]
93pub struct FixtureEntry {
94 pub meta: String,
95 pub text: String,
96}
97
98/// Parses text wich looks like this:
99///
100/// ```notrust
101/// //- some meta
102/// line 1
103/// line 2
104/// // - other meta
105/// ```
106pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
107 let mut res = Vec::new();
108 let mut buf = String::new();
109 let mut meta: Option<&str> = None;
110
111 macro_rules! flush {
112 () => {
113 if let Some(meta) = meta {
114 res.push(FixtureEntry { meta: meta.to_string(), text: buf.clone() });
115 buf.clear();
116 }
117 };
118 };
119 for line in fixture.lines() {
120 if line.starts_with("//-") {
121 flush!();
122 buf.clear();
123 meta = Some(line["//-".len()..].trim());
124 continue;
125 }
126 buf.push_str(line);
127 buf.push('\n');
128 }
129 flush!();
130 res
131}