aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/tests/test
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/tests/test')
-rw-r--r--crates/ra_ide_api/tests/test/main.rs20
-rw-r--r--crates/ra_ide_api/tests/test/runnables.rs109
-rw-r--r--crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap26
3 files changed, 30 insertions, 125 deletions
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs
index 7dc1dba73..2b863aedf 100644
--- a/crates/ra_ide_api/tests/test/main.rs
+++ b/crates/ra_ide_api/tests/test/main.rs
@@ -1,7 +1,6 @@
1mod runnables;
2
3use ra_syntax::TextRange; 1use ra_syntax::TextRange;
4use test_utils::{assert_eq_dbg, assert_eq_text}; 2use test_utils::assert_eq_text;
3use insta::assert_debug_snapshot_matches;
5 4
6use ra_ide_api::{ 5use ra_ide_api::{
7 mock_analysis::{single_file, single_file_with_position, MockAnalysis}, 6 mock_analysis::{single_file, single_file_with_position, MockAnalysis},
@@ -12,18 +11,7 @@ use ra_ide_api::{
12fn test_unresolved_module_diagnostic() { 11fn test_unresolved_module_diagnostic() {
13 let (analysis, file_id) = single_file("mod foo;"); 12 let (analysis, file_id) = single_file("mod foo;");
14 let diagnostics = analysis.diagnostics(file_id).unwrap(); 13 let diagnostics = analysis.diagnostics(file_id).unwrap();
15 assert_eq_dbg( 14 assert_debug_snapshot_matches!("unresolved_module_diagnostic", &diagnostics);
16 r#"[Diagnostic {
17 message: "unresolved module",
18 range: [4; 7),
19 fix: Some(SourceChange {
20 label: "create module",
21 source_file_edits: [],
22 file_system_edits: [CreateFile { source_root: SourceRootId(0), path: "foo.rs" }],
23 cursor_position: None }),
24 severity: Error }]"#,
25 &diagnostics,
26 );
27} 15}
28 16
29// FIXME: move this test to hir 17// FIXME: move this test to hir
@@ -31,7 +19,7 @@ fn test_unresolved_module_diagnostic() {
31fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() { 19fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() {
32 let (analysis, file_id) = single_file("mod foo {}"); 20 let (analysis, file_id) = single_file("mod foo {}");
33 let diagnostics = analysis.diagnostics(file_id).unwrap(); 21 let diagnostics = analysis.diagnostics(file_id).unwrap();
34 assert_eq_dbg(r#"[]"#, &diagnostics); 22 assert!(diagnostics.is_empty());
35} 23}
36 24
37#[test] 25#[test]
diff --git a/crates/ra_ide_api/tests/test/runnables.rs b/crates/ra_ide_api/tests/test/runnables.rs
deleted file mode 100644
index da8d5e0d5..000000000
--- a/crates/ra_ide_api/tests/test/runnables.rs
+++ /dev/null
@@ -1,109 +0,0 @@
1use test_utils::assert_eq_dbg;
2
3use ra_ide_api::mock_analysis::analysis_and_position;
4
5#[test]
6fn test_runnables() {
7 let (analysis, pos) = analysis_and_position(
8 r#"
9 //- /lib.rs
10 <|> //empty
11 fn main() {}
12
13 #[test]
14 fn test_foo() {}
15
16 #[test]
17 #[ignore]
18 fn test_foo() {}
19 "#,
20 );
21 let runnables = analysis.runnables(pos.file_id).unwrap();
22 assert_eq_dbg(
23 r#"[Runnable { range: [1; 21), kind: Bin },
24 Runnable { range: [22; 46), kind: Test { name: "test_foo" } },
25 Runnable { range: [47; 81), kind: Test { name: "test_foo" } }]"#,
26 &runnables,
27 )
28}
29
30#[test]
31fn test_runnables_module() {
32 let (analysis, pos) = analysis_and_position(
33 r#"
34 //- /lib.rs
35 <|> //empty
36 mod test_mod {
37 #[test]
38 fn test_foo1() {}
39 }
40 "#,
41 );
42 let runnables = analysis.runnables(pos.file_id).unwrap();
43 assert_eq_dbg(
44 r#"[Runnable { range: [1; 59), kind: TestMod { path: "test_mod" } },
45 Runnable { range: [28; 57), kind: Test { name: "test_foo1" } }]"#,
46 &runnables,
47 )
48}
49
50#[test]
51fn test_runnables_one_depth_layer_module() {
52 let (analysis, pos) = analysis_and_position(
53 r#"
54 //- /lib.rs
55 <|> //empty
56 mod foo {
57 mod test_mod {
58 #[test]
59 fn test_foo1() {}
60 }
61 }
62 "#,
63 );
64 let runnables = analysis.runnables(pos.file_id).unwrap();
65 assert_eq_dbg(
66 r#"[Runnable { range: [23; 85), kind: TestMod { path: "foo::test_mod" } },
67 Runnable { range: [46; 79), kind: Test { name: "test_foo1" } }]"#,
68 &runnables,
69 )
70}
71
72#[test]
73fn test_runnables_multiple_depth_module() {
74 let (analysis, pos) = analysis_and_position(
75 r#"
76 //- /lib.rs
77 <|> //empty
78 mod foo {
79 mod bar {
80 mod test_mod {
81 #[test]
82 fn test_foo1() {}
83 }
84 }
85 }
86 "#,
87 );
88 let runnables = analysis.runnables(pos.file_id).unwrap();
89 assert_eq_dbg(
90 r#"[Runnable { range: [41; 115), kind: TestMod { path: "foo::bar::test_mod" } },
91 Runnable { range: [68; 105), kind: Test { name: "test_foo1" } }]"#,
92 &runnables,
93 )
94}
95
96#[test]
97fn test_runnables_no_test_function_in_module() {
98 let (analysis, pos) = analysis_and_position(
99 r#"
100 //- /lib.rs
101 <|> //empty
102 mod test_mod {
103 fn foo1() {}
104 }
105 "#,
106 );
107 let runnables = analysis.runnables(pos.file_id).unwrap();
108 assert_eq_dbg(r#"[]"#, &runnables)
109}
diff --git a/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap b/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap
new file mode 100644
index 000000000..1b41e2b00
--- /dev/null
+++ b/crates/ra_ide_api/tests/test/snapshots/test__unresolved_module_diagnostic.snap
@@ -0,0 +1,26 @@
1Created: 2019-01-15T11:15:20.891129945+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/tests/test/main.rs
4
5[
6 Diagnostic {
7 message: "unresolved module",
8 range: [4; 7),
9 fix: Some(
10 SourceChange {
11 label: "create module",
12 source_file_edits: [],
13 file_system_edits: [
14 CreateFile {
15 source_root: SourceRootId(
16 0
17 ),
18 path: "foo.rs"
19 }
20 ],
21 cursor_position: None
22 }
23 ),
24 severity: Error
25 }
26]