about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvxpm <viniciusximenespm@gmail.com>2023-09-23 19:39:42 -0300
committervxpm <viniciusximenespm@gmail.com>2023-09-23 19:39:42 -0300
commit9f3d627681e069ea313076ce65cbd28a8dfe0974 (patch)
tree6ce36f3a02b415707550233eff99d053cbf52543
parent6b487ed4be81e723e0ed2035f79b27d9efb93b8a (diff)
downloadrust-9f3d627681e069ea313076ce65cbd28a8dfe0974.tar.gz
rust-9f3d627681e069ea313076ce65cbd28a8dfe0974.zip
add tests for full signatures
-rw-r--r--crates/ide-completion/src/tests/special.rs73
1 files changed, 71 insertions, 2 deletions
diff --git a/crates/ide-completion/src/tests/special.rs b/crates/ide-completion/src/tests/special.rs
index e80a289049f..83888e08f1c 100644
--- a/crates/ide-completion/src/tests/special.rs
+++ b/crates/ide-completion/src/tests/special.rs
@@ -2,10 +2,15 @@
 
 use expect_test::{expect, Expect};
 
-use crate::tests::{
-    check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character,
+use crate::{
+    tests::{
+        check_edit, completion_list, completion_list_no_kw, completion_list_with_trigger_character,
+    },
+    CompletionItemKind,
 };
 
+use super::{do_completion_with_config, TEST_CONFIG};
+
 fn check_no_kw(ra_fixture: &str, expect: Expect) {
     let actual = completion_list_no_kw(ra_fixture);
     expect.assert_eq(&actual)
@@ -1303,3 +1308,67 @@ struct Foo<T: PartialOrd
 "#,
     );
 }
+
+fn check_signatures(src: &str, kind: CompletionItemKind, reduced: Expect, full: Expect) {
+    const FULL_SIGNATURES_CONFIG: crate::CompletionConfig = {
+        let mut x = TEST_CONFIG;
+        x.full_function_signatures = true;
+        x
+    };
+
+    // reduced signature
+    let completion = do_completion_with_config(TEST_CONFIG, src, kind);
+    assert!(completion[0].detail.is_some());
+    reduced.assert_eq(completion[0].detail.as_ref().unwrap());
+
+    // full signature
+    let completion = do_completion_with_config(FULL_SIGNATURES_CONFIG, src, kind);
+    assert!(completion[0].detail.is_some());
+    full.assert_eq(completion[0].detail.as_ref().unwrap());
+}
+
+#[test]
+fn respects_full_function_signatures() {
+    check_signatures(
+        r#"
+pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone, { 0u8 }
+fn main() { fo$0 }
+"#,
+        CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function),
+        expect!("fn(&mut T) -> u8"),
+        expect!("pub fn foo<'x, T>(x: &'x mut T) -> u8 where T: Clone,"),
+    );
+
+    check_signatures(
+        r#"
+struct Foo;
+struct Bar;
+impl Bar {
+    pub const fn baz(x: Foo) -> ! { loop {} };
+}
+
+fn main() { Bar::b$0 }
+"#,
+        CompletionItemKind::SymbolKind(ide_db::SymbolKind::Function),
+        expect!("const fn(Foo) -> !"),
+        expect!("pub const fn baz(x: Foo) -> !"),
+    );
+
+    check_signatures(
+        r#"
+struct Foo;
+struct Bar;
+impl Bar {
+    pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> ! { loop {} };
+}
+
+fn main() {
+    let mut bar = Bar;
+    bar.b$0
+}
+"#,
+        CompletionItemKind::Method,
+        expect!("const fn(&'foo mut self, &Foo) -> !"),
+        expect!("pub const fn baz<'foo>(&'foo mut self, x: &'foo Foo) -> !"),
+    );
+}