]> git.lizzy.rs Git - rust.git/blobdiff - crates/rust-analyzer/tests/heavy_tests/main.rs
Remove RelativePathBuf from fixture
[rust.git] / crates / rust-analyzer / tests / heavy_tests / main.rs
index c80745945cba0c6167274f8a6b2faf25fc2b9364..48ce831af7a039c8a879edc254b5c60e283b81d5 100644 (file)
@@ -4,9 +4,7 @@
 
 use lsp_types::{
     notification::DidOpenTextDocument,
-    request::{
-        CodeActionRequest, Completion, Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest,
-    },
+    request::{CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest},
     CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
     DocumentFormattingParams, FormattingOptions, GotoDefinitionParams, HoverParams,
     PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams,
@@ -31,12 +29,12 @@ fn completes_items_from_standard_library() {
     let project_start = Instant::now();
     let server = Project::with_fixture(
         r#"
-//- Cargo.toml
+//- /Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
 
-//- src/lib.rs
+//- /src/lib.rs
 use std::collections::Spam;
 "#,
     )
@@ -58,55 +56,6 @@ fn completes_items_from_standard_library() {
     eprintln!("completion took {:?}", completion_start.elapsed());
 }
 
-#[test]
-fn test_runnables_no_project() {
-    if skip_slow_tests() {
-        return;
-    }
-
-    let server = project(
-        r"
-//- lib.rs
-#[test]
-fn foo() {
-}
-",
-    );
-    server.wait_until_workspace_is_loaded();
-    server.request::<Runnables>(
-        RunnablesParams { text_document: server.doc_id("lib.rs"), position: None },
-        json!([
-            {
-              "args": {
-                "cargoArgs": ["test"],
-                "executableArgs": ["foo", "--nocapture"],
-              },
-              "kind": "cargo",
-              "label": "test foo",
-              "location": {
-                "targetRange": {
-                  "end": { "character": 1, "line": 2 },
-                  "start": { "character": 0, "line": 0 }
-                },
-                "targetSelectionRange": {
-                  "end": { "character": 6, "line": 1 },
-                  "start": { "character": 3, "line": 1 }
-                },
-                "targetUri": "file:///[..]/lib.rs"
-              }
-            },
-            {
-              "args": {
-                "cargoArgs": ["check", "--workspace"],
-                "executableArgs": [],
-              },
-              "kind": "cargo",
-              "label": "cargo check --workspace"
-            }
-        ]),
-    );
-}
-
 #[test]
 fn test_runnables_project() {
     if skip_slow_tests() {
@@ -114,24 +63,24 @@ fn test_runnables_project() {
     }
 
     let code = r#"
-//- foo/Cargo.toml
+//- /foo/Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
 
-//- foo/src/lib.rs
+//- /foo/src/lib.rs
 pub fn foo() {}
 
-//- foo/tests/spam.rs
+//- /foo/tests/spam.rs
 #[test]
 fn test_eggs() {}
 
-//- bar/Cargo.toml
+//- /bar/Cargo.toml
 [package]
 name = "bar"
 version = "0.0.0"
 
-//- bar/src/main.rs
+//- /bar/src/main.rs
 fn main() {}
 "#;
 
@@ -191,12 +140,12 @@ fn test_format_document() {
 
     let server = project(
         r#"
-//- Cargo.toml
+//- /Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
 
-//- src/lib.rs
+//- /src/lib.rs
 mod bar;
 
 fn main() {
@@ -251,13 +200,13 @@ fn test_format_document_2018() {
 
     let server = project(
         r#"
-//- Cargo.toml
+//- /Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
 edition = "2018"
 
-//- src/lib.rs
+//- /src/lib.rs
 mod bar;
 
 async fn test() {
@@ -317,12 +266,12 @@ fn test_missing_module_code_action() {
 
     let server = project(
         r#"
-//- Cargo.toml
+//- /Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
 
-//- src/lib.rs
+//- /src/lib.rs
 mod bar;
 
 fn main() {}
@@ -347,6 +296,7 @@ fn main() {}
                 }
               ]
             },
+            "kind": "quickfix",
             "title": "Create module"
         }]),
     );
@@ -380,17 +330,15 @@ fn test_missing_module_code_action_in_json_project() {
             "deps": [],
             "edition": "2015",
             "cfg": [ "cfg_atom_1", "feature=cfg_1"],
-            "atom_cfgs": ["atom_2"],
-            "key_value_cfgs": { "feature": "key_value_feature", "other": "value"}
         } ]
     });
 
     let code = format!(
         r#"
-//- rust-project.json
+//- /rust-project.json
 {PROJECT}
 
-//- src/lib.rs
+//- /src/lib.rs
 mod bar;
 
 fn main() {{}}
@@ -419,6 +367,7 @@ fn main() {{}}
                 }
               ]
             },
+            "kind": "quickfix",
             "title": "Create module"
         }]),
     );
@@ -442,15 +391,15 @@ fn diagnostics_dont_block_typing() {
     }
 
     let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect();
