Skip to content

Commit ee9cec5

Browse files
bors[bot]matklad
andauthored
Merge #4539
4539: Relax cursor position tests in assists r=matklad a=matklad Those will be replaced with snippets anyway bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 3dfc461 + 65fa586 commit ee9cec5

14 files changed

+96
-117
lines changed

crates/ra_assists/src/handlers/add_explicit_type.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,15 @@ mod tests {
8686

8787
#[test]
8888
fn add_explicit_type_works_for_simple_expr() {
89-
check_assist(
90-
add_explicit_type,
91-
"fn f() { let a<|> = 1; }",
92-
"fn f() { let a<|>: i32 = 1; }",
93-
);
89+
check_assist(add_explicit_type, "fn f() { let a<|> = 1; }", "fn f() { let a: i32 = 1; }");
9490
}
9591

9692
#[test]
9793
fn add_explicit_type_works_for_underscore() {
9894
check_assist(
9995
add_explicit_type,
10096
"fn f() { let a<|>: _ = 1; }",
101-
"fn f() { let a<|>: i32 = 1; }",
97+
"fn f() { let a: i32 = 1; }",
10298
);
10399
}
104100

@@ -122,7 +118,7 @@ mod tests {
122118
}
123119
124120
fn f() {
125-
let a<|>: Option<i32> = Option::Some(1);
121+
let a: Option<i32> = Option::Some(1);
126122
}"#,
127123
);
128124
}
@@ -132,16 +128,16 @@ mod tests {
132128
check_assist(
133129
add_explicit_type,
134130
r"macro_rules! v { () => {0u64} } fn f() { let a<|> = v!(); }",
135-
r"macro_rules! v { () => {0u64} } fn f() { let a<|>: u64 = v!(); }",
131+
r"macro_rules! v { () => {0u64} } fn f() { let a: u64 = v!(); }",
136132
);
137133
}
138134

139135
#[test]
140136
fn add_explicit_type_works_for_macro_call_recursive() {
141137
check_assist(
142138
add_explicit_type,
143-
"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a<|> = v!(); }",
144-
"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a<|>: u64 = v!(); }",
139+
r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a<|> = v!(); }"#,
140+
r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a: u64 = v!(); }"#,
145141
);
146142
}
147143

@@ -208,7 +204,7 @@ struct Test<K, T = u8> {
208204
}
209205
210206
fn main() {
211-
let test<|>: Test<i32> = Test { t: 23, k: 33 };
207+
let test: Test<i32> = Test { t: 23, k: 33 };
212208
}"#,
213209
);
214210
}

