aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r--crates/ide/src/diagnostics.rs42
1 files changed, 7 insertions, 35 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index b2714cb69..7e53ed361 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -248,35 +248,7 @@ mod tests {
248 /// * a diagnostic is produced 248 /// * a diagnostic is produced
249 /// * this diagnostic fix trigger range touches the input cursor position 249 /// * this diagnostic fix trigger range touches the input cursor position
250 /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied 250 /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
251 pub(super) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { 251 pub(crate) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
252 let after = trim_indent(ra_fixture_after);
253
254 let (analysis, file_position) = fixture::position(ra_fixture_before);
255 let diagnostic = analysis
256 .diagnostics(&DiagnosticsConfig::default(), file_position.file_id)
257 .unwrap()
258 .pop()
259 .unwrap();
260 let mut fix = diagnostic.fix.unwrap();
261 let edit = fix.source_change.source_file_edits.pop().unwrap().edit;
262 let target_file_contents = analysis.file_text(file_position.file_id).unwrap();
263 let actual = {
264 let mut actual = target_file_contents.to_string();
265 edit.apply(&mut actual);
266 actual
267 };
268
269 assert_eq_text!(&after, &actual);
270 assert!(
271 fix.fix_trigger_range.contains_inclusive(file_position.offset),
272 "diagnostic fix range {:?} does not touch cursor position {:?}",
273 fix.fix_trigger_range,
274 file_position.offset
275 );
276 }
277
278 /// Similar to `check_fix`, but applies all the available fixes.
279 fn check_fixes(ra_fixture_before: &str, ra_fixture_after: &str) {
280 let after = trim_indent(ra_fixture_after); 252 let after = trim_indent(ra_fixture_after);
281 253
282 let (analysis, file_position) = fixture::position(ra_fixture_before); 254 let (analysis, file_position) = fixture::position(ra_fixture_before);
@@ -802,7 +774,7 @@ struct Foo {
802 774
803 #[test] 775 #[test]
804 fn test_rename_incorrect_case() { 776 fn test_rename_incorrect_case() {
805 check_fixes( 777 check_fix(
806 r#" 778 r#"
807pub struct test_struct<|> { one: i32 } 779pub struct test_struct<|> { one: i32 }
808 780
@@ -819,7 +791,7 @@ pub fn some_fn(val: TestStruct) -> TestStruct {
819"#, 791"#,
820 ); 792 );
821 793
822 check_fixes( 794 check_fix(
823 r#" 795 r#"
824pub fn some_fn(NonSnakeCase<|>: u8) -> u8 { 796pub fn some_fn(NonSnakeCase<|>: u8) -> u8 {
825 NonSnakeCase 797 NonSnakeCase
@@ -832,7 +804,7 @@ pub fn some_fn(non_snake_case: u8) -> u8 {
832"#, 804"#,
833 ); 805 );
834 806
835 check_fixes( 807 check_fix(
836 r#" 808 r#"
837pub fn SomeFn<|>(val: u8) -> u8 { 809pub fn SomeFn<|>(val: u8) -> u8 {
838 if val != 0 { SomeFn(val - 1) } else { val } 810 if val != 0 { SomeFn(val - 1) } else { val }
@@ -845,7 +817,7 @@ pub fn some_fn(val: u8) -> u8 {
845"#, 817"#,
846 ); 818 );
847 819
848 check_fixes( 820 check_fix(
849 r#" 821 r#"
850fn some_fn() { 822fn some_fn() {
851 let whatAWeird_Formatting<|> = 10; 823 let whatAWeird_Formatting<|> = 10;
@@ -874,7 +846,7 @@ fn foo() {
874 846
875 #[test] 847 #[test]
876 fn test_rename_incorrect_case_struct_method() { 848 fn test_rename_incorrect_case_struct_method() {
877 check_fixes( 849 check_fix(
878 r#" 850 r#"
879pub struct TestStruct; 851pub struct TestStruct;
880 852
@@ -906,6 +878,6 @@ impl TestStruct {
906 analysis.diagnostics(&DiagnosticsConfig::default(), file_position.file_id).unwrap(); 878 analysis.diagnostics(&DiagnosticsConfig::default(), file_position.file_id).unwrap();
907 assert_eq!(diagnostics.len(), 1); 879 assert_eq!(diagnostics.len(), 1);
908 880
909 check_fixes(input, expected); 881 check_fix(input, expected);
910 } 882 }
911} 883}