Skip to content

Commit 12b67ef

Browse files
committed
basic test
1 parent 2d66f6d commit 12b67ef

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

crates/ide-completion/src/completions/dot.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,20 @@ mod tests {
155155
use expect_test::{expect, Expect};
156156

157157
use crate::tests::{
158-
check_edit, completion_list_no_kw, completion_list_no_kw_with_private_editable,
158+
check_edit, completion_list_exact_order, completion_list_no_kw,
159+
completion_list_no_kw_with_private_editable,
159160
};
160161

161162
fn check(ra_fixture: &str, expect: Expect) {
162163
let actual = completion_list_no_kw(ra_fixture);
163164
expect.assert_eq(&actual);
164165
}
165166

167+
fn check_exact_order(ra_fixture: &str, expect: Expect) {
168+
let actual = completion_list_exact_order(ra_fixture);
169+
expect.assert_eq(&actual);
170+
}
171+
166172
fn check_with_private_editable(ra_fixture: &str, expect: Expect) {
167173
let actual = completion_list_no_kw_with_private_editable(ra_fixture);
168174
expect.assert_eq(&actual);
@@ -265,6 +271,32 @@ fn foo(a: A) { a.$0() }
265271
);
266272
}
267273

274+
#[test]
275+
fn test_usable_types_first() {
276+
check_exact_order(
277+
r#"
278+
struct A;
279+
impl A {
280+
fn foo(&self) {}
281+
fn new_1(input: u32) -> Self { A }
282+
fn new_2() -> A { A }
283+
}
284+
285+
fn test() {
286+
let a = A::$0;
287+
}
288+
"#,
289+
// preference:
290+
// fn with no param that returns itself
291+
// fn with param that returns itself
292+
expect![[r#"
293+
fn new_2() fn() -> A
294+
fn new_1(…) fn(u32) -> A
295+
me foo(…) fn(&self)
296+
"#]],
297+
);
298+
}
299+
268300
#[test]
269301
fn test_visibility_filtering() {
270302
check(

crates/ide-completion/src/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ pub(crate) fn completion_list_no_kw(ra_fixture: &str) -> String {
8888
completion_list_with_config(TEST_CONFIG, ra_fixture, false, None)
8989
}
9090

91+
pub(crate) fn completion_list_exact_order(ra_fixture: &str) -> String {
92+
let items = get_all_items(TEST_CONFIG, ra_fixture, None);
93+
render_completion_list(items)
94+
}
95+
9196
pub(crate) fn completion_list_no_kw_with_private_editable(ra_fixture: &str) -> String {
9297
let mut config = TEST_CONFIG;
9398
config.enable_private_editable = true;

0 commit comments

Comments
 (0)