Repository: rust-analyzer/rust-analyzer
Pull request #409 (2019-01-03 03:02:48)

Add Analysis#teype_of test


Patch:
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs
index ce777a771e..739ca6ae83 100644
--- a/crates/ra_analysis/src/completion.rs
+++ b/crates/ra_analysis/src/completion.rs
@@ -28,21 +28,7 @@ pub use crate::completion::completion_item::{CompletionItem, InsertText, Complet
 /// incomplete and can look really weird.
 ///
 /// Once the context is collected, we run a series of completion routines which
-/// look at the context and produce completion items. One subtelty about this
-/// phase is that completion engine should not filter by the substring which is
-/// already present, it should give all possible variants for the identifier at
-/// the caret. In other words, for
-///
-/// ```no-run
-/// fn f() {
-///     let foo = 92;
-///     let _ = bar<|>
-/// }
-/// ```
-///
-/// `foo` *should* be present among the completion variants. Filtering by
-/// identifier prefix/fuzzy match should be done higher in the stack, together
-/// with ordering of completions (currently this is done by the client).
+/// look at the context and produce completion items.
 pub(crate) fn completions(
     db: &db::RootDatabase,
     position: FilePosition,


Test patch:
diff --git a/crates/ra_analysis/tests/type_of.rs b/crates/ra_analysis/tests/type_of.rs
new file mode 100644
index 0000000000..375f808bb9
--- /dev/null
+++ b/crates/ra_analysis/tests/type_of.rs
@@ -0,0 +1,79 @@
+use ra_analysis::{
+    mock_analysis::{single_file_with_range},
+};
+
+#[test]
+fn test_type_of_for_function() {
+    let (analysis, range) = single_file_with_range(
+        "
+        pub fn foo() -> u32 { 1 };
+
+        fn main() {
+            let foo_test = <|>foo()<|>;
+        }
+        ",
+    );
+
+    let type_name = analysis.type_of(range).unwrap().unwrap();
+    assert_eq!("u32", &type_name);
+}
+
+// FIXME: improve type_of to make this work
+#[test]
+fn test_type_of_for_num() {
+    let (analysis, range) = single_file_with_range(
+        r#"
+        fn main() {
+            let foo_test = <|>"foo"<|>;
+        }
+        "#,
+    );
+
+    assert!(analysis.type_of(range).unwrap().is_none());
+}
+// FIXME: improve type_of to make this work
+#[test]
+fn test_type_of_for_binding() {
+    let (analysis, range) = single_file_with_range(
+        "
+        pub fn foo() -> u32 { 1 };
+
+        fn main() {
+            let <|>foo_test<|> = foo();
+        }
+        ",
+    );
+
+    assert!(analysis.type_of(range).unwrap().is_none());
+}
+
+// FIXME: improve type_of to make this work
+#[test]
+fn test_type_of_for_expr_1() {
+    let (analysis, range) = single_file_with_range(
+        "
+        fn main() {
+            let foo = <|>1 + foo_test<|>;
+        }
+        ",
+    );
+
+    let type_name = analysis.type_of(range).unwrap().unwrap();
+    assert_eq!("[unknown]", &type_name);
+}
+
+// FIXME: improve type_of to make this work
+#[test]
+fn test_type_of_for_expr_2() {
+    let (analysis, range) = single_file_with_range(
+        "
+        fn main() {
+            let foo: usize = 1;
+            let bar = <|>1 + foo_test<|>;
+        }
+        ",
+    );
+
+    let type_name = analysis.type_of(range).unwrap().unwrap();
+    assert_eq!("[unknown]", &type_name);
+}