"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
"smol_str 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "test_utils 0.1.0",
"text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
use serde::Serialize;
use serde_json::{from_str, to_string_pretty, Value};
use tempdir::TempDir;
+use test_utils::parse_fixture;
use ra_lsp_server::{
main_loop, req,
INIT.call_once(|| Logger::with_env_or_str(crate::LOG).start().unwrap());
let tmp_dir = TempDir::new("test-project").unwrap();
- let mut buf = String::new();
- let mut file_name = None;
let mut paths = vec![];
- macro_rules! flush {
- () => {
- if let Some(file_name) = file_name {
- let path = tmp_dir.path().join(file_name);
- fs::create_dir_all(path.parent().unwrap()).unwrap();
- fs::write(path.as_path(), buf.as_bytes()).unwrap();
- paths.push((path, buf.clone()));
- }
- };
- };
- for line in fixture.lines() {
- if line.starts_with("//-") {
- flush!();
- buf.clear();
- file_name = Some(line["//-".len()..].trim());
- continue;
- }
- buf.push_str(line);
- buf.push('\n');
+
+ for entry in parse_fixture(fixture) {
+ let path = tmp_dir.path().join(entry.meta);
+ fs::create_dir_all(path.parent().unwrap()).unwrap();
+ fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
+ paths.push((path, entry.text));
}
- flush!();
Server::new(tmp_dir, paths)
}
res.push_str(&text[offset..]);
res
}
+
+
+#[derive(Debug)]
+pub struct FixtureEntry {
+ pub meta: String,
+ pub text: String,
+}
+
+/// Parses text wich looks like this:
+///
+/// ```notrust
+/// //- some meta
+/// line 1
+/// line 2
+/// // - other meta
+/// ```
+pub fn parse_fixture(fixture: &str) -> Vec<FixtureEntry> {
+ let mut res = Vec::new();
+ let mut buf = String::new();
+ let mut meta: Option<&str> = None;
+
+ macro_rules! flush {
+ () => {
+ if let Some(meta) = meta {
+ res.push(FixtureEntry { meta: meta.to_string(), text: buf.clone() });
+ buf.clear();
+ }
+ };
+ };
+ for line in fixture.lines() {
+ if line.starts_with("//-") {
+ flush!();
+ buf.clear();
+ meta = Some(line["//-".len()..].trim());
+ continue;
+ }
+ buf.push_str(line);
+ buf.push('\n');
+ }
+ flush!();
+ res
+}