crates/ra_assists/src/handlers/add_from_impl_for_enum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ mod tests {
101101
check_assist(
102102
add_from_impl_for_enum,
103103
"enum A { <|>One(u32) }",
104-
r#"enum A { <|>One(u32) }
104+
r#"enum A { One(u32) }
105105
106106
impl From<u32> for A {
107107
fn from(v: u32) -> Self {
@@ -116,7 +116,7 @@ impl From<u32> for A {
116116
check_assist(
117117
add_from_impl_for_enum,
118118
r#"enum A { <|>One(foo::bar::baz::Boo) }"#,
119-
r#"enum A { <|>One(foo::bar::baz::Boo) }
119+
r#"enum A { One(foo::bar::baz::Boo) }
120120
121121
impl From<foo::bar::baz::Boo> for A {
122122
fn from(v: foo::bar::baz::Boo) -> Self {
@@ -178,7 +178,7 @@ impl From<String> for A {
178178
pub trait From<T> {
179179
fn from(T) -> Self;
180180
}"#,
181-
r#"enum A { <|>One(u32), Two(String), }
181+
r#"enum A { One(u32), Two(String), }
182182
183183
impl From<u32> for A {
184184
fn from(v: u32) -> Self {

crates/ra_assists/src/handlers/apply_demorgan.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ mod tests {
6363

6464
#[test]
6565
fn demorgan_turns_and_into_or() {
66-
check_assist(apply_demorgan, "fn f() { !x &&<|> !x }", "fn f() { !(x ||<|> x) }")
66+
check_assist(apply_demorgan, "fn f() { !x &&<|> !x }", "fn f() { !(x || x) }")
6767
}
6868

6969
#[test]
7070
fn demorgan_turns_or_into_and() {
71-
check_assist(apply_demorgan, "fn f() { !x ||<|> !x }", "fn f() { !(x &&<|> x) }")
71+
check_assist(apply_demorgan, "fn f() { !x ||<|> !x }", "fn f() { !(x && x) }")
7272
}
7373

7474
#[test]
7575
fn demorgan_removes_inequality() {
76-
check_assist(apply_demorgan, "fn f() { x != x ||<|> !x }", "fn f() { !(x == x &&<|> x) }")
76+
check_assist(apply_demorgan, "fn f() { x != x ||<|> !x }", "fn f() { !(x == x && x) }")
7777
}
7878

7979
#[test]
8080
fn demorgan_general_case() {
81-
check_assist(apply_demorgan, "fn f() { x ||<|> x }", "fn f() { !(!x &&<|> !x) }")
81+
check_assist(apply_demorgan, "fn f() { x ||<|> x }", "fn f() { !(!x && !x) }")
8282
}
8383

8484
#[test]

crates/ra_assists/src/handlers/auto_import.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ mod tests {
298298
}
299299
",
300300
r"
301-
<|>use PubMod::PubStruct;
301+
use PubMod::PubStruct;
302302
303303
PubStruct
304304
@@ -329,7 +329,7 @@ mod tests {
329329
macro_rules! foo {
330330
($i:ident) => { fn foo(a: $i) {} }
331331
}
332-
foo!(Pub<|>Struct);
332+
foo!(PubStruct);
333333
334334
pub mod PubMod {
335335
pub struct PubStruct;
@@ -360,7 +360,7 @@ mod tests {
360360
use PubMod::{PubStruct2, PubStruct1};
361361
362362
struct Test {
363-
test: Pub<|>Struct2<u8>,
363+
test: PubStruct2<u8>,
364364
}
365365
366366
pub mod PubMod {
@@ -393,7 +393,7 @@ mod tests {
393393
r"
394394
use PubMod3::PubStruct;
395395
396-
PubSt<|>ruct
396+
PubStruct
397397
398398
pub mod PubMod1 {
399399
pub struct PubStruct;
@@ -474,7 +474,7 @@ mod tests {
474474
r"
475475
use PubMod::test_function;
476476
477-
test_function<|>
477+
test_function
478478
479479
pub mod PubMod {
480480
pub fn test_function() {};
@@ -501,7 +501,7 @@ mod tests {
501501
r"use crate_with_macro::foo;
502502
503503
fn main() {
504-
foo<|>
504+
foo
505505
}
506506
",
507507
);
@@ -587,7 +587,7 @@ fn main() {
587587
}
588588
589589
fn main() {
590-
TestStruct::test_function<|>
590+
TestStruct::test_function
591591
}
592592
",
593593
);
@@ -620,7 +620,7 @@ fn main() {
620620
}
621621
622622
fn main() {
623-
TestStruct::TEST_CONST<|>
623+
TestStruct::TEST_CONST
624624
}
625625
",
626626
);
@@ -659,7 +659,7 @@ fn main() {
659659
}
660660
661661
fn main() {
662-
test_mod::TestStruct::test_function<|>
662+
test_mod::TestStruct::test_function
663663
}
664664
",
665665
);
@@ -730,7 +730,7 @@ fn main() {
730730
}
731731
732732
fn main() {
733-
test_mod::TestStruct::TEST_CONST<|>
733+
test_mod::TestStruct::TEST_CONST
734734
}
735735
",
736736
);
@@ -803,7 +803,7 @@ fn main() {
803803
804804
fn main() {
805805
let test_struct = test_mod::TestStruct {};
806-
test_struct.test_meth<|>od()
806+
test_struct.test_method()
807807
}
808808
",
809809
);

crates/ra_assists/src/handlers/change_visibility.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,27 +118,23 @@ mod tests {
118118

119119
#[test]
120120
fn change_visibility_adds_pub_crate_to_items() {
121-
check_assist(change_visibility, "<|>fn foo() {}", "<|>pub(crate) fn foo() {}");
122-
check_assist(change_visibility, "f<|>n foo() {}", "pub(crate) f<|>n foo() {}");
123-
check_assist(change_visibility, "<|>struct Foo {}", "<|>pub(crate) struct Foo {}");
124-
check_assist(change_visibility, "<|>mod foo {}", "<|>pub(crate) mod foo {}");
125-
check_assist(change_visibility, "<|>trait Foo {}", "<|>pub(crate) trait Foo {}");
126-
check_assist(change_visibility, "m<|>od {}", "pub(crate) m<|>od {}");
127-
check_assist(
128-
change_visibility,
129-
"unsafe f<|>n foo() {}",
130-
"pub(crate) unsafe f<|>n foo() {}",
131-
);
121+
check_assist(change_visibility, "<|>fn foo() {}", "pub(crate) fn foo() {}");
122+
check_assist(change_visibility, "f<|>n foo() {}", "pub(crate) fn foo() {}");
123+
check_assist(change_visibility, "<|>struct Foo {}", "pub(crate) struct Foo {}");
124+
check_assist(change_visibility, "<|>mod foo {}", "pub(crate) mod foo {}");
125+
check_assist(change_visibility, "<|>trait Foo {}", "pub(crate) trait Foo {}");
126+
check_assist(change_visibility, "m<|>od {}", "pub(crate) mod {}");
127+
check_assist(change_visibility, "unsafe f<|>n foo() {}", "pub(crate) unsafe fn foo() {}");
132128
}
133129

134130
#[test]
135131
fn change_visibility_works_with_struct_fields() {
136132
check_assist(
137133
change_visibility,
138134
r"struct S { <|>field: u32 }",
139-
r"struct S { <|>pub(crate) field: u32 }",
135+
r"struct S { pub(crate) field: u32 }",
140136
);
141-
check_assist(change_visibility, r"struct S ( <|>u32 )", r"struct S ( <|>pub(crate) u32 )");
137+
check_assist(change_visibility, r"struct S ( <|>u32 )", r"struct S ( pub(crate) u32 )");
142138
}
143139

144140
#[test]
@@ -152,17 +148,17 @@ mod tests {
152148

153149
#[test]
154150
fn change_visibility_pub_to_pub_crate() {
155-
check_assist(change_visibility, "<|>pub fn foo() {}", "<|>pub(crate) fn foo() {}")
151+
check_assist(change_visibility, "<|>pub fn foo() {}", "pub(crate) fn foo() {}")
156152
}
157153

158154
#[test]
159155
fn change_visibility_pub_crate_to_pub() {
160-
check_assist(change_visibility, "<|>pub(crate) fn foo() {}", "<|>pub fn foo() {}")
156+
check_assist(change_visibility, "<|>pub(crate) fn foo() {}", "pub fn foo() {}")
161157
}
162158

163159
#[test]
164160
fn change_visibility_const() {
165-
check_assist(change_visibility, "<|>const FOO = 3u8;", "<|>pub(crate) const FOO = 3u8;");
161+
check_assist(change_visibility, "<|>const FOO = 3u8;", "pub(crate) const FOO = 3u8;");
166162
}
167163

168164
#[test]
@@ -183,7 +179,7 @@ mod tests {
183179
// comments
184180
185181
#[derive(Debug)]
186-
<|>pub(crate) struct Foo;
182+
pub(crate) struct Foo;
187183
",
188184
)
189185
}

crates/ra_assists/src/handlers/flip_binexpr.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,21 @@ mod tests {
8585
check_assist(
8686
flip_binexpr,
8787
"fn f() { let res = 1 ==<|> 2; }",
88-
"fn f() { let res = 2 ==<|> 1; }",
88+
"fn f() { let res = 2 == 1; }",
8989
)
9090
}
9191

9292
#[test]
9393
fn flip_binexpr_works_for_gt() {
94-
check_assist(
95-
flip_binexpr,
96-
"fn f() { let res = 1 ><|> 2; }",
97-
"fn f() { let res = 2 <<|> 1; }",
98-
)
94+
check_assist(flip_binexpr, "fn f() { let res = 1 ><|> 2; }", "fn f() { let res = 2 < 1; }")
9995
}
10096

10197
#[test]
10298
fn flip_binexpr_works_for_lteq() {
10399
check_assist(
104100
flip_binexpr,
105101
"fn f() { let res = 1 <=<|> 2; }",
106-
"fn f() { let res = 2 >=<|> 1; }",
102+
"fn f() { let res = 2 >= 1; }",
107103
)
108104
}
109105

@@ -112,7 +108,7 @@ mod tests {
112108
check_assist(
113109
flip_binexpr,
114110
"fn f() { let res = (1 + 1) ==<|> (2 + 2); }",
115-
"fn f() { let res = (2 + 2) ==<|> (1 + 1); }",
111+
"fn f() { let res = (2 + 2) == (1 + 1); }",
116112
)
117113
}
118114

@@ -132,7 +128,7 @@ mod tests {
132128
fn dyn_eq(&self, other: &dyn Diagnostic) -> bool {
133129
match other.downcast_ref::<Self>() {
134130
None => false,
135-
Some(it) => self ==<|> it,
131+
Some(it) => self == it,
136132
}
137133
}
138134
"#,

crates/ra_assists/src/handlers/flip_comma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ mod tests {
4545
check_assist(
4646
flip_comma,
4747
"fn foo(x: i32,<|> y: Result<(), ()>) {}",
48-
"fn foo(y: Result<(), ()>,<|> x: i32) {}",
48+
"fn foo(y: Result<(), ()>, x: i32) {}",
4949
)
5050
}
5151

crates/ra_assists/src/handlers/flip_trait_bound.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ mod tests {
6060
check_assist(
6161
flip_trait_bound,
6262
"struct S<T> where T: A <|>+ B { }",
63-
"struct S<T> where T: B <|>+ A { }",
63+
"struct S<T> where T: B + A { }",
6464
)
6565
}
6666

@@ -69,21 +69,21 @@ mod tests {
6969
check_assist(
7070
flip_trait_bound,
7171
"impl X for S<T> where T: A +<|> B { }",
72-
"impl X for S<T> where T: B +<|> A { }",
72+
"impl X for S<T> where T: B + A { }",
7373
)
7474
}
7575

7676
#[test]
7777
fn flip_trait_bound_works_for_fn() {
78-
check_assist(flip_trait_bound, "fn f<T: A <|>+ B>(t: T) { }", "fn f<T: B <|>+ A>(t: T) { }")
78+
check_assist(flip_trait_bound, "fn f<T: A <|>+ B>(t: T) { }", "fn f<T: B + A>(t: T) { }")
7979
}
8080

8181
#[test]
8282
fn flip_trait_bound_works_for_fn_where_clause() {
8383
check_assist(
8484
flip_trait_bound,
8585
"fn f<T>(t: T) where T: A +<|> B { }",
86-
"fn f<T>(t: T) where T: B +<|> A { }",
86+
"fn f<T>(t: T) where T: B + A { }",
8787
)
8888
}
8989

@@ -92,7 +92,7 @@ mod tests {
9292
check_assist(
9393
flip_trait_bound,
9494
"fn f<T>(t: T) where T: A <|>+ 'static { }",
95-
"fn f<T>(t: T) where T: 'static <|>+ A { }",
95+
"fn f<T>(t: T) where T: 'static + A { }",
9696
)
9797
}
9898

@@ -101,7 +101,7 @@ mod tests {
101101
check_assist(
102102
flip_trait_bound,
103103
"struct S<T> where T: A<T> <|>+ b_mod::B<T> + C<T> { }",
104-
"struct S<T> where T: b_mod::B<T> <|>+ A<T> + C<T> { }",
104+
"struct S<T> where T: b_mod::B<T> + A<T> + C<T> { }",
105105
)
106106
}
107107

@@ -110,7 +110,7 @@ mod tests {
110110
check_assist(
111111
flip_trait_bound,
112112
"struct S<T> where T: A + B + C + D + E + F +<|> G + H + I + J { }",
113-
"struct S<T> where T: A + B + C + D + E + G +<|> F + H + I + J { }",
113+
"struct S<T> where T: A + B + C + D + E + G + F + H + I + J { }",
114114
)
115115
}
116116
}

0 commit comments

Comments
 (0)