-    let libs: String = (0..10).map(|i| format!("//- src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
+    let libs: String = (0..10).map(|i| format!("//- /src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
     let server = Project::with_fixture(&format!(
         r#"
-//- Cargo.toml
+//- /Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
 
-//- src/lib.rs
+//- /src/lib.rs
 {}
 
 {}
@@ -500,12 +449,12 @@ fn preserves_dos_line_endings() {
 
     let server = Project::with_fixture(
         &"
-//- Cargo.toml
+//- /Cargo.toml
 [package]
 name = \"foo\"
 version = \"0.0.0\"
 
-//- src/main.rs
+//- /src/main.rs
 /// Some Docs\r\nfn main() {}
 ",
     )
@@ -535,12 +484,12 @@ fn out_dirs_check() {
 
     let server = Project::with_fixture(
         r###"
-//- Cargo.toml
+//- /Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
 
-//- build.rs
+//- /build.rs
 use std::{env, fs, path::Path};
 
 fn main() {
@@ -555,7 +504,11 @@ fn main() {
     println!("cargo:rustc-cfg=featlike=\"set\"");
     println!("cargo:rerun-if-changed=build.rs");
 }
-//- src/main.rs
+//- /src/main.rs
+#[rustc_builtin_macro] macro_rules! include {}
+#[rustc_builtin_macro] macro_rules! concat {}
+#[rustc_builtin_macro] macro_rules! env {}
+
 include!(concat!(env!("OUT_DIR"), "/hello.rs"));
 
 #[cfg(atom_cfg)]
@@ -570,10 +523,8 @@ fn main() {
 fn main() {
     let va = A;
     let vb = B;
-    message();
+    let should_be_str = message();
 }
-
-fn main() { message(); }
 "###,
     )
     .with_config(|config| {
@@ -581,54 +532,35 @@ fn main() {
     })
     .server();
     server.wait_until_workspace_is_loaded();
-    let res = server.send_request::<GotoDefinition>(GotoDefinitionParams {
+    let res = server.send_request::<HoverRequest>(HoverParams {
         text_document_position_params: TextDocumentPositionParams::new(
             server.doc_id("src/main.rs"),
-            Position::new(14, 8),
+            Position::new(18, 10),
         ),
         work_done_progress_params: Default::default(),
-        partial_result_params: Default::default(),
     });
-    assert!(format!("{}", res).contains("hello.rs"));
+    assert!(res.to_string().contains("&str"));
     server.request::<GotoTypeDefinition>(
         GotoDefinitionParams {
             text_document_position_params: TextDocumentPositionParams::new(
                 server.doc_id("src/main.rs"),
-                Position::new(12, 9),
+                Position::new(16, 9),
             ),
             work_done_progress_params: Default::default(),
             partial_result_params: Default::default(),
         },
         json!([{
             "originSelectionRange": {
-                "end": {
-                    "character": 10,
-                    "line": 12
-                },
-                "start": {
-                    "character": 8,
-                    "line": 12
-                }
+                "end": { "character": 10, "line": 16 },
+                "start": { "character": 8, "line": 16 }
             },
             "targetRange": {
-                "end": {
-                    "character": 9,
-                    "line": 3
-                },
-                "start": {
-                    "character": 0,
-                    "line": 2
-                }
+                "end": { "character": 9, "line": 7 },
+                "start": { "character": 0, "line": 6 }
             },
             "targetSelectionRange": {
-                "end": {
-                    "character": 8,
-                    "line": 3
-                },
-                "start": {
-                    "character": 7,
-                    "line": 3
-                }
+                "end": { "character": 8, "line": 7 },
+                "start": { "character": 7, "line": 7 }
             },
             "targetUri": "file:///[..]src/main.rs"
         }]),
@@ -637,41 +569,23 @@ fn main() {
         GotoDefinitionParams {
             text_document_position_params: TextDocumentPositionParams::new(
                 server.doc_id("src/main.rs"),
-                Position::new(13, 9),
+                Position::new(17, 9),
             ),
             work_done_progress_params: Default::default(),
             partial_result_params: Default::default(),
         },
         json!([{
             "originSelectionRange": {
-                "end": {
-                    "character": 10,
-                    "line": 13
-                },
-                "start": {
-                    "character": 8,
-                    "line":13
-                }
+                "end": { "character": 10, "line": 17 },
+                "start": { "character": 8, "line": 17 }
             },
             "targetRange": {
-                "end": {
-                    "character": 9,
-                    "line": 7
-                },
-                "start": {
-                    "character": 0,
-                    "line":6
-                }
+                "end": { "character": 9, "line": 11 },
+                "start": { "character": 0, "line":10 }
             },
             "targetSelectionRange": {
-                "end": {
-                    "character": 8,
-                    "line": 7
-                },
-                "start": {
-                    "character": 7,
-                    "line": 7
-                }
+                "end": { "character": 8, "line": 11 },
+                "start": { "character": 7, "line": 11 }
             },
             "targetUri": "file:///[..]src/main.rs"
         }]),
@@ -685,7 +599,7 @@ fn resolve_proc_macro() {
     }
     let server = Project::with_fixture(
         r###"
-//- foo/Cargo.toml
+//- /foo/Cargo.toml
 [package]
 name = "foo"
 version = "0.0.0"
@@ -693,7 +607,7 @@ fn resolve_proc_macro() {
 [dependencies]
 bar = {path = "../bar"}
 
-//- foo/src/main.rs
+//- /foo/src/main.rs
 use bar::Bar;
 trait Bar {
   fn bar();
@@ -704,7 +618,7 @@ fn main() {
   Foo::bar();
 }
 
-//- bar/Cargo.toml
+//- /bar/Cargo.toml
 [package]
 name = "bar"
 version = "0.0.0"
@@ -713,7 +627,7 @@ fn main() {
 [lib]
 proc-macro = true
 
-//- bar/src/lib.rs
+//- /bar/src/lib.rs
 extern crate proc_macro;
 use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
 macro_rules! t {