aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/Cargo.toml3
-rw-r--r--crates/ra_ide_api/src/extend_selection.rs5
-rw-r--r--crates/ra_ide_api/src/runnables.rs97
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap26
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap70
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__runnables.snap22
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__runnables_module.snap18
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap18
-rw-r--r--crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap18
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs32
-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
13 files changed, 309 insertions, 155 deletions
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml
index d42a664b6..f7013c3c1 100644
--- a/crates/ra_ide_api/Cargo.toml
+++ b/crates/ra_ide_api/Cargo.toml
@@ -21,3 +21,6 @@ ra_text_edit = { path = "../ra_text_edit" }
21ra_db = { path = "../ra_db" } 21ra_db = { path = "../ra_db" }
22hir = { path = "../ra_hir", package = "ra_hir" } 22hir = { path = "../ra_hir", package = "ra_hir" }
23test_utils = { path = "../test_utils" } 23test_utils = { path = "../test_utils" }
24
25[dev-dependencies]
26insta = "0.1.4"
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs
index c3c809c9f..9f0ab2f1c 100644
--- a/crates/ra_ide_api/src/extend_selection.rs
+++ b/crates/ra_ide_api/src/extend_selection.rs
@@ -38,8 +38,9 @@ fn find_macro_call(node: &SyntaxNode, range: TextRange) -> Option<&ast::MacroCal
38 38
39#[cfg(test)] 39#[cfg(test)]
40mod tests { 40mod tests {
41 use ra_syntax::TextRange;
42
41 use crate::mock_analysis::single_file_with_range; 43 use crate::mock_analysis::single_file_with_range;
42 use test_utils::assert_eq_dbg;
43 44
44 #[test] 45 #[test]
45 fn extend_selection_inside_macros() { 46 fn extend_selection_inside_macros() {
@@ -51,6 +52,6 @@ mod tests {
51 ", 52 ",
52 ); 53 );
53 let r = analysis.extend_selection(frange); 54 let r = analysis.extend_selection(frange);
54 assert_eq_dbg("[51; 56)", &r); 55 assert_eq!(r, TextRange::from_to(51.into(), 56.into()));
55 } 56 }
56} 57}
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index 53e49da5b..f1de28094 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -92,3 +92,100 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt
92 kind: RunnableKind::TestMod { path }, 92 kind: RunnableKind::TestMod { path },
93 }) 93 })
94} 94}
95
96#[cfg(test)]
97mod tests {
98 use insta::assert_debug_snapshot_matches;
99
100 use crate::mock_analysis::analysis_and_position;
101
102 #[test]
103 fn test_runnables() {
104 let (analysis, pos) = analysis_and_position(
105 r#"
106 //- /lib.rs
107 <|> //empty
108 fn main() {}
109
110 #[test]
111 fn test_foo() {}
112
113 #[test]
114 #[ignore]
115 fn test_foo() {}
116 "#,
117 );
118 let runnables = analysis.runnables(pos.file_id).unwrap();
119 assert_debug_snapshot_matches!("runnables", &runnables)
120 }
121
122 #[test]
123 fn test_runnables_module() {
124 let (analysis, pos) = analysis_and_position(
125 r#"
126 //- /lib.rs
127 <|> //empty
128 mod test_mod {
129 #[test]
130 fn test_foo1() {}
131 }
132 "#,
133 );
134 let runnables = analysis.runnables(pos.file_id).unwrap();
135 assert_debug_snapshot_matches!("runnables_module", &runnables)
136 }
137
138 #[test]
139 fn test_runnables_one_depth_layer_module() {
140 let (analysis, pos) = analysis_and_position(
141 r#"
142 //- /lib.rs
143 <|> //empty
144 mod foo {
145 mod test_mod {
146 #[test]
147 fn test_foo1() {}
148 }
149 }
150 "#,
151 );
152 let runnables = analysis.runnables(pos.file_id).unwrap();
153 assert_debug_snapshot_matches!("runnables_one_depth_layer_module", &runnables)
154 }
155
156 #[test]
157 fn test_runnables_multiple_depth_module() {
158 let (analysis, pos) = analysis_and_position(
159 r#"
160 //- /lib.rs
161 <|> //empty
162 mod foo {
163 mod bar {
164 mod test_mod {
165 #[test]
166 fn test_foo1() {}
167 }
168 }
169 }
170 "#,
171 );
172 let runnables = analysis.runnables(pos.file_id).unwrap();
173 assert_debug_snapshot_matches!("runnables_multiple_depth_module", &runnables)
174 }
175
176 #[test]
177 fn test_runnables_no_test_function_in_module() {
178 let (analysis, pos) = analysis_and_position(
179 r#"
180 //- /lib.rs
181 <|> //empty
182 mod test_mod {
183 fn foo1() {}
184 }
185 "#,
186 );
187 let runnables = analysis.runnables(pos.file_id).unwrap();
188 assert!(runnables.is_empty())
189 }
190
191}
diff --git a/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap b/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap
new file mode 100644
index 000000000..b84aa9c78
--- /dev/null
+++ b/crates/ra_ide_api/src/snapshots/tests__highlight_query_group_macro.snap
@@ -0,0 +1,26 @@
1Created: 2019-01-15T11:15:20.732493641+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/syntax_highlighting.rs
4
5[
6 HighlightedRange {
7 range: [20; 32),
8 tag: "macro"
9 },
10 HighlightedRange {
11 range: [13; 18),
12 tag: "text"
13 },
14 HighlightedRange {
15 range: [51; 54),
16 tag: "keyword"
17 },
18 HighlightedRange {
19 range: [55; 60),
20 tag: "keyword"
21 },
22 HighlightedRange {
23 range: [61; 72),
24 tag: "function"
25 }
26]
diff --git a/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap b/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap
new file mode 100644
index 000000000..14c6e5a4e
--- /dev/null
+++ b/crates/ra_ide_api/src/snapshots/tests__highlights_code_inside_macros.snap
@@ -0,0 +1,70 @@
1Created: 2019-01-15T11:15:20.732523231+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/syntax_highlighting.rs
4
5[
6 HighlightedRange {
7 range: [13; 15),
8 tag: "keyword"
9 },
10 HighlightedRange {
11 range: [16; 20),
12 tag: "function"
13 },
14 HighlightedRange {
15 range: [41; 46),
16 tag: "macro"
17 },
18 HighlightedRange {
19 range: [49; 52),
20 tag: "keyword"
21 },
22 HighlightedRange {
23 range: [57; 59),
24 tag: "literal"
25 },
26 HighlightedRange {
27 range: [82; 86),
28 tag: "macro"
29 },
30 HighlightedRange {
31 range: [89; 92),
32 tag: "keyword"
33 },
34 HighlightedRange {
35 range: [97; 99),
36 tag: "literal"
37 },
38 HighlightedRange {
39 range: [49; 52),
40 tag: "keyword"
41 },
42 HighlightedRange {
43 range: [53; 54),
44 tag: "function"
45 },
46 HighlightedRange {
47 range: [57; 59),
48 tag: "literal"
49 },
50 HighlightedRange {
51 range: [61; 62),
52 tag: "text"
53 },
54 HighlightedRange {
55 range: [89; 92),
56 tag: "keyword"
57 },
58 HighlightedRange {
59 range: [93; 94),
60 tag: "function"
61 },
62 HighlightedRange {
63 range: [97; 99),
64 tag: "literal"
65 },
66 HighlightedRange {
67 range: [101; 102),
68 tag: "text"
69 }
70]
diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables.snap b/crates/ra_ide_api/src/snapshots/tests__runnables.snap
new file mode 100644
index 000000000..ba6cba0ab
--- /dev/null
+++ b/crates/ra_ide_api/src/snapshots/tests__runnables.snap
@@ -0,0 +1,22 @@
1Created: 2019-01-15T11:15:20.732460119+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/runnables.rs
4
5[
6 Runnable {
7 range: [1; 21),
8 kind: Bin
9 },
10 Runnable {
11 range: [22; 46),
12 kind: Test {
13 name: "test_foo"
14 }
15 },
16 Runnable {
17 range: [47; 81),
18 kind: Test {
19 name: "test_foo"
20 }
21 }
22]
diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables_module.snap b/crates/ra_ide_api/src/snapshots/tests__runnables_module.snap
new file mode 100644
index 000000000..b3f2d4d6e
--- /dev/null
+++ b/crates/ra_ide_api/src/snapshots/tests__runnables_module.snap
@@ -0,0 +1,18 @@
1Created: 2019-01-15T11:15:20.732460109+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/runnables.rs
4
5[
6 Runnable {
7 range: [1; 59),
8 kind: TestMod {
9 path: "test_mod"
10 }
11 },
12 Runnable {
13 range: [28; 57),
14 kind: Test {
15 name: "test_foo1"
16 }
17 }
18]
diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap b/crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap
new file mode 100644
index 000000000..6eba482e7
--- /dev/null
+++ b/crates/ra_ide_api/src/snapshots/tests__runnables_multiple_depth_module.snap
@@ -0,0 +1,18 @@
1Created: 2019-01-15T11:15:20.732522773+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/runnables.rs
4
5[
6 Runnable {
7 range: [41; 115),
8 kind: TestMod {
9 path: "foo::bar::test_mod"
10 }
11 },
12 Runnable {
13 range: [68; 105),
14 kind: Test {
15 name: "test_foo1"
16 }
17 }
18]
diff --git a/crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap b/crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap
new file mode 100644
index 000000000..f40c762f3
--- /dev/null
+++ b/crates/ra_ide_api/src/snapshots/tests__runnables_one_depth_layer_module.snap
@@ -0,0 +1,18 @@
1Created: 2019-01-15T11:15:20.732480089+00:00
2Creator: [email protected]
3Source: crates/ra_ide_api/src/runnables.rs
4
5[
6 Runnable {
7 range: [23; 85),
8 kind: TestMod {
9 path: "foo::test_mod"
10 }
11 },
12 Runnable {
13 range: [46; 79),
14 kind: Test {
15 name: "test_foo1"
16 }
17 }
18]
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index cb19e9515..480b78dce 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -34,7 +34,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Cancelable<Vec<Hi
34#[cfg(test)] 34#[cfg(test)]
35mod tests { 35mod tests {
36 use crate::mock_analysis::single_file; 36 use crate::mock_analysis::single_file;
37 use test_utils::assert_eq_dbg; 37
38 use insta::assert_debug_snapshot_matches;
38 39
39 #[test] 40 #[test]
40 fn highlights_code_inside_macros() { 41 fn highlights_code_inside_macros() {
@@ -47,25 +48,7 @@ mod tests {
47 ", 48 ",
48 ); 49 );
49 let highlights = analysis.highlight(file_id).unwrap(); 50 let highlights = analysis.highlight(file_id).unwrap();
50 assert_eq_dbg( 51 assert_debug_snapshot_matches!("highlights_code_inside_macros", &highlights);
51 r#"[HighlightedRange { range: [13; 15), tag: "keyword" },
52 HighlightedRange { range: [16; 20), tag: "function" },
53 HighlightedRange { range: [41; 46), tag: "macro" },
54 HighlightedRange { range: [49; 52), tag: "keyword" },
55 HighlightedRange { range: [57; 59), tag: "literal" },
56 HighlightedRange { range: [82; 86), tag: "macro" },
57 HighlightedRange { range: [89; 92), tag: "keyword" },
58 HighlightedRange { range: [97; 99), tag: "literal" },
59 HighlightedRange { range: [49; 52), tag: "keyword" },
60 HighlightedRange { range: [53; 54), tag: "function" },
61 HighlightedRange { range: [57; 59), tag: "literal" },
62 HighlightedRange { range: [61; 62), tag: "text" },
63 HighlightedRange { range: [89; 92), tag: "keyword" },
64 HighlightedRange { range: [93; 94), tag: "function" },
65 HighlightedRange { range: [97; 99), tag: "literal" },
66 HighlightedRange { range: [101; 102), tag: "text" }]"#,
67 &highlights,
68 )
69 } 52 }
70 53
71 // FIXME: this test is not really necessary: artifact of the inital hacky 54 // FIXME: this test is not really necessary: artifact of the inital hacky
@@ -80,13 +63,6 @@ mod tests {
80 ", 63 ",
81 ); 64 );
82 let highlights = analysis.highlight(file_id).unwrap(); 65 let highlights = analysis.highlight(file_id).unwrap();
83 assert_eq_dbg( 66 assert_debug_snapshot_matches!("highlight_query_group_macro", &highlights);
84 r#"[HighlightedRange { range: [20; 32), tag: "macro" },
85 HighlightedRange { range: [13; 18), tag: "text" },
86 HighlightedRange { range: [51; 54), tag: "keyword" },
87 HighlightedRange { range: [55; 60), tag: "keyword" },
88 HighlightedRange { range: [61; 72), tag: "function" }]"#,
89 &highlights,
90 )
91 } 67 }
92} 68}
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]