]> git.lizzy.rs Git - rust.git/commitdiff
move completion item tests closer to the code
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 23 Jan 2019 13:05:13 +0000 (16:05 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 23 Jan 2019 13:05:13 +0000 (16:05 +0300)
this is the reason why we need marks: the tests were spread across two
files, because I've forgotten that there were tests already

crates/ra_hir/src/lib.rs
crates/ra_hir/src/marks.rs
crates/ra_ide_api/src/completion/complete_path.rs
crates/ra_ide_api/src/completion/complete_scope.rs
crates/ra_ide_api/src/completion/completion_item.rs
crates/ra_ide_api/src/lib.rs
crates/ra_ide_api/src/marks.rs [new file with mode: 0644]

index 33a9ba60594fb646961a3fa9c75b709c27a18b85..a861ee88e6d272ee2babf7b1656dcc0915eeba27 100644 (file)
@@ -8,8 +8,6 @@
 pub mod db;
 #[cfg(test)]
 mod mock;
-#[cfg(test)]
-mod marks;
 mod query_definitions;
 mod path;
 pub mod source_binder;
@@ -29,6 +27,9 @@
 mod code_model_api;
 mod code_model_impl;
 
+#[cfg(test)]
+mod marks;
+
 use crate::{
     db::HirDatabase,
     name::{AsName, KnownName},
index 6aff2c4e1e08508050dce7e3c3c988023a80cb3f..f4d0c3e59667c3d6a0df2be6d93c6af4601bfab3 100644 (file)
@@ -1 +1,3 @@
-test_utils::mark!(name_res_works_for_broken_modules);
+use test_utils::mark;
+
+mark!(name_res_works_for_broken_modules);
index 804954ee16ce8e2fcfca2df835a5ebfd94ca8f4b..6bed299d2f4012ab26b010e5610e4b5eff8934ac 100644 (file)
@@ -121,30 +121,4 @@ fn foo() { let _ = E::<|> }
             ",
         );
     }
-
-    #[test]
-    fn dont_render_function_parens_in_use_item() {
-        check_reference_completion(
-            "dont_render_function_parens_in_use_item",
-            "
-            //- /lib.rs
-            mod m { pub fn foo() {} }
-            use crate::m::f<|>;
-            ",
-        )
-    }
-
-    #[test]
-    fn dont_render_function_parens_if_already_call() {
-        check_reference_completion(
-            "dont_render_function_parens_if_already_call",
-            "
-            //- /lib.rs
-            fn frobnicate() {}
-            fn main() {
-                frob<|>();
-            }
-            ",
-        )
-    }
 }
index 20fc77f06e2897cb248514246f6b8737dd07f2c0..f837bb1db2bcaff0f0ce60c356c482419cc5650c 100644 (file)
@@ -175,21 +175,4 @@ fn completes_self_in_methods() {
         check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }")
     }
 
-    #[test]
-    fn inserts_parens_for_function_calls() {
-        check_reference_completion(
-            "inserts_parens_for_function_calls1",
-            r"
-            fn no_args() {}
-            fn main() { no_<|> }
-            ",
-        );
-        check_reference_completion(
-            "inserts_parens_for_function_calls2",
-            r"
-            fn with_args(x: i32, y: String) {}
-            fn main() { with_<|> }
-            ",
-        );
-    }
 }
index 680fd8d1b5d3d45bcdafbd0e10950dc34ad63bcf..48be812a08552c6d3549ba0c37bd7a28aa659f9f 100644 (file)
@@ -3,9 +3,10 @@
 use crate::completion::completion_context::CompletionContext;
 use ra_syntax::{
     ast::{self, AstNode},
-    TextRange
+    TextRange,
 };
 use ra_text_edit::TextEdit;
+use test_utils::tested_by;
 
 /// `CompletionItem` describes a single completion variant in the editor pop-up.
 /// It is basically a POD with various properties. To construct a
@@ -255,6 +256,7 @@ pub(super) fn from_function(
     ) -> Builder {
         // If not an import, add parenthesis automatically.
         if ctx.use_item_syntax.is_none() && !ctx.is_call {
+            tested_by!(inserts_parens_for_function_calls);
             if function.signature(ctx.db).params().is_empty() {
                 self.insert_text = Some(format!("{}()$0", self.label));
             } else {
@@ -344,3 +346,60 @@ pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind
         .collect();
     assert_debug_snapshot_matches!(test_name, kind_completions);
 }
+
+#[cfg(test)]
+mod tests {
+    use test_utils::covers;
+
+    use super::*;
+
+    fn check_reference_completion(code: &str, expected_completions: &str) {
+        check_completion(code, expected_completions, CompletionKind::Reference);
+    }
+
+    #[test]
+    fn inserts_parens_for_function_calls() {
+        covers!(inserts_parens_for_function_calls);
+        check_reference_completion(
+            "inserts_parens_for_function_calls1",
+            r"
+            fn no_args() {}
+            fn main() { no_<|> }
+            ",
+        );
+        check_reference_completion(
+            "inserts_parens_for_function_calls2",
+            r"
+            fn with_args(x: i32, y: String) {}
+            fn main() { with_<|> }
+            ",
+        );
+    }
+
+    #[test]
+    fn dont_render_function_parens_in_use_item() {
+        check_reference_completion(
+            "dont_render_function_parens_in_use_item",
+            "
+            //- /lib.rs
+            mod m { pub fn foo() {} }
+            use crate::m::f<|>;
+            ",
+        )
+    }
+
+    #[test]
+    fn dont_render_function_parens_if_already_call() {
+        check_reference_completion(
+            "dont_render_function_parens_if_already_call",
+            "
+            //- /lib.rs
+            fn frobnicate() {}
+            fn main() {
+                frob<|>();
+            }
+            ",
+        )
+    }
+
+}
index 3c53e75ac43240797608cfbe42079bc7ebe8ea92..3502bfd2e56407d0fd30299a8132091154110355 100644 (file)
@@ -26,6 +26,9 @@
 mod parent_module;
 mod rename;
 
+#[cfg(test)]
+mod marks;
+
 use std::{fmt, sync::Arc};
 
 use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
diff --git a/crates/ra_ide_api/src/marks.rs b/crates/ra_ide_api/src/marks.rs
new file mode 100644 (file)
index 0000000..b4a726e
--- /dev/null
@@ -0,0 +1,3 @@
+use test_utils::mark;
+
+mark!(inserts_parens_for_function_calls);