aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/diagnostics.rs')
-rw-r--r--crates/ra_ide/src/diagnostics.rs23
1 files changed, 4 insertions, 19 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 9bde1db8e..8cb0700b9 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -283,7 +283,7 @@ fn check_struct_shorthand_initialization(
283mod tests { 283mod tests {
284 use insta::assert_debug_snapshot; 284 use insta::assert_debug_snapshot;
285 use ra_syntax::SourceFile; 285 use ra_syntax::SourceFile;
286 use stdx::SepBy; 286 use stdx::trim_indent;
287 use test_utils::assert_eq_text; 287 use test_utils::assert_eq_text;
288 288
289 use crate::mock_analysis::{analysis_and_position, single_file}; 289 use crate::mock_analysis::{analysis_and_position, single_file};
@@ -325,6 +325,8 @@ mod tests {
325 /// * this diagnostic touches the input cursor position 325 /// * this diagnostic touches the input cursor position
326 /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied 326 /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
327 fn check_apply_diagnostic_fix_from_position(fixture: &str, after: &str) { 327 fn check_apply_diagnostic_fix_from_position(fixture: &str, after: &str) {
328 let after = trim_indent(after);
329
328 let (analysis, file_position) = analysis_and_position(fixture); 330 let (analysis, file_position) = analysis_and_position(fixture);
329 let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap(); 331 let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap();
330 let mut fix = diagnostic.fix.unwrap(); 332 let mut fix = diagnostic.fix.unwrap();
@@ -336,21 +338,6 @@ mod tests {
336 actual 338 actual
337 }; 339 };
338 340
339 // Strip indent and empty lines from `after`, to match the behaviour of
340 // `parse_fixture` called from `analysis_and_position`.
341 let margin = fixture
342 .lines()
343 .filter(|it| it.trim_start().starts_with("//-"))
344 .map(|it| it.len() - it.trim_start().len())
345 .next()
346 .expect("empty fixture");
347 let after = after
348 .lines()
349 .filter_map(|line| if line.len() > margin { Some(&line[margin..]) } else { None })
350 .sep_by("\n")
351 .suffix("\n")
352 .to_string();
353
354 assert_eq_text!(&after, &actual); 341 assert_eq_text!(&after, &actual);
355 assert!( 342 assert!(
356 diagnostic.range.start() <= file_position.offset 343 diagnostic.range.start() <= file_position.offset
@@ -400,7 +387,6 @@ mod tests {
400 } 387 }
401 x / y<|> 388 x / y<|>
402 } 389 }
403
404 //- /core/lib.rs 390 //- /core/lib.rs
405 pub mod result { 391 pub mod result {
406 pub enum Result<T, E> { Ok(T), Err(E) } 392 pub enum Result<T, E> { Ok(T), Err(E) }
@@ -431,7 +417,6 @@ mod tests {
431 } 417 }
432 <|>x 418 <|>x
433 } 419 }
434
435 //- /core/lib.rs 420 //- /core/lib.rs
436 pub mod result { 421 pub mod result {
437 pub enum Result<T, E> { Ok(T), Err(E) } 422 pub enum Result<T, E> { Ok(T), Err(E) }
@@ -464,7 +449,6 @@ mod tests {
464 } 449 }
465 x <|>/ y 450 x <|>/ y
466 } 451 }
467
468 //- /core/lib.rs 452 //- /core/lib.rs
469 pub mod result { 453 pub mod result {
470 pub enum Result<T, E> { Ok(T), Err(E) } 454 pub enum Result<T, E> { Ok(T), Err(E) }
@@ -474,6 +458,7 @@ mod tests {
474 use core::result::Result::{self, Ok, Err}; 458 use core::result::Result::{self, Ok, Err};
475 459
476 type MyResult<T> = Result<T, ()>; 460 type MyResult<T> = Result<T, ()>;
461
477 fn div(x: i32, y: i32) -> MyResult<i32> { 462 fn div(x: i32, y: i32) -> MyResult<i32> {
478 if y == 0 { 463 if y == 0 {
479 return Err(()); 464 return Err(());