diff options
Diffstat (limited to 'crates/ide_db/src/helpers/insert_use')
-rw-r--r-- | crates/ide_db/src/helpers/insert_use/tests.rs | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs index 3d151e629..048c213e2 100644 --- a/crates/ide_db/src/helpers/insert_use/tests.rs +++ b/crates/ide_db/src/helpers/insert_use/tests.rs | |||
@@ -5,6 +5,7 @@ use test_utils::assert_eq_text; | |||
5 | 5 | ||
6 | #[test] | 6 | #[test] |
7 | fn insert_not_group() { | 7 | fn insert_not_group() { |
8 | cov_mark::check!(insert_no_grouping_last); | ||
8 | check( | 9 | check( |
9 | "use external_crate2::bar::A", | 10 | "use external_crate2::bar::A", |
10 | r" | 11 | r" |
@@ -27,6 +28,21 @@ use external_crate2::bar::A;", | |||
27 | } | 28 | } |
28 | 29 | ||
29 | #[test] | 30 | #[test] |
31 | fn insert_not_group_empty() { | ||
32 | cov_mark::check!(insert_no_grouping_last2); | ||
33 | check( | ||
34 | "use external_crate2::bar::A", | ||
35 | r"", | ||
36 | r"use external_crate2::bar::A; | ||
37 | |||
38 | ", | ||
39 | None, | ||
40 | false, | ||
41 | false, | ||
42 | ); | ||
43 | } | ||
44 | |||
45 | #[test] | ||
30 | fn insert_existing() { | 46 | fn insert_existing() { |
31 | check_full("std::fs", "use std::fs;", "use std::fs;") | 47 | check_full("std::fs", "use std::fs;", "use std::fs;") |
32 | } | 48 | } |
@@ -51,21 +67,21 @@ use std::bar::G;", | |||
51 | 67 | ||
52 | #[test] | 68 | #[test] |
53 | fn insert_start_indent() { | 69 | fn insert_start_indent() { |
54 | cov_mark::check!(insert_use_indent_after); | ||
55 | check_none( | 70 | check_none( |
56 | "std::bar::AA", | 71 | "std::bar::AA", |
57 | r" | 72 | r" |
58 | use std::bar::B; | 73 | use std::bar::B; |
59 | use std::bar::D;", | 74 | use std::bar::C;", |
60 | r" | 75 | r" |
61 | use std::bar::AA; | 76 | use std::bar::AA; |
62 | use std::bar::B; | 77 | use std::bar::B; |
63 | use std::bar::D;", | 78 | use std::bar::C;", |
64 | ) | 79 | ); |
65 | } | 80 | } |
66 | 81 | ||
67 | #[test] | 82 | #[test] |
68 | fn insert_middle() { | 83 | fn insert_middle() { |
84 | cov_mark::check!(insert_group); | ||
69 | check_none( | 85 | check_none( |
70 | "std::bar::EE", | 86 | "std::bar::EE", |
71 | r" | 87 | r" |
@@ -102,6 +118,7 @@ fn insert_middle_indent() { | |||
102 | 118 | ||
103 | #[test] | 119 | #[test] |
104 | fn insert_end() { | 120 | fn insert_end() { |
121 | cov_mark::check!(insert_group_last); | ||
105 | check_none( | 122 | check_none( |
106 | "std::bar::ZZ", | 123 | "std::bar::ZZ", |
107 | r" | 124 | r" |
@@ -120,7 +137,6 @@ use std::bar::ZZ;", | |||
120 | 137 | ||
121 | #[test] | 138 | #[test] |
122 | fn insert_end_indent() { | 139 | fn insert_end_indent() { |
123 | cov_mark::check!(insert_use_indent_before); | ||
124 | check_none( | 140 | check_none( |
125 | "std::bar::ZZ", | 141 | "std::bar::ZZ", |
126 | r" | 142 | r" |
@@ -201,6 +217,7 @@ fn insert_first_matching_group() { | |||
201 | 217 | ||
202 | #[test] | 218 | #[test] |
203 | fn insert_missing_group_std() { | 219 | fn insert_missing_group_std() { |
220 | cov_mark::check!(insert_group_new_group); | ||
204 | check_none( | 221 | check_none( |
205 | "std::fmt", | 222 | "std::fmt", |
206 | r" | 223 | r" |
@@ -216,6 +233,7 @@ fn insert_missing_group_std() { | |||
216 | 233 | ||
217 | #[test] | 234 | #[test] |
218 | fn insert_missing_group_self() { | 235 | fn insert_missing_group_self() { |
236 | cov_mark::check!(insert_group_no_group); | ||
219 | check_none( | 237 | check_none( |
220 | "self::fmt", | 238 | "self::fmt", |
221 | r" | 239 | r" |
@@ -242,6 +260,7 @@ fn main() {}", | |||
242 | 260 | ||
243 | #[test] | 261 | #[test] |
244 | fn insert_empty_file() { | 262 | fn insert_empty_file() { |
263 | cov_mark::check!(insert_group_empty_file); | ||
245 | // empty files will get two trailing newlines | 264 | // empty files will get two trailing newlines |
246 | // this is due to the test case insert_no_imports above | 265 | // this is due to the test case insert_no_imports above |
247 | check_full( | 266 | check_full( |
@@ -255,7 +274,7 @@ fn insert_empty_file() { | |||
255 | 274 | ||
256 | #[test] | 275 | #[test] |
257 | fn insert_empty_module() { | 276 | fn insert_empty_module() { |
258 | cov_mark::check!(insert_use_no_indent_after); | 277 | cov_mark::check!(insert_group_empty_module); |
259 | check( | 278 | check( |
260 | "foo::bar", | 279 | "foo::bar", |
261 | "mod x {}", | 280 | "mod x {}", |
@@ -270,6 +289,7 @@ fn insert_empty_module() { | |||
270 | 289 | ||
271 | #[test] | 290 | #[test] |
272 | fn insert_after_inner_attr() { | 291 | fn insert_after_inner_attr() { |
292 | cov_mark::check!(insert_group_empty_inner_attr); | ||
273 | check_full( | 293 | check_full( |
274 | "foo::bar", | 294 | "foo::bar", |
275 | r"#![allow(unused_imports)]", | 295 | r"#![allow(unused_imports)]", |
@@ -615,7 +635,7 @@ fn check( | |||
615 | if module { | 635 | if module { |
616 | syntax = syntax.descendants().find_map(ast::Module::cast).unwrap().syntax().clone(); | 636 | syntax = syntax.descendants().find_map(ast::Module::cast).unwrap().syntax().clone(); |
617 | } | 637 | } |
618 | let file = super::ImportScope::from(syntax).unwrap(); | 638 | let file = super::ImportScope::from(syntax.clone_for_update()).unwrap(); |
619 | let path = ast::SourceFile::parse(&format!("use {};", path)) | 639 | let path = ast::SourceFile::parse(&format!("use {};", path)) |
620 | .tree() | 640 | .tree() |
621 | .syntax() | 641 | .syntax() |
@@ -623,12 +643,8 @@ fn check( | |||
623 | .find_map(ast::Path::cast) | 643 | .find_map(ast::Path::cast) |
624 | .unwrap(); | 644 | .unwrap(); |
625 | 645 | ||
626 | let rewriter = insert_use( | 646 | insert_use(&file, path, InsertUseConfig { merge: mb, prefix_kind: PrefixKind::Plain, group }); |
627 | &file, | 647 | let result = file.as_syntax_node().to_string(); |
628 | path, | ||
629 | InsertUseConfig { merge: mb, prefix_kind: PrefixKind::Plain, group }, | ||
630 | ); | ||
631 | let result = rewriter.rewrite(file.as_syntax_node()).to_string(); | ||
632 | assert_eq_text!(ra_fixture_after, &result); | 648 | assert_eq_text!(ra_fixture_after, &result); |
633 | } | 649 | } |
634 | 650 | ||