Skip to content

Commit 9f3d627

Browse files
committed
add tests for full signatures
1 parent 6b487ed commit 9f3d627

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

crates/ide-completion/src/tests/special.rs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
33
use expect_test::{expect, Expect};
44

5-
use crate::tests::{
6-
check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character,
5+
use crate::{
6+
tests::{
7+
check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character,
8+
},
9+
CompletionItemKind,
710
};
811

12+
use super::{do_completion_with_config, TEST_CONFIG};
13+
914
fn check_no_kw(ra_fixture: &str, expect: Expect) {
1015
let actual = completion_list_no_kw(ra_fixture);
1116
expect.assert_eq(&actual)
@@ -1303,3 +1308,67 @@ struct Foo<T: PartialOrd
13031308
"#,
13041309
);
13051310
}
1311+
1312+
fn check_signatures(src: &str, kind: CompletionItemKind, reduced: Expect, full: Expect) {
1313+
const FULL_SIGNATURES_CONFIG: crate::CompletionConfig = {
1314+
let mut x = TEST_CONFIG;
1315+
x.full_function_signatures = true;
1316+
x
1317+
};
1318+
1319+
// reduced signature
1320+
let completion = do_completion_with_config(TEST_CONFIG, src, kind);
1321+
assert!(completion[0].detail.is_some());
1322+
reduced.assert_eq(completion[0].detail.as_ref().unwrap());
1323+
1324+
// full signature
1325+
let completion = do_completion_with_config(FULL_SIGNATURES_CONFIG, src, kind);
1326+
assert!(completion[0].detail.is_some());
1327+
full.assert_eq(completion[0].detail.as_ref().unwrap());
1328+
}
1329+
1330+
#[test]
1331+
fn respects_full_function_signatures() {
1332+
check_signatures(
1333+
r#"
1334+
pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone, { 0u8 }
1335+
fn main() { fo$0 }
1336+
"#,
1337+
CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function),
1338+
expect!("fn(&mut T) -> u8"),
1339+
expect!("pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone,"),
1340+
);
1341+
1342+
check_signatures(
1343+
r#"
1344+
struct Foo;
1345+
struct Bar;
1346+
impl Bar {
1347+
pub const fn baz(x: Foo) -> ! { loop {} };
1348+
}
1349+
1350+
fn main() { Bar::b$0 }
1351+
"#,
1352+
CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function),
1353+
expect!("const fn(Foo) -> !"),
1354+
expect!("pub const fn baz(x: Foo) -> !"),
1355+
);
1356+
1357+
check_signatures(
1358+
r#"
1359+
struct Foo;
1360+
struct Bar;
1361+
impl Bar {
1362+
pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> ! { loop {} };
1363+
}
1364+
1365+
fn main() {
1366+
let mut bar = Bar;
1367+
bar.b$0
1368+
}
1369+
"#,
1370+
CompletionItemKind::Method,
1371+
expect!("const fn(&'foo mut self, &Foo) -> !"),
1372+
expect!("pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> !"),
1373+
);
1374+
}

0 commit comments

Comments
 (0)