switch to insta for testing

This commit is contained in:
Aleksey Kladov 2019-01-14 16:27:08 +03:00
parent 8caff4e034
commit d79a9b17dc
20 changed files with 495 additions and 195 deletions

View file

@ -17,3 +17,4 @@ ra_text_edit = { path = "../ra_text_edit" }
[dev-dependencies]
test_utils = { path = "../test_utils" }
proptest = "0.8.7"
insta = "0.1.4"

View file

@ -132,8 +132,9 @@ pub fn syntax_tree(file: &SourceFile) -> String {
#[cfg(test)]
mod tests {
use ra_syntax::AstNode;
use insta::assert_debug_snapshot_matches;
use crate::test_utils::{add_cursor, assert_eq_dbg, assert_eq_text, extract_offset};
use crate::test_utils::{add_cursor, assert_eq_text, extract_offset};
use super::*;
@ -147,15 +148,7 @@ fn main() {}
"#,
);
let hls = highlight(file.syntax());
assert_eq_dbg(
r#"[HighlightedRange { range: [1; 11), tag: "comment" },
HighlightedRange { range: [12; 14), tag: "keyword" },
HighlightedRange { range: [15; 19), tag: "function" },
HighlightedRange { range: [29; 37), tag: "macro" },
HighlightedRange { range: [38; 50), tag: "string" },
HighlightedRange { range: [52; 54), tag: "literal" }]"#,
&hls,
);
assert_debug_snapshot_matches!("highlighting", hls);
}
#[test]

View file

@ -0,0 +1,80 @@
Created: 2019-01-15T11:15:21.073862814+00:00
Creator: insta@0.1.4
Source: crates/ra_ide_api_light/src/structure.rs
[
StructureNode {
parent: None,
label: "Foo",
navigation_range: [8; 11),
node_range: [1; 26),
kind: STRUCT_DEF
},
StructureNode {
parent: Some(
0
),
label: "x",
navigation_range: [18; 19),
node_range: [18; 24),
kind: NAMED_FIELD_DEF
},
StructureNode {
parent: None,
label: "m",
navigation_range: [32; 33),
node_range: [28; 53),
kind: MODULE
},
StructureNode {
parent: Some(
2
),
label: "bar",
navigation_range: [43; 46),
node_range: [40; 51),
kind: FN_DEF
},
StructureNode {
parent: None,
label: "E",
navigation_range: [60; 61),
node_range: [55; 75),
kind: ENUM_DEF
},
StructureNode {
parent: None,
label: "T",
navigation_range: [81; 82),
node_range: [76; 88),
kind: TYPE_DEF
},
StructureNode {
parent: None,
label: "S",
navigation_range: [96; 97),
node_range: [89; 108),
kind: STATIC_DEF
},
StructureNode {
parent: None,
label: "C",
navigation_range: [115; 116),
node_range: [109; 127),
kind: CONST_DEF
},
StructureNode {
parent: None,
label: "impl E",
navigation_range: [134; 135),
node_range: [129; 138),
kind: IMPL_BLOCK
},
StructureNode {
parent: None,
label: "impl fmt::Debug for E",
navigation_range: [160; 161),
node_range: [140; 164),
kind: IMPL_BLOCK
}
]

View file

@ -0,0 +1,30 @@
Created: 2019-01-15T11:15:21.073858657+00:00
Creator: insta@0.1.4
Source: crates/ra_ide_api_light/src/lib.rs
[
HighlightedRange {
range: [1; 11),
tag: "comment"
},
HighlightedRange {
range: [12; 14),
tag: "keyword"
},
HighlightedRange {
range: [15; 19),
tag: "function"
},
HighlightedRange {
range: [29; 37),
tag: "macro"
},
HighlightedRange {
range: [38; 50),
tag: "string"
},
HighlightedRange {
range: [52; 54),
tag: "literal"
}
]

View file

@ -87,7 +87,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
#[cfg(test)]
mod tests {
use super::*;
use test_utils::assert_eq_dbg;
use insta::assert_debug_snapshot_matches;
#[test]
fn test_file_structure() {
@ -112,18 +112,6 @@ impl fmt::Debug for E {}
"#,
);
let structure = file_structure(&file);
assert_eq_dbg(
r#"[StructureNode { parent: None, label: "Foo", navigation_range: [8; 11), node_range: [1; 26), kind: STRUCT_DEF },
StructureNode { parent: Some(0), label: "x", navigation_range: [18; 19), node_range: [18; 24), kind: NAMED_FIELD_DEF },
StructureNode { parent: None, label: "m", navigation_range: [32; 33), node_range: [28; 53), kind: MODULE },
StructureNode { parent: Some(2), label: "bar", navigation_range: [43; 46), node_range: [40; 51), kind: FN_DEF },
StructureNode { parent: None, label: "E", navigation_range: [60; 61), node_range: [55; 75), kind: ENUM_DEF },
StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF },
StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF },
StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF },
StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_BLOCK },
StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_BLOCK }]"#,
&structure,
)
assert_debug_snapshot_matches!("file_structure", structure);
}
}