diff options
author | Aleksey Kladov <[email protected]> | 2019-01-14 13:27:08 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-15 11:18:24 +0000 |
commit | d79a9b17dc4fb132443aa4ec1ca0ab278d2a217c (patch) | |
tree | 525b697381048b2f6d615a9c66c92485db8511ec /crates/ra_ide_api_light | |
parent | 8caff4e03475c20392f13e8c6ad469bd01a4b4ce (diff) |
switch to insta for testing
Diffstat (limited to 'crates/ra_ide_api_light')
-rw-r--r-- | crates/ra_ide_api_light/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/lib.rs | 13 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap | 80 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap | 30 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/structure.rs | 16 |
5 files changed, 116 insertions, 24 deletions
diff --git a/crates/ra_ide_api_light/Cargo.toml b/crates/ra_ide_api_light/Cargo.toml index 8c192fca6..16cf228e7 100644 --- a/crates/ra_ide_api_light/Cargo.toml +++ b/crates/ra_ide_api_light/Cargo.toml | |||
@@ -17,3 +17,4 @@ ra_text_edit = { path = "../ra_text_edit" } | |||
17 | [dev-dependencies] | 17 | [dev-dependencies] |
18 | test_utils = { path = "../test_utils" } | 18 | test_utils = { path = "../test_utils" } |
19 | proptest = "0.8.7" | 19 | proptest = "0.8.7" |
20 | insta = "0.1.4" | ||
diff --git a/crates/ra_ide_api_light/src/lib.rs b/crates/ra_ide_api_light/src/lib.rs index 72fba9402..9dd72701d 100644 --- a/crates/ra_ide_api_light/src/lib.rs +++ b/crates/ra_ide_api_light/src/lib.rs | |||
@@ -132,8 +132,9 @@ pub fn syntax_tree(file: &SourceFile) -> String { | |||
132 | #[cfg(test)] | 132 | #[cfg(test)] |
133 | mod tests { | 133 | mod tests { |
134 | use ra_syntax::AstNode; | 134 | use ra_syntax::AstNode; |
135 | use insta::assert_debug_snapshot_matches; | ||
135 | 136 | ||
136 | use crate::test_utils::{add_cursor, assert_eq_dbg, assert_eq_text, extract_offset}; | 137 | use crate::test_utils::{add_cursor, assert_eq_text, extract_offset}; |
137 | 138 | ||
138 | use super::*; | 139 | use super::*; |
139 | 140 | ||
@@ -147,15 +148,7 @@ fn main() {} | |||
147 | "#, | 148 | "#, |
148 | ); | 149 | ); |
149 | let hls = highlight(file.syntax()); | 150 | let hls = highlight(file.syntax()); |
150 | assert_eq_dbg( | 151 | assert_debug_snapshot_matches!("highlighting", hls); |
151 | r#"[HighlightedRange { range: [1; 11), tag: "comment" }, | ||
152 | HighlightedRange { range: [12; 14), tag: "keyword" }, | ||
153 | HighlightedRange { range: [15; 19), tag: "function" }, | ||
154 | HighlightedRange { range: [29; 37), tag: "macro" }, | ||
155 | HighlightedRange { range: [38; 50), tag: "string" }, | ||
156 | HighlightedRange { range: [52; 54), tag: "literal" }]"#, | ||
157 | &hls, | ||
158 | ); | ||
159 | } | 152 | } |
160 | 153 | ||
161 | #[test] | 154 | #[test] |
diff --git a/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap new file mode 100644 index 000000000..10eb5c724 --- /dev/null +++ b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap | |||
@@ -0,0 +1,80 @@ | |||
1 | Created: 2019-01-15T11:15:21.073862814+00:00 | ||
2 | Creator: [email protected] | ||
3 | Source: crates/ra_ide_api_light/src/structure.rs | ||
4 | |||
5 | [ | ||
6 | StructureNode { | ||
7 | parent: None, | ||
8 | label: "Foo", | ||
9 | navigation_range: [8; 11), | ||
10 | node_range: [1; 26), | ||
11 | kind: STRUCT_DEF | ||
12 | }, | ||
13 | StructureNode { | ||
14 | parent: Some( | ||
15 | 0 | ||
16 | ), | ||
17 | label: "x", | ||
18 | navigation_range: [18; 19), | ||
19 | node_range: [18; 24), | ||
20 | kind: NAMED_FIELD_DEF | ||
21 | }, | ||
22 | StructureNode { | ||
23 | parent: None, | ||
24 | label: "m", | ||
25 | navigation_range: [32; 33), | ||
26 | node_range: [28; 53), | ||
27 | kind: MODULE | ||
28 | }, | ||
29 | StructureNode { | ||
30 | parent: Some( | ||
31 | 2 | ||
32 | ), | ||
33 | label: "bar", | ||
34 | navigation_range: [43; 46), | ||
35 | node_range: [40; 51), | ||
36 | kind: FN_DEF | ||
37 | }, | ||
38 | StructureNode { | ||
39 | parent: None, | ||
40 | label: "E", | ||
41 | navigation_range: [60; 61), | ||
42 | node_range: [55; 75), | ||
43 | kind: ENUM_DEF | ||
44 | }, | ||
45 | StructureNode { | ||
46 | parent: None, | ||
47 | label: "T", | ||
48 | navigation_range: [81; 82), | ||
49 | node_range: [76; 88), | ||
50 | kind: TYPE_DEF | ||
51 | }, | ||
52 | StructureNode { | ||
53 | parent: None, | ||
54 | label: "S", | ||
55 | navigation_range: [96; 97), | ||
56 | node_range: [89; 108), | ||
57 | kind: STATIC_DEF | ||
58 | }, | ||
59 | StructureNode { | ||
60 | parent: None, | ||
61 | label: "C", | ||
62 | navigation_range: [115; 116), | ||
63 | node_range: [109; 127), | ||
64 | kind: CONST_DEF | ||
65 | }, | ||
66 | StructureNode { | ||
67 | parent: None, | ||
68 | label: "impl E", | ||
69 | navigation_range: [134; 135), | ||
70 | node_range: [129; 138), | ||
71 | kind: IMPL_BLOCK | ||
72 | }, | ||
73 | StructureNode { | ||
74 | parent: None, | ||
75 | label: "impl fmt::Debug for E", | ||
76 | navigation_range: [160; 161), | ||
77 | node_range: [140; 164), | ||
78 | kind: IMPL_BLOCK | ||
79 | } | ||
80 | ] | ||
diff --git a/crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap b/crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap new file mode 100644 index 000000000..d8f44a713 --- /dev/null +++ b/crates/ra_ide_api_light/src/snapshots/tests__highlighting.snap | |||
@@ -0,0 +1,30 @@ | |||
1 | Created: 2019-01-15T11:15:21.073858657+00:00 | ||
2 | Creator: [email protected] | ||
3 | Source: crates/ra_ide_api_light/src/lib.rs | ||
4 | |||
5 | [ | ||
6 | HighlightedRange { | ||
7 | range: [1; 11), | ||
8 | tag: "comment" | ||
9 | }, | ||
10 | HighlightedRange { | ||
11 | range: [12; 14), | ||
12 | tag: "keyword" | ||
13 | }, | ||
14 | HighlightedRange { | ||
15 | range: [15; 19), | ||
16 | tag: "function" | ||
17 | }, | ||
18 | HighlightedRange { | ||
19 | range: [29; 37), | ||
20 | tag: "macro" | ||
21 | }, | ||
22 | HighlightedRange { | ||
23 | range: [38; 50), | ||
24 | tag: "string" | ||
25 | }, | ||
26 | HighlightedRange { | ||
27 | range: [52; 54), | ||
28 | tag: "literal" | ||
29 | } | ||
30 | ] | ||
diff --git a/crates/ra_ide_api_light/src/structure.rs b/crates/ra_ide_api_light/src/structure.rs index 8bd57555f..3c6f39e16 100644 --- a/crates/ra_ide_api_light/src/structure.rs +++ b/crates/ra_ide_api_light/src/structure.rs | |||
@@ -87,7 +87,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
87 | #[cfg(test)] | 87 | #[cfg(test)] |
88 | mod tests { | 88 | mod tests { |
89 | use super::*; | 89 | use super::*; |
90 | use test_utils::assert_eq_dbg; | 90 | use insta::assert_debug_snapshot_matches; |
91 | 91 | ||
92 | #[test] | 92 | #[test] |
93 | fn test_file_structure() { | 93 | fn test_file_structure() { |
@@ -112,18 +112,6 @@ impl fmt::Debug for E {} | |||
112 | "#, | 112 | "#, |
113 | ); | 113 | ); |
114 | let structure = file_structure(&file); | 114 | let structure = file_structure(&file); |
115 | assert_eq_dbg( | 115 | assert_debug_snapshot_matches!("file_structure", structure); |
116 | r#"[StructureNode { parent: None, label: "Foo", navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF }, | ||
117 | StructureNode { parent: Some(0), label: "x", navigation_range: [18; 19), node_range: [18; 24), kind: NAMED_FIELD_DEF }, | ||
118 | StructureNode { parent: None, label: "m", navigation_range: [32; 33), node_range: [28; 53), kind: MODULE }, | ||
119 | StructureNode { parent: Some(2), label: "bar", navigation_range: [43; 46), node_range: [40; 51), kind: FN_DEF }, | ||
120 | StructureNode { parent: None, label: "E", navigation_range: [60; 61), node_range: [55; 75), kind: ENUM_DEF }, | ||
121 | StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF }, | ||
122 | StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF }, | ||
123 | StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF }, | ||
124 | StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_BLOCK }, | ||
125 | StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_BLOCK }]"#, | ||
126 | &structure, | ||
127 | ) | ||
128 | } | 116 | } |
129 | } | 117 | } |