mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
switch to insta for testing
This commit is contained in:
parent
8caff4e034
commit
d79a9b17dc
20 changed files with 495 additions and 195 deletions
|
@ -1,7 +1,6 @@
|
|||
mod runnables;
|
||||
|
||||
use ra_syntax::TextRange;
|
||||
use test_utils::{assert_eq_dbg, assert_eq_text};
|
||||
use test_utils::assert_eq_text;
|
||||
use insta::assert_debug_snapshot_matches;
|
||||
|
||||
use ra_ide_api::{
|
||||
mock_analysis::{single_file, single_file_with_position, MockAnalysis},
|
||||
|
@ -12,18 +11,7 @@ use ra_ide_api::{
|
|||
fn test_unresolved_module_diagnostic() {
|
||||
let (analysis, file_id) = single_file("mod foo;");
|
||||
let diagnostics = analysis.diagnostics(file_id).unwrap();
|
||||
assert_eq_dbg(
|
||||
r#"[Diagnostic {
|
||||
message: "unresolved module",
|
||||
range: [4; 7),
|
||||
fix: Some(SourceChange {
|
||||
label: "create module",
|
||||
source_file_edits: [],
|
||||
file_system_edits: [CreateFile { source_root: SourceRootId(0), path: "foo.rs" }],
|
||||
cursor_position: None }),
|
||||
severity: Error }]"#,
|
||||
&diagnostics,
|
||||
);
|
||||
assert_debug_snapshot_matches!("unresolved_module_diagnostic", &diagnostics);
|
||||
}
|
||||
|
||||
// FIXME: move this test to hir
|
||||
|
@ -31,7 +19,7 @@ fn test_unresolved_module_diagnostic() {
|
|||
fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() {
|
||||
let (analysis, file_id) = single_file("mod foo {}");
|
||||
let diagnostics = analysis.diagnostics(file_id).unwrap();
|
||||
assert_eq_dbg(r#"[]"#, &diagnostics);
|
||||
assert!(diagnostics.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
use test_utils::assert_eq_dbg;
|
||||
|
||||
use ra_ide_api::mock_analysis::analysis_and_position;
|
||||
|
||||
#[test]
|
||||
fn test_runnables() {
|
||||
let (analysis, pos) = analysis_and_position(
|
||||
r#"
|
||||
//- /lib.rs
|
||||
<|> //empty
|
||||
fn main() {}
|
||||
|
||||
#[test]
|
||||
fn test_foo() {}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_foo() {}
|
||||
"#,
|
||||
);
|
||||
let runnables = analysis.runnables(pos.file_id).unwrap();
|
||||
assert_eq_dbg(
|
||||
r#"[Runnable { range: [1; 21), kind: Bin },
|
||||
Runnable { range: [22; 46), kind: Test { name: "test_foo" } },
|
||||
Runnable { range: [47; 81), kind: Test { name: "test_foo" } }]"#,
|
||||
&runnables,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_runnables_module() {
|
||||
let (analysis, pos) = analysis_and_position(
|
||||
r#"
|
||||
//- /lib.rs
|
||||
<|> //empty
|
||||
mod test_mod {
|
||||
#[test]
|
||||
fn test_foo1() {}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
let runnables = analysis.runnables(pos.file_id).unwrap();
|
||||
assert_eq_dbg(
|
||||
r#"[Runnable { range: [1; 59), kind: TestMod { path: "test_mod" } },
|
||||
Runnable { range: [28; 57), kind: Test { name: "test_foo1" } }]"#,
|
||||
&runnables,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_runnables_one_depth_layer_module() {
|
||||
let (analysis, pos) = analysis_and_position(
|
||||
r#"
|
||||
//- /lib.rs
|
||||
<|> //empty
|
||||
mod foo {
|
||||
mod test_mod {
|
||||
#[test]
|
||||
fn test_foo1() {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
let runnables = analysis.runnables(pos.file_id).unwrap();
|
||||
assert_eq_dbg(
|
||||
r#"[Runnable { range: [23; 85), kind: TestMod { path: "foo::test_mod" } },
|
||||
Runnable { range: [46; 79), kind: Test { name: "test_foo1" } }]"#,
|
||||
&runnables,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_runnables_multiple_depth_module() {
|
||||
let (analysis, pos) = analysis_and_position(
|
||||
r#"
|
||||
//- /lib.rs
|
||||
<|> //empty
|
||||
mod foo {
|
||||
mod bar {
|
||||
mod test_mod {
|
||||
#[test]
|
||||
fn test_foo1() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
let runnables = analysis.runnables(pos.file_id).unwrap();
|
||||
assert_eq_dbg(
|
||||
r#"[Runnable { range: [41; 115), kind: TestMod { path: "foo::bar::test_mod" } },
|
||||
Runnable { range: [68; 105), kind: Test { name: "test_foo1" } }]"#,
|
||||
&runnables,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_runnables_no_test_function_in_module() {
|
||||
let (analysis, pos) = analysis_and_position(
|
||||
r#"
|
||||
//- /lib.rs
|
||||
<|> //empty
|
||||
mod test_mod {
|
||||
fn foo1() {}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
let runnables = analysis.runnables(pos.file_id).unwrap();
|
||||
assert_eq_dbg(r#"[]"#, &runnables)
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
Created: 2019-01-15T11:15:20.891129945+00:00
|
||||
Creator: insta@0.1.4
|
||||
Source: crates/ra_ide_api/tests/test/main.rs
|
||||
|
||||
[
|
||||
Diagnostic {
|
||||
message: "unresolved module",
|
||||
range: [4; 7),
|
||||
fix: Some(
|
||||
SourceChange {
|
||||
label: "create module",
|
||||
source_file_edits: [],
|
||||
file_system_edits: [
|
||||
CreateFile {
|
||||
source_root: SourceRootId(
|
||||
0
|
||||
),
|
||||
path: "foo.rs"
|
||||
}
|
||||
],
|
||||
cursor_position: None
|
||||
}
|
||||
),
|
||||
severity: Error
|
||||
}
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue