Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/tests.rs')
-rw-r--r--crates/ide-assists/src/tests.rs319
1 files changed, 301 insertions, 18 deletions
diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs
index 6469957fe1..0b1ff87c5c 100644
--- a/crates/ide-assists/src/tests.rs
+++ b/crates/ide-assists/src/tests.rs
@@ -362,8 +362,7 @@ pub fn test_some_range(a: int) -> bool {
expect![[r#"
Convert integer base
- Extract into variable
- Extract into function
+ Extract into...
Replace if let with match
"#]]
.assert_eq(&expected);
@@ -391,8 +390,7 @@ pub fn test_some_range(a: int) -> bool {
expect![[r#"
Convert integer base
- Extract into variable
- Extract into function
+ Extract into...
Replace if let with match
"#]]
.assert_eq(&expected);
@@ -405,8 +403,7 @@ pub fn test_some_range(a: int) -> bool {
let expected = labels(&assists);
expect![[r#"
- Extract into variable
- Extract into function
+ Extract into...
"#]]
.assert_eq(&expected);
}
@@ -440,7 +437,7 @@ pub fn test_some_range(a: int) -> bool {
{
let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange.into());
- assert_eq!(2, assists.len());
+ assert_eq!(4, assists.len());
let mut assists = assists.into_iter();
let extract_into_variable_assist = assists.next().unwrap();
@@ -451,7 +448,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into variable",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: None,
command: None,
@@ -459,6 +460,46 @@ pub fn test_some_range(a: int) -> bool {
"#]]
.assert_debug_eq(&extract_into_variable_assist);
+ let extract_into_constant_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_constant",
+ RefactorExtract,
+ ),
+ label: "Extract into constant",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: None,
+ command: None,
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_constant_assist);
+
+ let extract_into_static_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_static",
+ RefactorExtract,
+ ),
+ label: "Extract into static",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: None,
+ command: None,
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_static_assist);
+
let extract_into_function_assist = assists.next().unwrap();
expect![[r#"
Assist {
@@ -467,7 +508,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into function",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: None,
command: None,
@@ -486,7 +531,7 @@ pub fn test_some_range(a: int) -> bool {
}),
frange.into(),
);
- assert_eq!(2, assists.len());
+ assert_eq!(4, assists.len());
let mut assists = assists.into_iter();
let extract_into_variable_assist = assists.next().unwrap();
@@ -497,7 +542,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into variable",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: None,
command: None,
@@ -505,6 +554,46 @@ pub fn test_some_range(a: int) -> bool {
"#]]
.assert_debug_eq(&extract_into_variable_assist);
+ let extract_into_constant_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_constant",
+ RefactorExtract,
+ ),
+ label: "Extract into constant",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: None,
+ command: None,
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_constant_assist);
+
+ let extract_into_static_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_static",
+ RefactorExtract,
+ ),
+ label: "Extract into static",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: None,
+ command: None,
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_static_assist);
+
let extract_into_function_assist = assists.next().unwrap();
expect![[r#"
Assist {
@@ -513,7 +602,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into function",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: None,
command: None,
@@ -532,7 +625,7 @@ pub fn test_some_range(a: int) -> bool {
}),
frange.into(),
);
- assert_eq!(2, assists.len());
+ assert_eq!(4, assists.len());
let mut assists = assists.into_iter();
let extract_into_variable_assist = assists.next().unwrap();
@@ -543,7 +636,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into variable",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: Some(
SourceChange {
@@ -594,6 +691,46 @@ pub fn test_some_range(a: int) -> bool {
"#]]
.assert_debug_eq(&extract_into_variable_assist);
+ let extract_into_constant_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_constant",
+ RefactorExtract,
+ ),
+ label: "Extract into constant",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: None,
+ command: None,
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_constant_assist);
+
+ let extract_into_static_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_static",
+ RefactorExtract,
+ ),
+ label: "Extract into static",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: None,
+ command: None,
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_static_assist);
+
let extract_into_function_assist = assists.next().unwrap();
expect![[r#"
Assist {
@@ -602,7 +739,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into function",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: None,
command: None,
@@ -613,7 +754,7 @@ pub fn test_some_range(a: int) -> bool {
{
let assists = assists(&db, &cfg, AssistResolveStrategy::All, frange.into());
- assert_eq!(2, assists.len());
+ assert_eq!(4, assists.len());
let mut assists = assists.into_iter();
let extract_into_variable_assist = assists.next().unwrap();
@@ -624,7 +765,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into variable",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: Some(
SourceChange {
@@ -675,6 +820,140 @@ pub fn test_some_range(a: int) -> bool {
"#]]
.assert_debug_eq(&extract_into_variable_assist);
+ let extract_into_constant_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_constant",
+ RefactorExtract,
+ ),
+ label: "Extract into constant",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: Some(
+ SourceChange {
+ source_file_edits: {
+ FileId(
+ 0,
+ ): (
+ TextEdit {
+ indels: [
+ Indel {
+ insert: "const",
+ delete: 45..47,
+ },
+ Indel {
+ insert: "VAR_NAME:",
+ delete: 48..60,
+ },
+ Indel {
+ insert: "i32",
+ delete: 61..81,
+ },
+ Indel {
+ insert: "=",
+ delete: 82..86,
+ },
+ Indel {
+ insert: "5;\n if let 2..6 = VAR_NAME {\n true\n } else {\n false\n }",
+ delete: 87..108,
+ },
+ ],
+ },
+ Some(
+ SnippetEdit(
+ [
+ (
+ 0,
+ 51..51,
+ ),
+ ],
+ ),
+ ),
+ ),
+ },
+ file_system_edits: [],
+ is_snippet: true,
+ },
+ ),
+ command: Some(
+ Rename,
+ ),
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_constant_assist);
+
+ let extract_into_static_assist = assists.next().unwrap();
+ expect![[r#"
+ Assist {
+ id: AssistId(
+ "extract_static",
+ RefactorExtract,
+ ),
+ label: "Extract into static",
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
+ target: 59..60,
+ source_change: Some(
+ SourceChange {
+ source_file_edits: {
+ FileId(
+ 0,
+ ): (
+ TextEdit {
+ indels: [
+ Indel {
+ insert: "static",
+ delete: 45..47,
+ },
+ Indel {
+ insert: "VAR_NAME:",
+ delete: 48..60,
+ },
+ Indel {
+ insert: "i32",
+ delete: 61..81,
+ },
+ Indel {
+ insert: "=",
+ delete: 82..86,
+ },
+ Indel {
+ insert: "5;\n if let 2..6 = VAR_NAME {\n true\n } else {\n false\n }",
+ delete: 87..108,
+ },
+ ],
+ },
+ Some(
+ SnippetEdit(
+ [
+ (
+ 0,
+ 52..52,
+ ),
+ ],
+ ),
+ ),
+ ),
+ },
+ file_system_edits: [],
+ is_snippet: true,
+ },
+ ),
+ command: Some(
+ Rename,
+ ),
+ }
+ "#]]
+ .assert_debug_eq(&extract_into_static_assist);
+
let extract_into_function_assist = assists.next().unwrap();
expect![[r#"
Assist {
@@ -683,7 +962,11 @@ pub fn test_some_range(a: int) -> bool {
RefactorExtract,
),
label: "Extract into function",
- group: None,
+ group: Some(
+ GroupLabel(
+ "Extract into...",
+ ),
+ ),
target: 59..60,
source_change: Some(
SourceChange {