From 25e6bbde01d4a9cd08fa79db5b8b7da6bbf1a623 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 10:16:55 +0200 Subject: Merge assits::test_helpers and tests --- crates/ra_assists/src/tests.rs | 137 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 crates/ra_assists/src/tests.rs (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs new file mode 100644 index 000000000..ca3096a43 --- /dev/null +++ b/crates/ra_assists/src/tests.rs @@ -0,0 +1,137 @@ +use std::sync::Arc; + +use hir::Semantics; +use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; +use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; +use ra_syntax::TextRange; +use test_utils::{ + add_cursor, assert_eq_text, extract_offset, extract_range, extract_range_or_offset, + RangeOrOffset, +}; + +use crate::{handlers::Handler, resolved_assists, AssistCtx, AssistFile}; + +pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { + let (mut db, file_id) = RootDatabase::with_single_file(text); + // FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`, + // but it looks like this might need specialization? :( + db.set_local_roots(Arc::new(vec![db.file_source_root(file_id)])); + (db, file_id) +} + +pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { + check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); +} + +// FIXME: instead of having a separate function here, maybe use +// `extract_ranges` and mark the target as ` ` in the +// fixuture? +pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { + check(assist, ra_fixture, ExpectedResult::Target(target)); +} + +pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { + check(assist, ra_fixture, ExpectedResult::NotApplicable); +} + +enum ExpectedResult<'a> { + NotApplicable, + After(&'a str), + Target(&'a str), +} + +fn check(assist: Handler, before: &str, expected: ExpectedResult) { + let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { + let (mut db, position) = RootDatabase::with_position(before); + db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)])); + ( + db.file_text(position.file_id).as_ref().to_owned(), + position.file_id, + RangeOrOffset::Offset(position.offset), + db, + ) + } else { + let (range_or_offset, text_without_caret) = extract_range_or_offset(before); + let (db, file_id) = with_single_file(&text_without_caret); + (text_without_caret, file_id, range_or_offset, db) + }; + + let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; + + let sema = Semantics::new(&db); + let assist_ctx = AssistCtx::new(&sema, frange, true); + + match (assist(assist_ctx), expected) { + (Some(assist), ExpectedResult::After(after)) => { + let action = assist.0[0].action.clone().unwrap(); + + let mut actual = if let AssistFile::TargetFile(file_id) = action.file { + db.file_text(file_id).as_ref().to_owned() + } else { + text_without_caret + }; + action.edit.apply(&mut actual); + + match action.cursor_position { + None => { + if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { + let off = action + .edit + .apply_to_offset(before_cursor_pos) + .expect("cursor position is affected by the edit"); + actual = add_cursor(&actual, off) + } + } + Some(off) => actual = add_cursor(&actual, off), + }; + + assert_eq_text!(after, &actual); + } + (Some(assist), ExpectedResult::Target(target)) => { + let action = assist.0[0].action.clone().unwrap(); + let range = action.target.expect("expected target on action"); + assert_eq_text!(&text_without_caret[range], target); + } + (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), + (None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => { + panic!("code action is not applicable") + } + (None, ExpectedResult::NotApplicable) => (), + }; +} + +#[test] +fn assist_order_field_struct() { + let before = "struct Foo { <|>bar: u32 }"; + let (before_cursor_pos, before) = extract_offset(before); + let (db, file_id) = with_single_file(&before); + let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; + let assists = resolved_assists(&db, frange); + let mut assists = assists.iter(); + + assert_eq!( + assists.next().expect("expected assist").label.label, + "Change visibility to pub(crate)" + ); + assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`"); +} + +#[test] +fn assist_order_if_expr() { + let before = " + pub fn test_some_range(a: int) -> bool { + if let 2..6 = <|>5<|> { + true + } else { + false + } + }"; + let (range, before) = extract_range(before); + let (db, file_id) = with_single_file(&before); + let frange = FileRange { file_id, range }; + let assists = resolved_assists(&db, frange); + let mut assists = assists.iter(); + + assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable"); + assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match"); +} -- cgit v1.2.3 From d308ff910b18719fabaeb9df7bc5fc0afbd0a194 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 10:18:12 +0200 Subject: Merge doc_tests and tests --- crates/ra_assists/src/tests.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index ca3096a43..97744904a 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -34,6 +34,34 @@ pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { check(assist, ra_fixture, ExpectedResult::NotApplicable); } +fn check_doc_test(assist_id: &str, before: &str, after: &str) { + let (selection, before) = extract_range_or_offset(before); + let (db, file_id) = crate::tests::with_single_file(&before); + let frange = FileRange { file_id, range: selection.into() }; + + let assist = resolved_assists(&db, frange) + .into_iter() + .find(|assist| assist.label.id.0 == assist_id) + .unwrap_or_else(|| { + panic!( + "\n\nAssist is not applicable: {}\nAvailable assists: {}", + assist_id, + resolved_assists(&db, frange) + .into_iter() + .map(|assist| assist.label.id.0) + .collect::>() + .join(", ") + ) + }); + + let actual = { + let mut actual = before.clone(); + assist.action.edit.apply(&mut actual); + actual + }; + assert_eq_text!(after, &actual); +} + enum ExpectedResult<'a> { NotApplicable, After(&'a str), -- cgit v1.2.3 From eea431180eb5267928c8e0d4b8099ab1042e01d1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 10:21:35 +0200 Subject: Regenerate --- crates/ra_assists/src/tests.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 97744904a..483e11931 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -1,3 +1,5 @@ +mod generated; + use std::sync::Arc; use hir::Semantics; -- cgit v1.2.3 From 233f01c9ba555e5d06f336cb0ff64e7a83e4a23a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 12:51:28 +0200 Subject: Move target to AssistLabel Target is used for assists sorting, so we need it before we compute the action. --- crates/ra_assists/src/tests.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 483e11931..dd9026df6 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -118,8 +118,7 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) { assert_eq_text!(after, &actual); } (Some(assist), ExpectedResult::Target(target)) => { - let action = assist.0[0].action.clone().unwrap(); - let range = action.target.expect("expected target on action"); + let range = assist.0[0].label.target; assert_eq_text!(&text_without_caret[range], target); } (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), -- cgit v1.2.3 From fdd4df97ba5ce1f59abf9e945052fc6f3e077c3a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 15:26:40 +0200 Subject: Use SourceChange for assists --- crates/ra_assists/src/tests.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index dd9026df6..572462bfc 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -11,7 +11,7 @@ use test_utils::{ RangeOrOffset, }; -use crate::{handlers::Handler, resolved_assists, AssistCtx, AssistFile}; +use crate::{handlers::Handler, resolved_assists, AssistCtx}; pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { let (mut db, file_id) = RootDatabase::with_single_file(text); @@ -41,7 +41,7 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { let (db, file_id) = crate::tests::with_single_file(&before); let frange = FileRange { file_id, range: selection.into() }; - let assist = resolved_assists(&db, frange) + let mut assist = resolved_assists(&db, frange) .into_iter() .find(|assist| assist.label.id.0 == assist_id) .unwrap_or_else(|| { @@ -57,8 +57,9 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { }); let actual = { + let change = assist.action.source_file_edits.pop().unwrap(); let mut actual = before.clone(); - assist.action.edit.apply(&mut actual); + change.edit.apply(&mut actual); actual }; assert_eq_text!(after, &actual); @@ -93,26 +94,23 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) { match (assist(assist_ctx), expected) { (Some(assist), ExpectedResult::After(after)) => { - let action = assist.0[0].action.clone().unwrap(); + let mut action = assist.0[0].action.clone().unwrap(); + let change = action.source_file_edits.pop().unwrap(); - let mut actual = if let AssistFile::TargetFile(file_id) = action.file { - db.file_text(file_id).as_ref().to_owned() - } else { - text_without_caret - }; - action.edit.apply(&mut actual); + let mut actual = db.file_text(change.file_id).as_ref().to_owned(); + change.edit.apply(&mut actual); match action.cursor_position { None => { if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { - let off = action + let off = change .edit .apply_to_offset(before_cursor_pos) .expect("cursor position is affected by the edit"); actual = add_cursor(&actual, off) } } - Some(off) => actual = add_cursor(&actual, off), + Some(off) => actual = add_cursor(&actual, off.offset), }; assert_eq_text!(after, &actual); -- cgit v1.2.3 From 0970c3454baa0164df81a9ff665430d486687331 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 16:01:47 +0200 Subject: Rename --- crates/ra_assists/src/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 572462bfc..17e3ece9f 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -57,7 +57,7 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { }); let actual = { - let change = assist.action.source_file_edits.pop().unwrap(); + let change = assist.source_change.source_file_edits.pop().unwrap(); let mut actual = before.clone(); change.edit.apply(&mut actual); actual @@ -94,7 +94,7 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) { match (assist(assist_ctx), expected) { (Some(assist), ExpectedResult::After(after)) => { - let mut action = assist.0[0].action.clone().unwrap(); + let mut action = assist.0[0].source_change.clone().unwrap(); let change = action.source_file_edits.pop().unwrap(); let mut actual = db.file_text(change.file_id).as_ref().to_owned(); -- cgit v1.2.3 From 4867968d22899395e6551f22641b3617e995140c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 6 May 2020 18:45:35 +0200 Subject: Refactor assists API to be more convenient for adding new assists It now duplicates completion API in its shape. --- crates/ra_assists/src/tests.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 17e3ece9f..45b2d9733 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -11,7 +11,7 @@ use test_utils::{ RangeOrOffset, }; -use crate::{handlers::Handler, resolved_assists, AssistCtx}; +use crate::{handlers::Handler, resolved_assists, AssistContext, Assists}; pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { let (mut db, file_id) = RootDatabase::with_single_file(text); @@ -71,7 +71,7 @@ enum ExpectedResult<'a> { Target(&'a str), } -fn check(assist: Handler, before: &str, expected: ExpectedResult) { +fn check(handler: Handler, before: &str, expected: ExpectedResult) { let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { let (mut db, position) = RootDatabase::with_position(before); db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)])); @@ -90,17 +90,20 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) { let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; let sema = Semantics::new(&db); - let assist_ctx = AssistCtx::new(&sema, frange, true); - - match (assist(assist_ctx), expected) { + let ctx = AssistContext::new(sema, frange); + let mut acc = Assists::new_resolved(&ctx); + handler(&mut acc, &ctx); + let mut res = acc.finish_resolved(); + let assist = res.pop(); + match (assist, expected) { (Some(assist), ExpectedResult::After(after)) => { - let mut action = assist.0[0].source_change.clone().unwrap(); - let change = action.source_file_edits.pop().unwrap(); + let mut source_change = assist.source_change; + let change = source_change.source_file_edits.pop().unwrap(); let mut actual = db.file_text(change.file_id).as_ref().to_owned(); change.edit.apply(&mut actual); - match action.cursor_position { + match source_change.cursor_position { None => { if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { let off = change @@ -116,7 +119,7 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) { assert_eq_text!(after, &actual); } (Some(assist), ExpectedResult::Target(target)) => { - let range = assist.0[0].label.target; + let range = assist.label.target; assert_eq_text!(&text_without_caret[range], target); } (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), -- cgit v1.2.3 From c6b81bc013b5278b917d109b723405e0df413323 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 17:09:59 +0200 Subject: Rename AssitLabel -> Assist --- crates/ra_assists/src/tests.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 45b2d9733..a81c54d07 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -43,14 +43,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { let mut assist = resolved_assists(&db, frange) .into_iter() - .find(|assist| assist.label.id.0 == assist_id) + .find(|assist| assist.assist.id.0 == assist_id) .unwrap_or_else(|| { panic!( "\n\nAssist is not applicable: {}\nAvailable assists: {}", assist_id, resolved_assists(&db, frange) .into_iter() - .map(|assist| assist.label.id.0) + .map(|assist| assist.assist.id.0) .collect::>() .join(", ") ) @@ -119,7 +119,7 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) { assert_eq_text!(after, &actual); } (Some(assist), ExpectedResult::Target(target)) => { - let range = assist.label.target; + let range = assist.assist.target; assert_eq_text!(&text_without_caret[range], target); } (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), @@ -140,10 +140,10 @@ fn assist_order_field_struct() { let mut assists = assists.iter(); assert_eq!( - assists.next().expect("expected assist").label.label, + assists.next().expect("expected assist").assist.label, "Change visibility to pub(crate)" ); - assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`"); + assert_eq!(assists.next().expect("expected assist").assist.label, "Add `#[derive]`"); } #[test] @@ -162,6 +162,6 @@ fn assist_order_if_expr() { let assists = resolved_assists(&db, frange); let mut assists = assists.iter(); - assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable"); - assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match"); + assert_eq!(assists.next().expect("expected assist").assist.label, "Extract into variable"); + assert_eq!(assists.next().expect("expected assist").assist.label, "Replace with match"); } -- cgit v1.2.3 From 28fcff125a73ab2fc4aeaa100fc472af5178db20 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 17:29:23 +0200 Subject: Nicer API --- crates/ra_assists/src/tests.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index a81c54d07..a3eacb8f1 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -11,7 +11,7 @@ use test_utils::{ RangeOrOffset, }; -use crate::{handlers::Handler, resolved_assists, AssistContext, Assists}; +use crate::{handlers::Handler, Assist, AssistContext, Assists}; pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { let (mut db, file_id) = RootDatabase::with_single_file(text); @@ -41,14 +41,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { let (db, file_id) = crate::tests::with_single_file(&before); let frange = FileRange { file_id, range: selection.into() }; - let mut assist = resolved_assists(&db, frange) + let mut assist = Assist::resolved(&db, frange) .into_iter() .find(|assist| assist.assist.id.0 == assist_id) .unwrap_or_else(|| { panic!( "\n\nAssist is not applicable: {}\nAvailable assists: {}", assist_id, - resolved_assists(&db, frange) + Assist::resolved(&db, frange) .into_iter() .map(|assist| assist.assist.id.0) .collect::>() @@ -136,7 +136,7 @@ fn assist_order_field_struct() { let (before_cursor_pos, before) = extract_offset(before); let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; - let assists = resolved_assists(&db, frange); + let assists = Assist::resolved(&db, frange); let mut assists = assists.iter(); assert_eq!( @@ -159,7 +159,7 @@ fn assist_order_if_expr() { let (range, before) = extract_range(before); let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range }; - let assists = resolved_assists(&db, frange); + let assists = Assist::resolved(&db, frange); let mut assists = assists.iter(); assert_eq!(assists.next().expect("expected assist").assist.label, "Extract into variable"); -- cgit v1.2.3 From c847c079fd66d7ed09c64ff398baf05317b16500 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 May 2020 12:09:53 +0200 Subject: Add AssistConfig --- crates/ra_assists/src/tests.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index a3eacb8f1..9ba3da786 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -11,7 +11,7 @@ use test_utils::{ RangeOrOffset, }; -use crate::{handlers::Handler, Assist, AssistContext, Assists}; +use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists}; pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { let (mut db, file_id) = RootDatabase::with_single_file(text); @@ -41,14 +41,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { let (db, file_id) = crate::tests::with_single_file(&before); let frange = FileRange { file_id, range: selection.into() }; - let mut assist = Assist::resolved(&db, frange) + let mut assist = Assist::resolved(&db, &AssistConfig::default(), frange) .into_iter() .find(|assist| assist.assist.id.0 == assist_id) .unwrap_or_else(|| { panic!( "\n\nAssist is not applicable: {}\nAvailable assists: {}", assist_id, - Assist::resolved(&db, frange) + Assist::resolved(&db, &AssistConfig::default(), frange) .into_iter() .map(|assist| assist.assist.id.0) .collect::>() @@ -90,7 +90,8 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) { let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; let sema = Semantics::new(&db); - let ctx = AssistContext::new(sema, frange); + let config = AssistConfig::default(); + let ctx = AssistContext::new(sema, &config, frange); let mut acc = Assists::new_resolved(&ctx); handler(&mut acc, &ctx); let mut res = acc.finish_resolved(); @@ -103,19 +104,20 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) { let mut actual = db.file_text(change.file_id).as_ref().to_owned(); change.edit.apply(&mut actual); - match source_change.cursor_position { - None => { - if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { - let off = change - .edit - .apply_to_offset(before_cursor_pos) - .expect("cursor position is affected by the edit"); - actual = add_cursor(&actual, off) + if !source_change.is_snippet { + match source_change.cursor_position { + None => { + if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { + let off = change + .edit + .apply_to_offset(before_cursor_pos) + .expect("cursor position is affected by the edit"); + actual = add_cursor(&actual, off) + } } - } - Some(off) => actual = add_cursor(&actual, off.offset), - }; - + Some(off) => actual = add_cursor(&actual, off.offset), + }; + } assert_eq_text!(after, &actual); } (Some(assist), ExpectedResult::Target(target)) => { @@ -136,7 +138,7 @@ fn assist_order_field_struct() { let (before_cursor_pos, before) = extract_offset(before); let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; - let assists = Assist::resolved(&db, frange); + let assists = Assist::resolved(&db, &AssistConfig::default(), frange); let mut assists = assists.iter(); assert_eq!( @@ -159,7 +161,7 @@ fn assist_order_if_expr() { let (range, before) = extract_range(before); let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range }; - let assists = Assist::resolved(&db, frange); + let assists = Assist::resolved(&db, &AssistConfig::default(), frange); let mut assists = assists.iter(); assert_eq!(assists.next().expect("expected assist").assist.label, "Extract into variable"); -- cgit v1.2.3 From 65fa5864105280267e6ccdaa61957cd9953e444e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 22:55:37 +0200 Subject: Relax cursor position tests in assists Those will be replaced with snippets anyway --- crates/ra_assists/src/tests.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 9ba3da786..373a7f7cc 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -105,18 +105,9 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) { change.edit.apply(&mut actual); if !source_change.is_snippet { - match source_change.cursor_position { - None => { - if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { - let off = change - .edit - .apply_to_offset(before_cursor_pos) - .expect("cursor position is affected by the edit"); - actual = add_cursor(&actual, off) - } - } - Some(off) => actual = add_cursor(&actual, off.offset), - }; + if let Some(off) = source_change.cursor_position { + actual = add_cursor(&actual, off.offset) + } } assert_eq_text!(after, &actual); } -- cgit v1.2.3 From ff28c79ebd4c5a9a27542917940def9d4e66eea6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 14:34:27 +0200 Subject: Remove dead code for handling cursor positions --- crates/ra_assists/src/tests.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'crates/ra_assists/src/tests.rs') diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 373a7f7cc..62dd3547f 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -7,8 +7,7 @@ use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; use ra_syntax::TextRange; use test_utils::{ - add_cursor, assert_eq_text, extract_offset, extract_range, extract_range_or_offset, - RangeOrOffset, + assert_eq_text, extract_offset, extract_range, extract_range_or_offset, RangeOrOffset, }; use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists}; @@ -103,12 +102,6 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) { let mut actual = db.file_text(change.file_id).as_ref().to_owned(); change.edit.apply(&mut actual); - - if !source_change.is_snippet { - if let Some(off) = source_change.cursor_position { - actual = add_cursor(&actual, off.offset) - } - } assert_eq_text!(after, &actual); } (Some(assist), ExpectedResult::Target(target)) => { -- cgit v1.2.3