diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-06 09:22:10 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-06 09:22:10 +0100 |
commit | d81bf3772fa2802dbcb808f64835352519e832a3 (patch) | |
tree | 4797a973b944a831f5567953aa6c991f658d454b | |
parent | 30eb458b4fa8adcecd8cbf731bd1cfa9a7a8b88b (diff) | |
parent | eea431180eb5267928c8e0d4b8099ab1042e01d1 (diff) |
Merge #4337
4337: Cleanup assists tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
39 files changed, 242 insertions, 261 deletions
diff --git a/crates/ra_assists/src/doc_tests.rs b/crates/ra_assists/src/doc_tests.rs deleted file mode 100644 index f627f31dc..000000000 --- a/crates/ra_assists/src/doc_tests.rs +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | //! Each assist definition has a special comment, which specifies docs and | ||
2 | //! example. | ||
3 | //! | ||
4 | //! We collect all the example and write the as tests in this module. | ||
5 | |||
6 | mod generated; | ||
7 | |||
8 | use ra_db::FileRange; | ||
9 | use test_utils::{assert_eq_text, extract_range_or_offset}; | ||
10 | |||
11 | use crate::resolved_assists; | ||
12 | |||
13 | fn check(assist_id: &str, before: &str, after: &str) { | ||
14 | let (selection, before) = extract_range_or_offset(before); | ||
15 | let (db, file_id) = crate::helpers::with_single_file(&before); | ||
16 | let frange = FileRange { file_id, range: selection.into() }; | ||
17 | |||
18 | let assist = resolved_assists(&db, frange) | ||
19 | .into_iter() | ||
20 | .find(|assist| assist.label.id.0 == assist_id) | ||
21 | .unwrap_or_else(|| { | ||
22 | panic!( | ||
23 | "\n\nAssist is not applicable: {}\nAvailable assists: {}", | ||
24 | assist_id, | ||
25 | resolved_assists(&db, frange) | ||
26 | .into_iter() | ||
27 | .map(|assist| assist.label.id.0) | ||
28 | .collect::<Vec<_>>() | ||
29 | .join(", ") | ||
30 | ) | ||
31 | }); | ||
32 | |||
33 | let actual = { | ||
34 | let mut actual = before.clone(); | ||
35 | assist.action.edit.apply(&mut actual); | ||
36 | actual | ||
37 | }; | ||
38 | assert_eq_text!(after, &actual); | ||
39 | } | ||
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..b794b021d 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -13,7 +13,7 @@ macro_rules! eprintln { | |||
13 | mod assist_ctx; | 13 | mod assist_ctx; |
14 | mod marks; | 14 | mod marks; |
15 | #[cfg(test)] | 15 | #[cfg(test)] |
16 | mod doc_tests; | 16 | mod tests; |
17 | pub mod utils; | 17 | pub mod utils; |
18 | pub mod ast_transform; | 18 | pub mod ast_transform; |
19 | 19 | ||
@@ -194,150 +194,3 @@ mod handlers { | |||
194 | ] | 194 | ] |
195 | } | 195 | } |
196 | } | 196 | } |
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..483e11931 --- /dev/null +++ b/crates/ra_assists/src/tests.rs | |||
@@ -0,0 +1,167 @@ | |||
1 | mod generated; | ||
2 | |||
3 | use std::sync::Arc; | ||
4 | |||
5 | use hir::Semantics; | ||
6 | use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; | ||
7 | use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; | ||
8 | use ra_syntax::TextRange; | ||
9 | use test_utils::{ | ||
10 | add_cursor, assert_eq_text, extract_offset, extract_range, extract_range_or_offset, | ||
11 | RangeOrOffset, | ||
12 | }; | ||
13 | |||
14 | use crate::{handlers::Handler, resolved_assists, AssistCtx, AssistFile}; | ||
15 | |||
16 | pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { | ||
17 | let (mut db, file_id) = RootDatabase::with_single_file(text); | ||
18 | // FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`, | ||
19 | // but it looks like this might need specialization? :( | ||
20 | db.set_local_roots(Arc::new(vec![db.file_source_root(file_id)])); | ||
21 | (db, file_id) | ||
22 | } | ||
23 | |||
24 | pub(crate) fn check_assist(assist: Handler, ra_fixture_before: &str, ra_fixture_after: &str) { | ||
25 | check(assist, ra_fixture_before, ExpectedResult::After(ra_fixture_after)); | ||
26 | } | ||
27 | |||
28 | // FIXME: instead of having a separate function here, maybe use | ||
29 | // `extract_ranges` and mark the target as `<target> </target>` in the | ||
30 | // fixuture? | ||
31 | pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { | ||
32 | check(assist, ra_fixture, ExpectedResult::Target(target)); | ||
33 | } | ||
34 | |||
35 | pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { | ||
36 | check(assist, ra_fixture, ExpectedResult::NotApplicable); | ||
37 | } | ||
38 | |||
39 | fn check_doc_test(assist_id: &str, before: &str, after: &str) { | ||
40 | let (selection, before) = extract_range_or_offset(before); | ||
41 | let (db, file_id) = crate::tests::with_single_file(&before); | ||
42 | let frange = FileRange { file_id, range: selection.into() }; | ||
43 | |||
44 | let assist = resolved_assists(&db, frange) | ||
45 | .into_iter() | ||
46 | .find(|assist| assist.label.id.0 == assist_id) | ||
47 | .unwrap_or_else(|| { | ||
48 | panic!( | ||
49 | "\n\nAssist is not applicable: {}\nAvailable assists: {}", | ||
50 | assist_id, | ||
51 | resolved_assists(&db, frange) | ||
52 | .into_iter() | ||
53 | .map(|assist| assist.label.id.0) | ||
54 | .collect::<Vec<_>>() | ||
55 | .join(", ") | ||
56 | ) | ||
57 | }); | ||
58 | |||
59 | let actual = { | ||
60 | let mut actual = before.clone(); | ||
61 | assist.action.edit.apply(&mut actual); | ||
62 | actual | ||
63 | }; | ||
64 | assert_eq_text!(after, &actual); | ||
65 | } | ||
66 | |||
67 | enum ExpectedResult<'a> { | ||
68 | NotApplicable, | ||
69 | After(&'a str), | ||
70 | Target(&'a str), | ||
71 | } | ||
72 | |||
73 | fn check(assist: Handler, before: &str, expected: ExpectedResult) { | ||
74 | let (text_without_caret, file_with_caret_id, range_or_offset, db) = if before.contains("//-") { | ||
75 | let (mut db, position) = RootDatabase::with_position(before); | ||
76 | db.set_local_roots(Arc::new(vec![db.file_source_root(position.file_id)])); | ||
77 | ( | ||
78 | db.file_text(position.file_id).as_ref().to_owned(), | ||
79 | position.file_id, | ||
80 | RangeOrOffset::Offset(position.offset), | ||
81 | db, | ||
82 | ) | ||
83 | } else { | ||
84 | let (range_or_offset, text_without_caret) = extract_range_or_offset(before); | ||
85 | let (db, file_id) = with_single_file(&text_without_caret); | ||
86 | (text_without_caret, file_id, range_or_offset, db) | ||
87 | }; | ||
88 | |||
89 | let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() }; | ||
90 | |||
91 | let sema = Semantics::new(&db); | ||
92 | let assist_ctx = AssistCtx::new(&sema, frange, true); | ||
93 | |||
94 | match (assist(assist_ctx), expected) { | ||
95 | (Some(assist), ExpectedResult::After(after)) => { | ||
96 | let action = assist.0[0].action.clone().unwrap(); | ||
97 | |||
98 | let mut actual = if let AssistFile::TargetFile(file_id) = action.file { | ||
99 | db.file_text(file_id).as_ref().to_owned() | ||
100 | } else { | ||
101 | text_without_caret | ||
102 | }; | ||
103 | action.edit.apply(&mut actual); | ||
104 | |||
105 | match action.cursor_position { | ||
106 | None => { | ||
107 | if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { | ||
108 | let off = action | ||
109 | .edit | ||
110 | .apply_to_offset(before_cursor_pos) | ||
111 | .expect("cursor position is affected by the edit"); | ||
112 | actual = add_cursor(&actual, off) | ||
113 | } | ||
114 | } | ||
115 | Some(off) => actual = add_cursor(&actual, off), | ||
116 | }; | ||
117 | |||
118 | assert_eq_text!(after, &actual); | ||
119 | } | ||
120 | (Some(assist), ExpectedResult::Target(target)) => { | ||
121 | let action = assist.0[0].action.clone().unwrap(); | ||
122 | let range = action.target.expect("expected target on action"); | ||
123 | assert_eq_text!(&text_without_caret[range], target); | ||
124 | } | ||
125 | (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), | ||
126 | (None, ExpectedResult::After(_)) | (None, ExpectedResult::Target(_)) => { | ||
127 | panic!("code action is not applicable") | ||
128 | } | ||
129 | (None, ExpectedResult::NotApplicable) => (), | ||
130 | }; | ||
131 | } | ||
132 | |||
133 | #[test] | ||
134 | fn assist_order_field_struct() { | ||
135 | let before = "struct Foo { <|>bar: u32 }"; | ||
136 | let (before_cursor_pos, before) = extract_offset(before); | ||
137 | let (db, file_id) = with_single_file(&before); | ||
138 | let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; | ||
139 | let assists = resolved_assists(&db, frange); | ||
140 | let mut assists = assists.iter(); | ||
141 | |||
142 | assert_eq!( | ||
143 | assists.next().expect("expected assist").label.label, | ||
144 | "Change visibility to pub(crate)" | ||
145 | ); | ||
146 | assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`"); | ||
147 | } | ||
148 | |||
149 | #[test] | ||
150 | fn assist_order_if_expr() { | ||
151 | let before = " | ||
152 | pub fn test_some_range(a: int) -> bool { | ||
153 | if let 2..6 = <|>5<|> { | ||
154 | true | ||
155 | } else { | ||
156 | false | ||
157 | } | ||
158 | }"; | ||
159 | let (range, before) = extract_range(before); | ||
160 | let (db, file_id) = with_single_file(&before); | ||
161 | let frange = FileRange { file_id, range }; | ||
162 | let assists = resolved_assists(&db, frange); | ||
163 | let mut assists = assists.iter(); | ||
164 | |||
165 | assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable"); | ||
166 | assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match"); | ||
167 | } | ||
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/tests/generated.rs index 6696cc832..7d35fa284 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/tests/generated.rs | |||
@@ -1,10 +1,10 @@ | |||
1 | //! Generated file, do not edit by hand, see `xtask/src/codegen` | 1 | //! Generated file, do not edit by hand, see `xtask/src/codegen` |
2 | 2 | ||
3 | use super::check; | 3 | use super::check_doc_test; |
4 | 4 | ||
5 | #[test] | 5 | #[test] |
6 | fn doctest_add_custom_impl() { | 6 | fn doctest_add_custom_impl() { |
7 | check( | 7 | check_doc_test( |
8 | "add_custom_impl", | 8 | "add_custom_impl", |
9 | r#####" | 9 | r#####" |
10 | #[derive(Deb<|>ug, Display)] | 10 | #[derive(Deb<|>ug, Display)] |
@@ -23,7 +23,7 @@ impl Debug for S { | |||
23 | 23 | ||
24 | #[test] | 24 | #[test] |
25 | fn doctest_add_derive() { | 25 | fn doctest_add_derive() { |
26 | check( | 26 | check_doc_test( |
27 | "add_derive", | 27 | "add_derive", |
28 | r#####" | 28 | r#####" |
29 | struct Point { | 29 | struct Point { |
@@ -43,7 +43,7 @@ struct Point { | |||
43 | 43 | ||
44 | #[test] | 44 | #[test] |
45 | fn doctest_add_explicit_type() { | 45 | fn doctest_add_explicit_type() { |
46 | check( | 46 | check_doc_test( |
47 | "add_explicit_type", | 47 | "add_explicit_type", |
48 | r#####" | 48 | r#####" |
49 | fn main() { | 49 | fn main() { |
@@ -60,7 +60,7 @@ fn main() { | |||
60 | 60 | ||
61 | #[test] | 61 | #[test] |
62 | fn doctest_add_function() { | 62 | fn doctest_add_function() { |
63 | check( | 63 | check_doc_test( |
64 | "add_function", | 64 | "add_function", |
65 | r#####" | 65 | r#####" |
66 | struct Baz; | 66 | struct Baz; |
@@ -87,7 +87,7 @@ fn bar(arg: &str, baz: Baz) { | |||
87 | 87 | ||
88 | #[test] | 88 | #[test] |
89 | fn doctest_add_hash() { | 89 | fn doctest_add_hash() { |
90 | check( | 90 | check_doc_test( |
91 | "add_hash", | 91 | "add_hash", |
92 | r#####" | 92 | r#####" |
93 | fn main() { | 93 | fn main() { |
@@ -104,7 +104,7 @@ fn main() { | |||
104 | 104 | ||
105 | #[test] | 105 | #[test] |
106 | fn doctest_add_impl() { | 106 | fn doctest_add_impl() { |
107 | check( | 107 | check_doc_test( |
108 | "add_impl", | 108 | "add_impl", |
109 | r#####" | 109 | r#####" |
110 | struct Ctx<T: Clone> { | 110 | struct Ctx<T: Clone> { |
@@ -125,7 +125,7 @@ impl<T: Clone> Ctx<T> { | |||
125 | 125 | ||
126 | #[test] | 126 | #[test] |
127 | fn doctest_add_impl_default_members() { | 127 | fn doctest_add_impl_default_members() { |
128 | check( | 128 | check_doc_test( |
129 | "add_impl_default_members", | 129 | "add_impl_default_members", |
130 | r#####" | 130 | r#####" |
131 | trait Trait { | 131 | trait Trait { |
@@ -159,7 +159,7 @@ impl Trait for () { | |||
159 | 159 | ||
160 | #[test] | 160 | #[test] |
161 | fn doctest_add_impl_missing_members() { | 161 | fn doctest_add_impl_missing_members() { |
162 | check( | 162 | check_doc_test( |
163 | "add_impl_missing_members", | 163 | "add_impl_missing_members", |
164 | r#####" | 164 | r#####" |
165 | trait Trait<T> { | 165 | trait Trait<T> { |
@@ -191,7 +191,7 @@ impl Trait<u32> for () { | |||
191 | 191 | ||
192 | #[test] | 192 | #[test] |
193 | fn doctest_add_new() { | 193 | fn doctest_add_new() { |
194 | check( | 194 | check_doc_test( |
195 | "add_new", | 195 | "add_new", |
196 | r#####" | 196 | r#####" |
197 | struct Ctx<T: Clone> { | 197 | struct Ctx<T: Clone> { |
@@ -213,7 +213,7 @@ impl<T: Clone> Ctx<T> { | |||
213 | 213 | ||
214 | #[test] | 214 | #[test] |
215 | fn doctest_apply_demorgan() { | 215 | fn doctest_apply_demorgan() { |
216 | check( | 216 | check_doc_test( |
217 | "apply_demorgan", | 217 | "apply_demorgan", |
218 | r#####" | 218 | r#####" |
219 | fn main() { | 219 | fn main() { |
@@ -230,7 +230,7 @@ fn main() { | |||
230 | 230 | ||
231 | #[test] | 231 | #[test] |
232 | fn doctest_auto_import() { | 232 | fn doctest_auto_import() { |
233 | check( | 233 | check_doc_test( |
234 | "auto_import", | 234 | "auto_import", |
235 | r#####" | 235 | r#####" |
236 | fn main() { | 236 | fn main() { |
@@ -251,7 +251,7 @@ pub mod std { pub mod collections { pub struct HashMap { } } } | |||
251 | 251 | ||
252 | #[test] | 252 | #[test] |
253 | fn doctest_change_visibility() { | 253 | fn doctest_change_visibility() { |
254 | check( | 254 | check_doc_test( |
255 | "change_visibility", | 255 | "change_visibility", |
256 | r#####" | 256 | r#####" |
257 | <|>fn frobnicate() {} | 257 | <|>fn frobnicate() {} |
@@ -264,7 +264,7 @@ pub(crate) fn frobnicate() {} | |||
264 | 264 | ||
265 | #[test] | 265 | #[test] |
266 | fn doctest_convert_to_guarded_return() { | 266 | fn doctest_convert_to_guarded_return() { |
267 | check( | 267 | check_doc_test( |
268 | "convert_to_guarded_return", | 268 | "convert_to_guarded_return", |
269 | r#####" | 269 | r#####" |
270 | fn main() { | 270 | fn main() { |
@@ -288,7 +288,7 @@ fn main() { | |||
288 | 288 | ||
289 | #[test] | 289 | #[test] |
290 | fn doctest_fill_match_arms() { | 290 | fn doctest_fill_match_arms() { |
291 | check( | 291 | check_doc_test( |
292 | "fill_match_arms", | 292 | "fill_match_arms", |
293 | r#####" | 293 | r#####" |
294 | enum Action { Move { distance: u32 }, Stop } | 294 | enum Action { Move { distance: u32 }, Stop } |
@@ -314,7 +314,7 @@ fn handle(action: Action) { | |||
314 | 314 | ||
315 | #[test] | 315 | #[test] |
316 | fn doctest_flip_binexpr() { | 316 | fn doctest_flip_binexpr() { |
317 | check( | 317 | check_doc_test( |
318 | "flip_binexpr", | 318 | "flip_binexpr", |
319 | r#####" | 319 | r#####" |
320 | fn main() { | 320 | fn main() { |
@@ -331,7 +331,7 @@ fn main() { | |||
331 | 331 | ||
332 | #[test] | 332 | #[test] |
333 | fn doctest_flip_comma() { | 333 | fn doctest_flip_comma() { |
334 | check( | 334 | check_doc_test( |
335 | "flip_comma", | 335 | "flip_comma", |
336 | r#####" | 336 | r#####" |
337 | fn main() { | 337 | fn main() { |
@@ -348,7 +348,7 @@ fn main() { | |||
348 | 348 | ||
349 | #[test] | 349 | #[test] |
350 | fn doctest_flip_trait_bound() { | 350 | fn doctest_flip_trait_bound() { |
351 | check( | 351 | check_doc_test( |
352 | "flip_trait_bound", | 352 | "flip_trait_bound", |
353 | r#####" | 353 | r#####" |
354 | fn foo<T: Clone +<|> Copy>() { } | 354 | fn foo<T: Clone +<|> Copy>() { } |
@@ -361,7 +361,7 @@ fn foo<T: Copy + Clone>() { } | |||
361 | 361 | ||
362 | #[test] | 362 | #[test] |
363 | fn doctest_inline_local_variable() { | 363 | fn doctest_inline_local_variable() { |
364 | check( | 364 | check_doc_test( |
365 | "inline_local_variable", | 365 | "inline_local_variable", |
366 | r#####" | 366 | r#####" |
367 | fn main() { | 367 | fn main() { |
@@ -379,7 +379,7 @@ fn main() { | |||
379 | 379 | ||
380 | #[test] | 380 | #[test] |
381 | fn doctest_introduce_variable() { | 381 | fn doctest_introduce_variable() { |
382 | check( | 382 | check_doc_test( |
383 | "introduce_variable", | 383 | "introduce_variable", |
384 | r#####" | 384 | r#####" |
385 | fn main() { | 385 | fn main() { |
@@ -397,7 +397,7 @@ fn main() { | |||
397 | 397 | ||
398 | #[test] | 398 | #[test] |
399 | fn doctest_invert_if() { | 399 | fn doctest_invert_if() { |
400 | check( | 400 | check_doc_test( |
401 | "invert_if", | 401 | "invert_if", |
402 | r#####" | 402 | r#####" |
403 | fn main() { | 403 | fn main() { |
@@ -414,7 +414,7 @@ fn main() { | |||
414 | 414 | ||
415 | #[test] | 415 | #[test] |
416 | fn doctest_make_raw_string() { | 416 | fn doctest_make_raw_string() { |
417 | check( | 417 | check_doc_test( |
418 | "make_raw_string", | 418 | "make_raw_string", |
419 | r#####" | 419 | r#####" |
420 | fn main() { | 420 | fn main() { |
@@ -431,7 +431,7 @@ fn main() { | |||
431 | 431 | ||
432 | #[test] | 432 | #[test] |
433 | fn doctest_make_usual_string() { | 433 | fn doctest_make_usual_string() { |
434 | check( | 434 | check_doc_test( |
435 | "make_usual_string", | 435 | "make_usual_string", |
436 | r#####" | 436 | r#####" |
437 | fn main() { | 437 | fn main() { |
@@ -448,7 +448,7 @@ fn main() { | |||
448 | 448 | ||
449 | #[test] | 449 | #[test] |
450 | fn doctest_merge_imports() { | 450 | fn doctest_merge_imports() { |
451 | check( | 451 | check_doc_test( |
452 | "merge_imports", | 452 | "merge_imports", |
453 | r#####" | 453 | r#####" |
454 | use std::<|>fmt::Formatter; | 454 | use std::<|>fmt::Formatter; |
@@ -462,7 +462,7 @@ use std::{fmt::Formatter, io}; | |||
462 | 462 | ||
463 | #[test] | 463 | #[test] |
464 | fn doctest_merge_match_arms() { | 464 | fn doctest_merge_match_arms() { |
465 | check( | 465 | check_doc_test( |
466 | "merge_match_arms", | 466 | "merge_match_arms", |
467 | r#####" | 467 | r#####" |
468 | enum Action { Move { distance: u32 }, Stop } | 468 | enum Action { Move { distance: u32 }, Stop } |
@@ -488,7 +488,7 @@ fn handle(action: Action) { | |||
488 | 488 | ||
489 | #[test] | 489 | #[test] |
490 | fn doctest_move_arm_cond_to_match_guard() { | 490 | fn doctest_move_arm_cond_to_match_guard() { |
491 | check( | 491 | check_doc_test( |
492 | "move_arm_cond_to_match_guard", | 492 | "move_arm_cond_to_match_guard", |
493 | r#####" | 493 | r#####" |
494 | enum Action { Move { distance: u32 }, Stop } | 494 | enum Action { Move { distance: u32 }, Stop } |
@@ -515,7 +515,7 @@ fn handle(action: Action) { | |||
515 | 515 | ||
516 | #[test] | 516 | #[test] |
517 | fn doctest_move_bounds_to_where_clause() { | 517 | fn doctest_move_bounds_to_where_clause() { |
518 | check( | 518 | check_doc_test( |
519 | "move_bounds_to_where_clause", | 519 | "move_bounds_to_where_clause", |
520 | r#####" | 520 | r#####" |
521 | fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U { | 521 | fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U { |
@@ -532,7 +532,7 @@ fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U { | |||
532 | 532 | ||
533 | #[test] | 533 | #[test] |
534 | fn doctest_move_guard_to_arm_body() { | 534 | fn doctest_move_guard_to_arm_body() { |
535 | check( | 535 | check_doc_test( |
536 | "move_guard_to_arm_body", | 536 | "move_guard_to_arm_body", |
537 | r#####" | 537 | r#####" |
538 | enum Action { Move { distance: u32 }, Stop } | 538 | enum Action { Move { distance: u32 }, Stop } |
@@ -559,7 +559,7 @@ fn handle(action: Action) { | |||
559 | 559 | ||
560 | #[test] | 560 | #[test] |
561 | fn doctest_remove_dbg() { | 561 | fn doctest_remove_dbg() { |
562 | check( | 562 | check_doc_test( |
563 | "remove_dbg", | 563 | "remove_dbg", |
564 | r#####" | 564 | r#####" |
565 | fn main() { | 565 | fn main() { |
@@ -576,7 +576,7 @@ fn main() { | |||
576 | 576 | ||
577 | #[test] | 577 | #[test] |
578 | fn doctest_remove_hash() { | 578 | fn doctest_remove_hash() { |
579 | check( | 579 | check_doc_test( |
580 | "remove_hash", | 580 | "remove_hash", |
581 | r#####" | 581 | r#####" |
582 | fn main() { | 582 | fn main() { |
@@ -593,7 +593,7 @@ fn main() { | |||
593 | 593 | ||
594 | #[test] | 594 | #[test] |
595 | fn doctest_remove_mut() { | 595 | fn doctest_remove_mut() { |
596 | check( | 596 | check_doc_test( |
597 | "remove_mut", | 597 | "remove_mut", |
598 | r#####" | 598 | r#####" |
599 | impl Walrus { | 599 | impl Walrus { |
@@ -610,7 +610,7 @@ impl Walrus { | |||
610 | 610 | ||
611 | #[test] | 611 | #[test] |
612 | fn doctest_reorder_fields() { | 612 | fn doctest_reorder_fields() { |
613 | check( | 613 | check_doc_test( |
614 | "reorder_fields", | 614 | "reorder_fields", |
615 | r#####" | 615 | r#####" |
616 | struct Foo {foo: i32, bar: i32}; | 616 | struct Foo {foo: i32, bar: i32}; |
@@ -625,7 +625,7 @@ const test: Foo = Foo {foo: 1, bar: 0} | |||
625 | 625 | ||
626 | #[test] | 626 | #[test] |
627 | fn doctest_replace_if_let_with_match() { | 627 | fn doctest_replace_if_let_with_match() { |
628 | check( | 628 | check_doc_test( |
629 | "replace_if_let_with_match", | 629 | "replace_if_let_with_match", |
630 | r#####" | 630 | r#####" |
631 | enum Action { Move { distance: u32 }, Stop } | 631 | enum Action { Move { distance: u32 }, Stop } |
@@ -653,7 +653,7 @@ fn handle(action: Action) { | |||
653 | 653 | ||
654 | #[test] | 654 | #[test] |
655 | fn doctest_replace_let_with_if_let() { | 655 | fn doctest_replace_let_with_if_let() { |
656 | check( | 656 | check_doc_test( |
657 | "replace_let_with_if_let", | 657 | "replace_let_with_if_let", |
658 | r#####" | 658 | r#####" |
659 | enum Option<T> { Some(T), None } | 659 | enum Option<T> { Some(T), None } |
@@ -679,7 +679,7 @@ fn compute() -> Option<i32> { None } | |||
679 | 679 | ||
680 | #[test] | 680 | #[test] |
681 | fn doctest_replace_qualified_name_with_use() { | 681 | fn doctest_replace_qualified_name_with_use() { |
682 | check( | 682 | check_doc_test( |
683 | "replace_qualified_name_with_use", | 683 | "replace_qualified_name_with_use", |
684 | r#####" | 684 | r#####" |
685 | fn process(map: std::collections::<|>HashMap<String, String>) {} | 685 | fn process(map: std::collections::<|>HashMap<String, String>) {} |
@@ -694,7 +694,7 @@ fn process(map: HashMap<String, String>) {} | |||
694 | 694 | ||
695 | #[test] | 695 | #[test] |
696 | fn doctest_replace_unwrap_with_match() { | 696 | fn doctest_replace_unwrap_with_match() { |
697 | check( | 697 | check_doc_test( |
698 | "replace_unwrap_with_match", | 698 | "replace_unwrap_with_match", |
699 | r#####" | 699 | r#####" |
700 | enum Result<T, E> { Ok(T), Err(E) } | 700 | enum Result<T, E> { Ok(T), Err(E) } |
@@ -718,7 +718,7 @@ fn main() { | |||
718 | 718 | ||
719 | #[test] | 719 | #[test] |
720 | fn doctest_split_import() { | 720 | fn doctest_split_import() { |
721 | check( | 721 | check_doc_test( |
722 | "split_import", | 722 | "split_import", |
723 | r#####" | 723 | r#####" |
724 | use std::<|>collections::HashMap; | 724 | use std::<|>collections::HashMap; |
@@ -731,7 +731,7 @@ use std::{collections::HashMap}; | |||
731 | 731 | ||
732 | #[test] | 732 | #[test] |
733 | fn doctest_unwrap_block() { | 733 | fn doctest_unwrap_block() { |
734 | check( | 734 | check_doc_test( |
735 | "unwrap_block", | 735 | "unwrap_block", |
736 | r#####" | 736 | r#####" |
737 | fn foo() { | 737 | fn foo() { |
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 0e4dcb95a..b4907f4b2 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs | |||
@@ -27,7 +27,7 @@ const AST_NODES: &str = "crates/ra_syntax/src/ast/generated/nodes.rs"; | |||
27 | const AST_TOKENS: &str = "crates/ra_syntax/src/ast/generated/tokens.rs"; | 27 | const AST_TOKENS: &str = "crates/ra_syntax/src/ast/generated/tokens.rs"; |
28 | 28 | ||
29 | const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers"; | 29 | const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers"; |
30 | const ASSISTS_TESTS: &str = "crates/ra_assists/src/doc_tests/generated.rs"; | 30 | const ASSISTS_TESTS: &str = "crates/ra_assists/src/tests/generated.rs"; |
31 | const ASSISTS_DOCS: &str = "docs/user/assists.md"; | 31 | const ASSISTS_DOCS: &str = "docs/user/assists.md"; |
32 | 32 | ||
33 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 33 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 31d606535..4bd6b5f0c 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs | |||
@@ -101,14 +101,14 @@ fn collect_assists() -> Result<Vec<Assist>> { | |||
101 | } | 101 | } |
102 | 102 | ||
103 | fn generate_tests(assists: &[Assist], mode: Mode) -> Result<()> { | 103 | fn generate_tests(assists: &[Assist], mode: Mode) -> Result<()> { |
104 | let mut buf = String::from("use super::check;\n"); | 104 | let mut buf = String::from("use super::check_doc_test;\n"); |
105 | 105 | ||
106 | for assist in assists.iter() { | 106 | for assist in assists.iter() { |
107 | let test = format!( | 107 | let test = format!( |
108 | r######" | 108 | r######" |
109 | #[test] | 109 | #[test] |
110 | fn doctest_{}() {{ | 110 | fn doctest_{}() {{ |
111 | check( | 111 | check_doc_test( |
112 | "{}", | 112 | "{}", |
113 | r#####" | 113 | r#####" |
114 | {}"#####, r#####" | 114 | {}"#####, r#####" |
diff --git a/xtask/tests/tidy-tests/main.rs b/xtask/tests/tidy-tests/main.rs index 3213c4dfa..a3c2e37d1 100644 --- a/xtask/tests/tidy-tests/main.rs +++ b/xtask/tests/tidy-tests/main.rs | |||
@@ -24,7 +24,7 @@ fn check_todo(path: &Path, text: &str) { | |||
24 | // This file itself is whitelisted since this test itself contains matches. | 24 | // This file itself is whitelisted since this test itself contains matches. |
25 | "tests/cli.rs", | 25 | "tests/cli.rs", |
26 | // Some of our assists generate `todo!()` so those files are whitelisted. | 26 | // Some of our assists generate `todo!()` so those files are whitelisted. |
27 | "doc_tests/generated.rs", | 27 | "tests/generated.rs", |
28 | "handlers/add_missing_impl_members.rs", | 28 | "handlers/add_missing_impl_members.rs", |
29 | "handlers/add_function.rs", | 29 | "handlers/add_function.rs", |
30 | // To support generating `todo!()` in assists, we have `expr_todo()` in ast::make. | 30 | // To support generating `todo!()` in assists, we have `expr_todo()` in ast::make. |