diff options
author | Aleksey Kladov <[email protected]> | 2020-05-06 09:16:55 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-05-06 09:16:55 +0100 |
commit | 25e6bbde01d4a9cd08fa79db5b8b7da6bbf1a623 (patch) | |
tree | b47a0ba06886a45d9a07a594c14a04e019b5e2d8 /crates/ra_assists/src | |
parent | 30eb458b4fa8adcecd8cbf731bd1cfa9a7a8b88b (diff) |
Merge assits::test_helpers and tests
Diffstat (limited to 'crates/ra_assists/src')
35 files changed, 172 insertions, 180 deletions
diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs index f627f31dc..5eabb33d0 100644 --- a/crates/ra_assists/src/doc_tests.rs +++ b/crates/ra_assists/src/doc_tests.rs | |||
@@ -12,7 +12,7 @@ use crate::resolved_assists; | |||
12 | 12 | ||
13 | fn check(assist_id: &str, before: &str, after: &str) { | 13 | fn check(assist_id: &str, before: &str, after: &str) { |
14 | let (selection, before) = extract_range_or_offset(before); | 14 | let (selection, before) = extract_range_or_offset(before); |
15 | let (db, file_id) = crate::helpers::with_single_file(&before); | 15 | let (db, file_id) = crate::tests::with_single_file(&before); |
16 | let frange = FileRange { file_id, range: selection.into() }; | 16 | let frange = FileRange { file_id, range: selection.into() }; |
17 | 17 | ||
18 | let assist = resolved_assists(&db, frange) | 18 | let assist = resolved_assists(&db, frange) |
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 4ea26a550..b72f7aeac 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs | |||
@@ -95,7 +95,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
95 | 95 | ||
96 | #[cfg(test)] | 96 | #[cfg(test)] |
97 | mod tests { | 97 | mod tests { |
98 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 98 | use crate::tests::{check_assist, check_assist_not_applicable}; |
99 | 99 | ||
100 | use super::*; | 100 | use super::*; |
101 | 101 | ||
diff --git a/crates/ra_assists/src/handlers/add_derive.rs b/crates/ra_assists/src/handlers/add_derive.rs index 6254eb7c4..3629dac6b 100644 --- a/crates/ra_assists/src/handlers/add_derive.rs +++ b/crates/ra_assists/src/handlers/add_derive.rs | |||
@@ -58,7 +58,7 @@ fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> { | |||
58 | #[cfg(test)] | 58 | #[cfg(test)] |
59 | mod tests { | 59 | mod tests { |
60 | use super::*; | 60 | use super::*; |
61 | use crate::helpers::{check_assist, check_assist_target}; | 61 | use crate::tests::{check_assist, check_assist_target}; |
62 | 62 | ||
63 | #[test] | 63 | #[test] |
64 | fn add_derive_new() { | 64 | fn add_derive_new() { |
diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs index bc313782b..e39e1f4f3 100644 --- a/crates/ra_assists/src/handlers/add_explicit_type.rs +++ b/crates/ra_assists/src/handlers/add_explicit_type.rs | |||
@@ -77,7 +77,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option<Assist> { | |||
77 | mod tests { | 77 | mod tests { |
78 | use super::*; | 78 | use super::*; |
79 | 79 | ||
80 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 80 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
81 | 81 | ||
82 | #[test] | 82 | #[test] |
83 | fn add_explicit_type_target() { | 83 | fn add_explicit_type_target() { |
diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs index 49deb6701..ee0d5ce98 100644 --- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs +++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs | |||
@@ -97,7 +97,7 @@ fn existing_from_impl( | |||
97 | mod tests { | 97 | mod tests { |
98 | use super::*; | 98 | use super::*; |
99 | 99 | ||
100 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 100 | use crate::tests::{check_assist, check_assist_not_applicable}; |
101 | use test_utils::covers; | 101 | use test_utils::covers; |
102 | 102 | ||
103 | #[test] | 103 | #[test] |
diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index 6c7456579..cb2afc863 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs | |||
@@ -283,7 +283,7 @@ fn next_space_for_fn_in_module( | |||
283 | 283 | ||
284 | #[cfg(test)] | 284 | #[cfg(test)] |
285 | mod tests { | 285 | mod tests { |
286 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 286 | use crate::tests::{check_assist, check_assist_not_applicable}; |
287 | 287 | ||
288 | use super::*; | 288 | use super::*; |
289 | 289 | ||
diff --git a/crates/ra_assists/src/handlers/add_impl.rs b/crates/ra_assists/src/handlers/add_impl.rs index d26f8b93d..3d390c20b 100644 --- a/crates/ra_assists/src/handlers/add_impl.rs +++ b/crates/ra_assists/src/handlers/add_impl.rs | |||
@@ -60,7 +60,7 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> { | |||
60 | #[cfg(test)] | 60 | #[cfg(test)] |
61 | mod tests { | 61 | mod tests { |
62 | use super::*; | 62 | use super::*; |
63 | use crate::helpers::{check_assist, check_assist_target}; | 63 | use crate::tests::{check_assist, check_assist_target}; |
64 | 64 | ||
65 | #[test] | 65 | #[test] |
66 | fn test_add_impl() { | 66 | fn test_add_impl() { |
diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index e47feda71..f7a101503 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs | |||
@@ -181,7 +181,7 @@ fn add_body(fn_def: ast::FnDef) -> ast::FnDef { | |||
181 | 181 | ||
182 | #[cfg(test)] | 182 | #[cfg(test)] |
183 | mod tests { | 183 | mod tests { |
184 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 184 | use crate::tests::{check_assist, check_assist_not_applicable}; |
185 | 185 | ||
186 | use super::*; | 186 | use super::*; |
187 | 187 | ||
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index e8a36c7de..1b5d604d1 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs | |||
@@ -178,7 +178,7 @@ fn has_new_fn(imp: &ast::ImplDef) -> bool { | |||
178 | 178 | ||
179 | #[cfg(test)] | 179 | #[cfg(test)] |
180 | mod tests { | 180 | mod tests { |
181 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 181 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
182 | 182 | ||
183 | use super::*; | 183 | use super::*; |
184 | 184 | ||
diff --git a/crates/ra_assists/src/handlers/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs index 260b9e073..a0c48d872 100644 --- a/crates/ra_assists/src/handlers/apply_demorgan.rs +++ b/crates/ra_assists/src/handlers/apply_demorgan.rs | |||
@@ -60,7 +60,7 @@ fn opposite_logic_op(kind: ast::BinOp) -> Option<&'static str> { | |||
60 | mod tests { | 60 | mod tests { |
61 | use super::*; | 61 | use super::*; |
62 | 62 | ||
63 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 63 | use crate::tests::{check_assist, check_assist_not_applicable}; |
64 | 64 | ||
65 | #[test] | 65 | #[test] |
66 | fn demorgan_turns_and_into_or() { | 66 | fn demorgan_turns_and_into_or() { |
diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index db6c4d2fa..9e4171ccd 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs | |||
@@ -277,7 +277,7 @@ impl ImportCandidate { | |||
277 | #[cfg(test)] | 277 | #[cfg(test)] |
278 | mod tests { | 278 | mod tests { |
279 | use super::*; | 279 | use super::*; |
280 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 280 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
281 | 281 | ||
282 | #[test] | 282 | #[test] |
283 | fn applicable_when_found_an_import() { | 283 | fn applicable_when_found_an_import() { |
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index 1cd532e80..6ac1f8e69 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs | |||
@@ -110,7 +110,7 @@ fn change_vis(ctx: AssistCtx, vis: ast::Visibility) -> Option<Assist> { | |||
110 | mod tests { | 110 | mod tests { |
111 | use test_utils::covers; | 111 | use test_utils::covers; |
112 | 112 | ||
113 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 113 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
114 | 114 | ||
115 | use super::*; | 115 | use super::*; |
116 | 116 | ||
diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs index eede2fe91..55ccc37b0 100644 --- a/crates/ra_assists/src/handlers/early_return.rs +++ b/crates/ra_assists/src/handlers/early_return.rs | |||
@@ -182,7 +182,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx) -> Option<Assist> { | |||
182 | 182 | ||
183 | #[cfg(test)] | 183 | #[cfg(test)] |
184 | mod tests { | 184 | mod tests { |
185 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 185 | use crate::tests::{check_assist, check_assist_not_applicable}; |
186 | 186 | ||
187 | use super::*; | 187 | use super::*; |
188 | 188 | ||
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 8d1af9933..1f9cd5585 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs | |||
@@ -168,7 +168,7 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O | |||
168 | 168 | ||
169 | #[cfg(test)] | 169 | #[cfg(test)] |
170 | mod tests { | 170 | mod tests { |
171 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 171 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
172 | 172 | ||
173 | use super::fill_match_arms; | 173 | use super::fill_match_arms; |
174 | 174 | ||
diff --git a/crates/ra_assists/src/handlers/flip_binexpr.rs b/crates/ra_assists/src/handlers/flip_binexpr.rs index 8030efb35..41db963dc 100644 --- a/crates/ra_assists/src/handlers/flip_binexpr.rs +++ b/crates/ra_assists/src/handlers/flip_binexpr.rs | |||
@@ -69,7 +69,7 @@ impl From<BinOp> for FlipAction { | |||
69 | mod tests { | 69 | mod tests { |
70 | use super::*; | 70 | use super::*; |
71 | 71 | ||
72 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 72 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
73 | 73 | ||
74 | #[test] | 74 | #[test] |
75 | fn flip_binexpr_target_is_the_op() { | 75 | fn flip_binexpr_target_is_the_op() { |
diff --git a/crates/ra_assists/src/handlers/flip_comma.rs b/crates/ra_assists/src/handlers/flip_comma.rs index 1dacf29f8..e65c9a41d 100644 --- a/crates/ra_assists/src/handlers/flip_comma.rs +++ b/crates/ra_assists/src/handlers/flip_comma.rs | |||
@@ -39,7 +39,7 @@ pub(crate) fn flip_comma(ctx: AssistCtx) -> Option<Assist> { | |||
39 | mod tests { | 39 | mod tests { |
40 | use super::*; | 40 | use super::*; |
41 | 41 | ||
42 | use crate::helpers::{check_assist, check_assist_target}; | 42 | use crate::tests::{check_assist, check_assist_target}; |
43 | 43 | ||
44 | #[test] | 44 | #[test] |
45 | fn flip_comma_works_for_function_parameters() { | 45 | fn flip_comma_works_for_function_parameters() { |
diff --git a/crates/ra_assists/src/handlers/flip_trait_bound.rs b/crates/ra_assists/src/handlers/flip_trait_bound.rs index f56769624..f186da585 100644 --- a/crates/ra_assists/src/handlers/flip_trait_bound.rs +++ b/crates/ra_assists/src/handlers/flip_trait_bound.rs | |||
@@ -43,7 +43,7 @@ pub(crate) fn flip_trait_bound(ctx: AssistCtx) -> Option<Assist> { | |||
43 | mod tests { | 43 | mod tests { |
44 | use super::*; | 44 | use super::*; |
45 | 45 | ||
46 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 46 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
47 | 47 | ||
48 | #[test] | 48 | #[test] |
49 | fn flip_trait_bound_assist_available() { | 49 | fn flip_trait_bound_assist_available() { |
diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index 60ec536a7..5f3b8dfd1 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs | |||
@@ -125,7 +125,7 @@ pub(crate) fn inline_local_variable(ctx: AssistCtx) -> Option<Assist> { | |||
125 | mod tests { | 125 | mod tests { |
126 | use test_utils::covers; | 126 | use test_utils::covers; |
127 | 127 | ||
128 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 128 | use crate::tests::{check_assist, check_assist_not_applicable}; |
129 | 129 | ||
130 | use super::*; | 130 | use super::*; |
131 | 131 | ||
diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs index 39c656305..9c2c20b22 100644 --- a/crates/ra_assists/src/handlers/introduce_variable.rs +++ b/crates/ra_assists/src/handlers/introduce_variable.rs | |||
@@ -136,7 +136,7 @@ fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> { | |||
136 | mod tests { | 136 | mod tests { |
137 | use test_utils::covers; | 137 | use test_utils::covers; |
138 | 138 | ||
139 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 139 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
140 | 140 | ||
141 | use super::*; | 141 | use super::*; |
142 | 142 | ||
diff --git a/crates/ra_assists/src/handlers/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs index 682e08512..303c1806d 100644 --- a/crates/ra_assists/src/handlers/invert_if.rs +++ b/crates/ra_assists/src/handlers/invert_if.rs | |||
@@ -62,7 +62,7 @@ pub(crate) fn invert_if(ctx: AssistCtx) -> Option<Assist> { | |||
62 | mod tests { | 62 | mod tests { |
63 | use super::*; | 63 | use super::*; |
64 | 64 | ||
65 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 65 | use crate::tests::{check_assist, check_assist_not_applicable}; |
66 | 66 | ||
67 | #[test] | 67 | #[test] |
68 | fn invert_if_remove_inequality() { | 68 | fn invert_if_remove_inequality() { |
diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index 4be1238f1..9a2083609 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs | |||
@@ -125,7 +125,7 @@ fn first_path(path: &ast::Path) -> ast::Path { | |||
125 | 125 | ||
126 | #[cfg(test)] | 126 | #[cfg(test)] |
127 | mod tests { | 127 | mod tests { |
128 | use crate::helpers::check_assist; | 128 | use crate::tests::check_assist; |
129 | 129 | ||
130 | use super::*; | 130 | use super::*; |
131 | 131 | ||
diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs index 5a77d3dbc..9ae099b41 100644 --- a/crates/ra_assists/src/handlers/merge_match_arms.rs +++ b/crates/ra_assists/src/handlers/merge_match_arms.rs | |||
@@ -105,7 +105,7 @@ fn contains_placeholder(a: &ast::MatchArm) -> bool { | |||
105 | 105 | ||
106 | #[cfg(test)] | 106 | #[cfg(test)] |
107 | mod tests { | 107 | mod tests { |
108 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 108 | use crate::tests::{check_assist, check_assist_not_applicable}; |
109 | 109 | ||
110 | use super::*; | 110 | use super::*; |
111 | 111 | ||
diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs index 0f26884dc..89956aea9 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs | |||
@@ -89,7 +89,7 @@ fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { | |||
89 | mod tests { | 89 | mod tests { |
90 | use super::*; | 90 | use super::*; |
91 | 91 | ||
92 | use crate::helpers::check_assist; | 92 | use crate::tests::check_assist; |
93 | 93 | ||
94 | #[test] | 94 | #[test] |
95 | fn move_bounds_to_where_clause_fn() { | 95 | fn move_bounds_to_where_clause_fn() { |
diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs index b084dd9ee..f2aa7e594 100644 --- a/crates/ra_assists/src/handlers/move_guard.rs +++ b/crates/ra_assists/src/handlers/move_guard.rs | |||
@@ -132,7 +132,7 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> { | |||
132 | mod tests { | 132 | mod tests { |
133 | use super::*; | 133 | use super::*; |
134 | 134 | ||
135 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 135 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
136 | 136 | ||
137 | #[test] | 137 | #[test] |
138 | fn move_guard_to_arm_body_target() { | 138 | fn move_guard_to_arm_body_target() { |
diff --git a/crates/ra_assists/src/handlers/raw_string.rs b/crates/ra_assists/src/handlers/raw_string.rs index 567400b9c..542f7a637 100644 --- a/crates/ra_assists/src/handlers/raw_string.rs +++ b/crates/ra_assists/src/handlers/raw_string.rs | |||
@@ -138,7 +138,7 @@ fn count_hashes(s: &str) -> usize { | |||
138 | #[cfg(test)] | 138 | #[cfg(test)] |
139 | mod test { | 139 | mod test { |
140 | use super::*; | 140 | use super::*; |
141 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 141 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
142 | 142 | ||
143 | #[test] | 143 | #[test] |
144 | fn make_raw_string_target() { | 144 | fn make_raw_string_target() { |
diff --git a/crates/ra_assists/src/handlers/remove_dbg.rs b/crates/ra_assists/src/handlers/remove_dbg.rs index 4e5eb4350..ddfb21a7e 100644 --- a/crates/ra_assists/src/handlers/remove_dbg.rs +++ b/crates/ra_assists/src/handlers/remove_dbg.rs | |||
@@ -90,7 +90,7 @@ fn is_valid_macrocall(macro_call: &ast::MacroCall, macro_name: &str) -> Option<b | |||
90 | #[cfg(test)] | 90 | #[cfg(test)] |
91 | mod tests { | 91 | mod tests { |
92 | use super::*; | 92 | use super::*; |
93 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 93 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
94 | 94 | ||
95 | #[test] | 95 | #[test] |
96 | fn test_remove_dbg() { | 96 | fn test_remove_dbg() { |
diff --git a/crates/ra_assists/src/handlers/reorder_fields.rs b/crates/ra_assists/src/handlers/reorder_fields.rs index 5cbb98d73..a57e327b8 100644 --- a/crates/ra_assists/src/handlers/reorder_fields.rs +++ b/crates/ra_assists/src/handlers/reorder_fields.rs | |||
@@ -109,7 +109,7 @@ fn compute_fields_ranks(path: &Path, ctx: &AssistCtx) -> Option<HashMap<String, | |||
109 | 109 | ||
110 | #[cfg(test)] | 110 | #[cfg(test)] |
111 | mod tests { | 111 | mod tests { |
112 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 112 | use crate::tests::{check_assist, check_assist_not_applicable}; |
113 | 113 | ||
114 | use super::*; | 114 | use super::*; |
115 | 115 | ||
diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs index 9841f6980..d0df3b84e 100644 --- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs | |||
@@ -74,7 +74,7 @@ pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> { | |||
74 | mod tests { | 74 | mod tests { |
75 | use super::*; | 75 | use super::*; |
76 | 76 | ||
77 | use crate::helpers::{check_assist, check_assist_target}; | 77 | use crate::tests::{check_assist, check_assist_target}; |
78 | 78 | ||
79 | #[test] | 79 | #[test] |
80 | fn test_replace_if_let_with_match_unwraps_simple_expressions() { | 80 | fn test_replace_if_let_with_match_unwraps_simple_expressions() { |
diff --git a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs index 0cf23b754..dc4d16055 100644 --- a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs +++ b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs | |||
@@ -74,7 +74,7 @@ pub(crate) fn replace_let_with_if_let(ctx: AssistCtx) -> Option<Assist> { | |||
74 | 74 | ||
75 | #[cfg(test)] | 75 | #[cfg(test)] |
76 | mod tests { | 76 | mod tests { |
77 | use crate::helpers::check_assist; | 77 | use crate::tests::check_assist; |
78 | 78 | ||
79 | use super::*; | 79 | use super::*; |
80 | 80 | ||
diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index ff2463c77..624178924 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs | |||
@@ -74,7 +74,7 @@ fn collect_hir_path_segments(path: &hir::Path) -> Option<Vec<SmolStr>> { | |||
74 | 74 | ||
75 | #[cfg(test)] | 75 | #[cfg(test)] |
76 | mod tests { | 76 | mod tests { |
77 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 77 | use crate::tests::{check_assist, check_assist_not_applicable}; |
78 | 78 | ||
79 | use super::*; | 79 | use super::*; |
80 | 80 | ||
diff --git a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs index 62d4ea522..dcb471edb 100644 --- a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs | |||
@@ -63,7 +63,7 @@ pub(crate) fn replace_unwrap_with_match(ctx: AssistCtx) -> Option<Assist> { | |||
63 | #[cfg(test)] | 63 | #[cfg(test)] |
64 | mod tests { | 64 | mod tests { |
65 | use super::*; | 65 | use super::*; |
66 | use crate::helpers::{check_assist, check_assist_target}; | 66 | use crate::tests::{check_assist, check_assist_target}; |
67 | 67 | ||
68 | #[test] | 68 | #[test] |
69 | fn test_replace_result_unwrap_with_match() { | 69 | fn test_replace_result_unwrap_with_match() { |
diff --git a/crates/ra_assists/src/handlers/split_import.rs b/crates/ra_assists/src/handlers/split_import.rs index f25826796..a59f2f76f 100644 --- a/crates/ra_assists/src/handlers/split_import.rs +++ b/crates/ra_assists/src/handlers/split_import.rs | |||
@@ -37,7 +37,7 @@ pub(crate) fn split_import(ctx: AssistCtx) -> Option<Assist> { | |||
37 | 37 | ||
38 | #[cfg(test)] | 38 | #[cfg(test)] |
39 | mod tests { | 39 | mod tests { |
40 | use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; | 40 | use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; |
41 | 41 | ||
42 | use super::*; | 42 | use super::*; |
43 | 43 | ||
diff --git a/crates/ra_assists/src/handlers/unwrap_block.rs b/crates/ra_assists/src/handlers/unwrap_block.rs index 859c70ad8..89992117d 100644 --- a/crates/ra_assists/src/handlers/unwrap_block.rs +++ b/crates/ra_assists/src/handlers/unwrap_block.rs | |||
@@ -89,7 +89,7 @@ fn extract_expr(cursor_range: TextRange, block: ast::BlockExpr) -> Option<ast::E | |||
89 | 89 | ||
90 | #[cfg(test)] | 90 | #[cfg(test)] |
91 | mod tests { | 91 | mod tests { |
92 | use crate::helpers::{check_assist, check_assist_not_applicable}; | 92 | use crate::tests::{check_assist, check_assist_not_applicable}; |
93 | 93 | ||
94 | use super::*; | 94 | use super::*; |
95 | 95 | ||
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 0f94f5ee8..b84d60c77 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -14,6 +14,8 @@ mod assist_ctx; | |||
14 | mod marks; | 14 | mod marks; |
15 | #[cfg(test)] | 15 | #[cfg(test)] |
16 | mod doc_tests; | 16 | mod doc_tests; |
17 | #[cfg(test)] | ||
18 | mod tests; | ||
17 | pub mod utils; | 19 | pub mod utils; |
18 | pub mod ast_transform; | 20 | pub mod ast_transform; |
19 | 21 | ||
@@ -194,150 +196,3 @@ mod handlers { | |||
194 | ] | 196 | ] |
195 | } | 197 | } |
196 | } | 198 | } |
197 | |||
198 | #[cfg(test)] | ||
199 | mod helpers { | ||
200 | use std::sync::Arc; | ||
201 | |||
202 | use hir::Semantics; | ||
203 | use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; | ||
204 | use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; | ||
205 | use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset}; | ||
206 | |||
207 | use crate::{handlers::Handler, AssistCtx, AssistFile}; | ||
208 | |||
209 | pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { | ||
210 | let (mut db, file_id) = RootDatabase::with_single_file(text); | ||
211 | // FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`, | ||
212 | // but it looks like this might need specialization? :( | ||
213 | db.set_local_roots(Arc::new(vec![db.file_source_root(file_id)])); | ||
214 | (db, file_id) | ||
215 | } | ||
216 | |||
217 | pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { | ||
218 | check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); | ||
219 | } | ||
220 | |||
221 | // FIXME: instead of having a separate function here, maybe use | ||
222 | // `extract_ranges` and mark the target as `<target> </target>` in the | ||
223 | // fixuture? | ||
224 | pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { | ||
225 | check(assist, ra_fixture, ExpectedResult::Target(target)); | ||
226 | } | ||
227 | |||
228 | pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { | ||
229 | check(assist, ra_fixture, ExpectedResult::NotApplicable); | ||
230 | } | ||
231 | |||
232 | enum ExpectedResult<'a> { | ||
233 | NotApplicable, | ||
234 | After(&'a str), | ||
235 | Target(&'a str), | ||
236 | } | ||
237 | |||
238 | fn check(assist: Handler, before: &str, expected: ExpectedResult) { | ||
239 | let (text_without_caret, file_with_caret_id, range_or_offset, db) = | ||
240 | if before.contains("//-") { | ||
241 | let (mut db, position) = RootDatabase::with_position(before); | ||
242 | db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)])); | ||
243 | ( | ||
244 | db.file_text(position.file_id).as_ref().to_owned(), | ||
245 | position.file_id, | ||
246 | RangeOrOffset::Offset(position.offset), | ||
247 | db, | ||
248 | ) | ||
249 | } else { | ||
250 | let (range_or_offset, text_without_caret) = extract_range_or_offset(before); | ||
251 | let (db, file_id) = with_single_file(&text_without_caret); | ||
252 | (text_without_caret, file_id, range_or_offset, db) | ||
253 | }; | ||
254 | |||
255 | let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; | ||
256 | |||
257 | let sema = Semantics::new(&db); | ||
258 | let assist_ctx = AssistCtx::new(&sema, frange, true); | ||
259 | |||
260 | match (assist(assist_ctx), expected) { | ||
261 | (Some(assist), ExpectedResult::After(after)) => { | ||
262 | let action = assist.0[0].action.clone().unwrap(); | ||
263 | |||
264 | let mut actual = if let AssistFile::TargetFile(file_id) = action.file { | ||
265 | db.file_text(file_id).as_ref().to_owned() | ||
266 | } else { | ||
267 | text_without_caret | ||
268 | }; | ||
269 | action.edit.apply(&mut actual); | ||
270 | |||
271 | match action.cursor_position { | ||
272 | None => { | ||
273 | if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { | ||
274 | let off = action | ||
275 | .edit | ||
276 | .apply_to_offset(before_cursor_pos) | ||
277 | .expect("cursor position is affected by the edit"); | ||
278 | actual = add_cursor(&actual, off) | ||
279 | } | ||
280 | } | ||
281 | Some(off) => actual = add_cursor(&actual, off), | ||
282 | }; | ||
283 | |||
284 | assert_eq_text!(after, &actual); | ||
285 | } | ||
286 | (Some(assist), ExpectedResult::Target(target)) => { | ||
287 | let action = assist.0[0].action.clone().unwrap(); | ||
288 | let range = action.target.expect("expected target on action"); | ||
289 | assert_eq_text!(&text_without_caret[range], target); | ||
290 | } | ||
291 | (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), | ||
292 | (None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => { | ||
293 | panic!("code action is not applicable") | ||
294 | } | ||
295 | (None, ExpectedResult::NotApplicable) => (), | ||
296 | }; | ||
297 | } | ||
298 | } | ||
299 | |||
300 | #[cfg(test)] | ||
301 | mod tests { | ||
302 | use ra_db::FileRange; | ||
303 | use ra_syntax::TextRange; | ||
304 | use test_utils::{extract_offset, extract_range}; | ||
305 | |||
306 | use crate::{helpers, resolved_assists}; | ||
307 | |||
308 | #[test] | ||
309 | fn assist_order_field_struct() { | ||
310 | let before = "struct Foo { <|>bar: u32 }"; | ||
311 | let (before_cursor_pos, before) = extract_offset(before); | ||
312 | let (db, file_id) = helpers::with_single_file(&before); | ||
313 | let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; | ||
314 | let assists = resolved_assists(&db, frange); | ||
315 | let mut assists = assists.iter(); | ||
316 | |||
317 | assert_eq!( | ||
318 | assists.next().expect("expected assist").label.label, | ||
319 | "Change visibility to pub(crate)" | ||
320 | ); | ||
321 | assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`"); | ||
322 | } | ||
323 | |||
324 | #[test] | ||
325 | fn assist_order_if_expr() { | ||
326 | let before = " | ||
327 | pub fn test_some_range(a: int) -> bool { | ||
328 | if let 2..6 = <|>5<|> { | ||
329 | true | ||
330 | } else { | ||
331 | false | ||
332 | } | ||
333 | }"; | ||
334 | let (range, before) = extract_range(before); | ||
335 | let (db, file_id) = helpers::with_single_file(&before); | ||
336 | let frange = FileRange { file_id, range }; | ||
337 | let assists = resolved_assists(&db, frange); | ||
338 | let mut assists = assists.iter(); | ||
339 | |||
340 | assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable"); | ||
341 | assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match"); | ||
342 | } | ||
343 | } | ||
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 @@ | |||
1 | use std::sync::Arc; | ||
2 | |||
3 | use hir::Semantics; | ||
4 | use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; | ||
5 | use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; | ||
6 | use ra_syntax::TextRange; | ||
7 | use test_utils::{ | ||
8 | add_cursor, assert_eq_text, extract_offset, extract_range, extract_range_or_offset, | ||
9 | RangeOrOffset, | ||
10 | }; | ||
11 | |||
12 | use crate::{handlers::Handler, resolved_assists, AssistCtx, AssistFile}; | ||
13 | |||
14 | pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { | ||
15 | let (mut db, file_id) = RootDatabase::with_single_file(text); | ||
16 | // FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`, | ||
17 | // but it looks like this might need specialization? :( | ||
18 | db.set_local_roots(Arc::new(vec![db.file_source_root(file_id)])); | ||
19 | (db, file_id) | ||
20 | } | ||
21 | |||
22 | pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { | ||
23 | check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); | ||
24 | } | ||
25 | |||
26 | // FIXME: instead of having a separate function here, maybe use | ||
27 | // `extract_ranges` and mark the target as `<target> </target>` in the | ||
28 | // fixuture? | ||
29 | pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { | ||
30 | check(assist, ra_fixture, ExpectedResult::Target(target)); | ||
31 | } | ||
32 | |||
33 | pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { | ||
34 | check(assist, ra_fixture, ExpectedResult::NotApplicable); | ||
35 | } | ||
36 | |||
37 | enum ExpectedResult<'a> { | ||
38 | NotApplicable, | ||
39 | After(&'a str), | ||
40 | Target(&'a str), | ||
41 | } | ||
42 | |||
43 | fn check(assist: Handler, before: &str, expected: ExpectedResult) { | ||
44 | let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { | ||
45 | let (mut db, position) = RootDatabase::with_position(before); | ||
46 | db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)])); | ||
47 | ( | ||
48 | db.file_text(position.file_id).as_ref().to_owned(), | ||
49 | position.file_id, | ||
50 | RangeOrOffset::Offset(position.offset), | ||
51 | db, | ||
52 | ) | ||
53 | } else { | ||
54 | let (range_or_offset, text_without_caret) = extract_range_or_offset(before); | ||
55 | let (db, file_id) = with_single_file(&text_without_caret); | ||
56 | (text_without_caret, file_id, range_or_offset, db) | ||
57 | }; | ||
58 | |||
59 | let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; | ||
60 | |||
61 | let sema = Semantics::new(&db); | ||
62 | let assist_ctx = AssistCtx::new(&sema, frange, true); | ||
63 | |||
64 | match (assist(assist_ctx), expected) { | ||
65 | (Some(assist), ExpectedResult::After(after)) => { | ||
66 | let action = assist.0[0].action.clone().unwrap(); | ||
67 | |||
68 | let mut actual = if let AssistFile::TargetFile(file_id) = action.file { | ||
69 | db.file_text(file_id).as_ref().to_owned() | ||
70 | } else { | ||
71 | text_without_caret | ||
72 | }; | ||
73 | action.edit.apply(&mut actual); | ||
74 | |||
75 | match action.cursor_position { | ||
76 | None => { | ||
77 | if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { | ||
78 | let off = action | ||
79 | .edit | ||
80 | .apply_to_offset(before_cursor_pos) | ||
81 | .expect("cursor position is affected by the edit"); | ||
82 | actual = add_cursor(&actual, off) | ||
83 | } | ||
84 | } | ||
85 | Some(off) => actual = add_cursor(&actual, off), | ||
86 | }; | ||
87 | |||
88 | assert_eq_text!(after, &actual); | ||
89 | } | ||
90 | (Some(assist), ExpectedResult::Target(target)) => { | ||
91 | let action = assist.0[0].action.clone().unwrap(); | ||
92 | let range = action.target.expect("expected target on action"); | ||
93 | assert_eq_text!(&text_without_caret[range], target); | ||
94 | } | ||
95 | (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), | ||
96 | (None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => { | ||
97 | panic!("code action is not applicable") | ||
98 | } | ||
99 | (None, ExpectedResult::NotApplicable) => (), | ||
100 | }; | ||
101 | } | ||
102 | |||
103 | #[test] | ||
104 | fn assist_order_field_struct() { | ||
105 | let before = "struct Foo { <|>bar: u32 }"; | ||
106 | let (before_cursor_pos, before) = extract_offset(before); | ||
107 | let (db, file_id) = with_single_file(&before); | ||
108 | let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; | ||
109 | let assists = resolved_assists(&db, frange); | ||
110 | let mut assists = assists.iter(); | ||
111 | |||
112 | assert_eq!( | ||
113 | assists.next().expect("expected assist").label.label, | ||
114 | "Change visibility to pub(crate)" | ||
115 | ); | ||
116 | assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`"); | ||
117 | } | ||
118 | |||
119 | #[test] | ||
120 | fn assist_order_if_expr() { | ||
121 | let before = " | ||
122 | pub fn test_some_range(a: int) -> bool { | ||
123 | if let 2..6 = <|>5<|> { | ||
124 | true | ||
125 | } else { | ||
126 | false | ||
127 | } | ||
128 | }"; | ||
129 | let (range, before) = extract_range(before); | ||
130 | let (db, file_id) = with_single_file(&before); | ||
131 | let frange = FileRange { file_id, range }; | ||
132 | let assists = resolved_assists(&db, frange); | ||
133 | let mut assists = assists.iter(); | ||
134 | |||
135 | assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable"); | ||
136 | assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match"); | ||
137 | } | ||