Use fixtures more

This commit is contained in:
Aleksey Kladov 2020-06-24 11:05:47 +02:00
parent 08e2149eab
commit e9cb818c26
6 changed files with 135 additions and 133 deletions

View file

@ -348,8 +348,10 @@ mod tests {
); );
} }
fn check_apply_diagnostic_fix(before: &str, after: &str) { fn check_apply_diagnostic_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
let (analysis, file_id) = single_file(before); let ra_fixture_after = &trim_indent(ra_fixture_after);
let (analysis, file_id) = single_file(ra_fixture_before);
let before = analysis.file_text(file_id).unwrap();
let diagnostic = analysis.diagnostics(file_id).unwrap().pop().unwrap(); let diagnostic = analysis.diagnostics(file_id).unwrap().pop().unwrap();
let mut fix = diagnostic.fix.unwrap(); let mut fix = diagnostic.fix.unwrap();
let edit = fix.source_change.source_file_edits.pop().unwrap().edit; let edit = fix.source_change.source_file_edits.pop().unwrap().edit;
@ -358,7 +360,7 @@ mod tests {
edit.apply(&mut actual); edit.apply(&mut actual);
actual actual
}; };
assert_eq_text!(after, &actual); assert_eq_text!(ra_fixture_after, &actual);
} }
/// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics
@ -709,7 +711,7 @@ mod tests {
[ [
Diagnostic { Diagnostic {
message: "Missing structure fields:\n- b\n", message: "Missing structure fields:\n- b\n",
range: 224..233, range: 127..136,
severity: Error, severity: Error,
fix: Some( fix: Some(
Fix { Fix {

View file

@ -315,17 +315,15 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use test_utils::extract_offset; use crate::mock_analysis::single_file_with_position;
use crate::mock_analysis::single_file;
use super::*; use super::*;
fn do_check(before: &str, afters: &[&str]) { fn do_check(before: &str, afters: &[&str]) {
let (cursor, before) = extract_offset(before); let (analysis, position) = single_file_with_position(&before);
let (analysis, file_id) = single_file(&before); let before = analysis.file_text(position.file_id).unwrap();
let range = TextRange::empty(cursor); let range = TextRange::empty(position.offset);
let mut frange = FileRange { file_id, range }; let mut frange = FileRange { file_id: position.file_id, range };
for &after in afters { for &after in afters {
frange.range = analysis.extend_selection(frange).unwrap(); frange.range = analysis.extend_selection(frange).unwrap();

View file

@ -363,16 +363,17 @@ mod tests {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: true, type_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 106..107, range: 69..70,
kind: ParameterHint, kind: ParameterHint,
label: "a", label: "a",
}, },
InlayHint { InlayHint {
range: 109..110, range: 72..73,
kind: ParameterHint, kind: ParameterHint,
label: "b", label: "b",
}, },
]"###); ]
"###);
} }
#[test] #[test]
@ -399,11 +400,12 @@ mod tests {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ type_hints: true, parameter_hints: false, chaining_hints: false, max_length: None}).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 97..99, range: 60..62,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
]"###); ]
"###);
} }
#[test] #[test]
fn default_generic_types_should_not_be_displayed() { fn default_generic_types_should_not_be_displayed() {
@ -423,12 +425,12 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 69..71, range: 68..70,
kind: TypeHint, kind: TypeHint,
label: "Test<i32>", label: "Test<i32>",
}, },
InlayHint { InlayHint {
range: 107..113, range: 106..112,
kind: TypeHint, kind: TypeHint,
label: "&Test<i32>", label: "&Test<i32>",
}, },
@ -480,57 +482,57 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 193..197, range: 192..196,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 236..244, range: 235..243,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 275..279, range: 274..278,
kind: TypeHint, kind: TypeHint,
label: "&str", label: "&str",
}, },
InlayHint { InlayHint {
range: 539..543, range: 538..542,
kind: TypeHint, kind: TypeHint,
label: "(i32, char)", label: "(i32, char)",
}, },
InlayHint { InlayHint {
range: 566..567, range: 565..566,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 570..571, range: 569..570,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 573..574, range: 572..573,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 577..578, range: 576..577,
kind: TypeHint, kind: TypeHint,
label: "f64", label: "f64",
}, },
InlayHint { InlayHint {
range: 580..581, range: 579..580,
kind: TypeHint, kind: TypeHint,
label: "f64", label: "f64",
}, },
InlayHint { InlayHint {
range: 584..585, range: 583..584,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 627..628, range: 626..627,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
@ -560,47 +562,47 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 21..30, range: 20..29,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 57..66, range: 56..65,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 115..123, range: 114..122,
kind: TypeHint, kind: TypeHint,
label: "|…| -> i32", label: "|…| -> i32",
}, },
InlayHint { InlayHint {
range: 127..128, range: 126..127,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 130..131, range: 129..130,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 133..134, range: 132..133,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 136..137, range: 135..136,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 201..213, range: 200..212,
kind: TypeHint, kind: TypeHint,
label: "&|…| -> i32", label: "&|…| -> i32",
}, },
InlayHint { InlayHint {
range: 236..245, range: 235..244,
kind: TypeHint, kind: TypeHint,
label: "|| -> i32", label: "|| -> i32",
}, },
@ -624,12 +626,12 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 21..30, range: 20..29,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 44..53, range: 43..52,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
@ -674,57 +676,57 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 188..192, range: 187..191,
kind: TypeHint, kind: TypeHint,
label: "CustomOption<Test>", label: "CustomOption<Test>",
}, },
InlayHint { InlayHint {
range: 267..271, range: 266..270,
kind: TypeHint, kind: TypeHint,
label: "&CustomOption<Test>", label: "&CustomOption<Test>",
}, },
InlayHint { InlayHint {
range: 300..304, range: 299..303,
kind: TypeHint, kind: TypeHint,
label: "&Test", label: "&Test",
}, },
InlayHint { InlayHint {
range: 341..342, range: 340..341,
kind: TypeHint, kind: TypeHint,
label: "&CustomOption<u32>", label: "&CustomOption<u32>",
}, },
InlayHint { InlayHint {
range: 344..345, range: 343..344,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 387..388, range: 386..387,
kind: TypeHint, kind: TypeHint,
label: "&CustomOption<u32>", label: "&CustomOption<u32>",
}, },
InlayHint { InlayHint {
range: 393..394, range: 392..393,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 441..442, range: 440..441,
kind: TypeHint, kind: TypeHint,
label: "&u32", label: "&u32",
}, },
InlayHint { InlayHint {
range: 448..449, range: 447..448,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 500..501, range: 499..500,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 543..544, range: 542..543,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
@ -769,57 +771,57 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 188..192, range: 187..191,
kind: TypeHint, kind: TypeHint,
label: "CustomOption<Test>", label: "CustomOption<Test>",
}, },
InlayHint { InlayHint {
range: 273..277, range: 272..276,
kind: TypeHint, kind: TypeHint,
label: "&CustomOption<Test>", label: "&CustomOption<Test>",
}, },
InlayHint { InlayHint {
range: 309..313, range: 308..312,
kind: TypeHint, kind: TypeHint,
label: "&Test", label: "&Test",
}, },
InlayHint { InlayHint {
range: 353..354, range: 352..353,
kind: TypeHint, kind: TypeHint,
label: "&CustomOption<u32>", label: "&CustomOption<u32>",
}, },
InlayHint { InlayHint {
range: 356..357, range: 355..356,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 402..403, range: 401..402,
kind: TypeHint, kind: TypeHint,
label: "&CustomOption<u32>", label: "&CustomOption<u32>",
}, },
InlayHint { InlayHint {
range: 408..409, range: 407..408,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 459..460, range: 458..459,
kind: TypeHint, kind: TypeHint,
label: "&u32", label: "&u32",
}, },
InlayHint { InlayHint {
range: 466..467, range: 465..466,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 521..522, range: 520..521,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
InlayHint { InlayHint {
range: 567..568, range: 566..567,
kind: TypeHint, kind: TypeHint,
label: "&u8", label: "&u8",
}, },
@ -864,52 +866,52 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 252..256, range: 251..255,
kind: TypeHint, kind: TypeHint,
label: "CustomOption<Test>", label: "CustomOption<Test>",
}, },
InlayHint { InlayHint {
range: 277..281, range: 276..280,
kind: TypeHint, kind: TypeHint,
label: "Test", label: "Test",
}, },
InlayHint { InlayHint {
range: 310..311, range: 309..310,
kind: TypeHint, kind: TypeHint,
label: "CustomOption<u32>", label: "CustomOption<u32>",
}, },
InlayHint { InlayHint {
range: 313..314, range: 312..313,
kind: TypeHint, kind: TypeHint,
label: "u8", label: "u8",
}, },
InlayHint { InlayHint {
range: 348..349, range: 347..348,
kind: TypeHint, kind: TypeHint,
label: "CustomOption<u32>", label: "CustomOption<u32>",
}, },
InlayHint { InlayHint {
range: 354..355, range: 353..354,
kind: TypeHint, kind: TypeHint,
label: "u8", label: "u8",
}, },
InlayHint { InlayHint {
range: 394..395, range: 393..394,
kind: TypeHint, kind: TypeHint,
label: "u32", label: "u32",
}, },
InlayHint { InlayHint {
range: 401..402, range: 400..401,
kind: TypeHint, kind: TypeHint,
label: "u8", label: "u8",
}, },
InlayHint { InlayHint {
range: 445..446, range: 444..445,
kind: TypeHint, kind: TypeHint,
label: "u8", label: "u8",
}, },
InlayHint { InlayHint {
range: 480..481, range: 479..480,
kind: TypeHint, kind: TypeHint,
label: "u8", label: "u8",
}, },
@ -936,17 +938,17 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 74..75, range: 73..74,
kind: TypeHint, kind: TypeHint,
label: "Smol<u32>", label: "Smol<u32>",
}, },
InlayHint { InlayHint {
range: 98..99, range: 97..98,
kind: TypeHint, kind: TypeHint,
label: "VeryLongOuterName<…>", label: "VeryLongOuterName<…>",
}, },
InlayHint { InlayHint {
range: 137..138, range: 136..137,
kind: TypeHint, kind: TypeHint,
label: "Smol<Smol<…>>", label: "Smol<Smol<…>>",
}, },
@ -1024,77 +1026,77 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig::default()).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 798..809, range: 797..808,
kind: TypeHint, kind: TypeHint,
label: "i32", label: "i32",
}, },
InlayHint { InlayHint {
range: 842..843, range: 841..842,
kind: ParameterHint, kind: ParameterHint,
label: "foo", label: "foo",
}, },
InlayHint { InlayHint {
range: 845..846, range: 844..845,
kind: ParameterHint, kind: ParameterHint,
label: "bar", label: "bar",
}, },
InlayHint { InlayHint {
range: 848..855, range: 847..854,
kind: ParameterHint, kind: ParameterHint,
label: "msg", label: "msg",
}, },
InlayHint { InlayHint {
range: 860..871, range: 859..870,
kind: ParameterHint, kind: ParameterHint,
label: "last", label: "last",
}, },
InlayHint { InlayHint {
range: 914..917, range: 913..916,
kind: ParameterHint, kind: ParameterHint,
label: "param", label: "param",
}, },
InlayHint { InlayHint {
range: 937..939, range: 936..938,
kind: ParameterHint, kind: ParameterHint,
label: "&self", label: "&self",
}, },
InlayHint { InlayHint {
range: 941..945, range: 940..944,
kind: ParameterHint, kind: ParameterHint,
label: "param", label: "param",
}, },
InlayHint { InlayHint {
range: 980..989, range: 979..988,
kind: ParameterHint, kind: ParameterHint,
label: "file_id", label: "file_id",
}, },
InlayHint { InlayHint {
range: 999..1012, range: 998..1011,
kind: ParameterHint, kind: ParameterHint,
label: "name", label: "name",
}, },
InlayHint { InlayHint {
range: 1022..1026, range: 1021..1025,
kind: ParameterHint, kind: ParameterHint,
label: "focus_range", label: "focus_range",
}, },
InlayHint { InlayHint {
range: 1036..1048, range: 1035..1047,
kind: ParameterHint, kind: ParameterHint,
label: "full_range", label: "full_range",
}, },
InlayHint { InlayHint {
range: 1058..1071, range: 1057..1070,
kind: ParameterHint, kind: ParameterHint,
label: "kind", label: "kind",
}, },
InlayHint { InlayHint {
range: 1081..1085, range: 1080..1084,
kind: ParameterHint, kind: ParameterHint,
label: "docs", label: "docs",
}, },
InlayHint { InlayHint {
range: 1095..1099, range: 1094..1098,
kind: ParameterHint, kind: ParameterHint,
label: "description", label: "description",
}, },
@ -1239,16 +1241,17 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 232..269, range: 147..172,
kind: ChainingHint, kind: ChainingHint,
label: "B", label: "B",
}, },
InlayHint { InlayHint {
range: 232..239, range: 147..154,
kind: ChainingHint, kind: ChainingHint,
label: "A", label: "A",
}, },
]"###); ]
"###);
} }
#[test] #[test]
@ -1293,12 +1296,12 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 252..323, range: 143..190,
kind: ChainingHint, kind: ChainingHint,
label: "C", label: "C",
}, },
InlayHint { InlayHint {
range: 252..300, range: 143..179,
kind: ChainingHint, kind: ChainingHint,
label: "B", label: "B",
}, },
@ -1331,15 +1334,16 @@ fn main() {
assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###" assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsConfig{ parameter_hints: false, type_hints: false, chaining_hints: true, max_length: None}).unwrap(), @r###"
[ [
InlayHint { InlayHint {
range: 403..452, range: 246..283,
kind: ChainingHint, kind: ChainingHint,
label: "B<X<i32, bool>>", label: "B<X<i32, bool>>",
}, },
InlayHint { InlayHint {
range: 403..422, range: 246..265,
kind: ChainingHint, kind: ChainingHint,
label: "A<X<i32, bool>>", label: "A<X<i32, bool>>",
}, },
]"###); ]
"###);
} }
} }

View file

@ -117,13 +117,13 @@ impl MockAnalysis {
(res, position) (res, position)
} }
pub fn add_file_fixture(&mut self, fixture: Fixture) -> FileId { fn add_file_fixture(&mut self, fixture: Fixture) -> FileId {
let file_id = self.next_id(); let file_id = self.next_id();
self.files.push(MockFileData::from(fixture)); self.files.push(MockFileData::from(fixture));
file_id file_id
} }
pub fn add_file_fixture_with_position(&mut self, mut fixture: Fixture) -> FilePosition { fn add_file_fixture_with_position(&mut self, mut fixture: Fixture) -> FilePosition {
let (offset, text) = extract_offset(&fixture.text); let (offset, text) = extract_offset(&fixture.text);
fixture.text = text; fixture.text = text;
let file_id = self.next_id(); let file_id = self.next_id();
@ -136,13 +136,13 @@ impl MockAnalysis {
self.files.push(MockFileData::new(path.to_string(), text.to_string())); self.files.push(MockFileData::new(path.to_string(), text.to_string()));
file_id file_id
} }
pub fn add_file_with_position(&mut self, path: &str, text: &str) -> FilePosition { fn add_file_with_position(&mut self, path: &str, text: &str) -> FilePosition {
let (offset, text) = extract_offset(text); let (offset, text) = extract_offset(text);
let file_id = self.next_id(); let file_id = self.next_id();
self.files.push(MockFileData::new(path.to_string(), text)); self.files.push(MockFileData::new(path.to_string(), text));
FilePosition { file_id, offset } FilePosition { file_id, offset }
} }
pub fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange { fn add_file_with_range(&mut self, path: &str, text: &str) -> FileRange {
let (range, text) = extract_range(text); let (range, text) = extract_range(text);
let file_id = self.next_id(); let file_id = self.next_id();
self.files.push(MockFileData::new(path.to_string(), text)); self.files.push(MockFileData::new(path.to_string(), text));
@ -222,8 +222,8 @@ pub fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) {
/// Creates analysis for a single file. /// Creates analysis for a single file.
pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) { pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) {
let mut mock = MockAnalysis::new(); let mock = MockAnalysis::with_files(ra_fixture);
let file_id = mock.add_file("/main.rs", ra_fixture); let file_id = mock.id_of("/main.rs");
(mock.analysis(), file_id) (mock.analysis(), file_id)
} }

View file

@ -144,12 +144,13 @@ fn test_ranges() {
struct Foo { struct Foo {
pub x: i32, pub x: i32,
pub y: i32, pub y: i32,
}"#, }
"#,
); );
// The "x" // The "x"
let highlights = &analysis let highlights = &analysis
.highlight_range(FileRange { file_id, range: TextRange::at(82.into(), 1.into()) }) .highlight_range(FileRange { file_id, range: TextRange::at(45.into(), 1.into()) })
.unwrap(); .unwrap();
assert_eq!(&highlights[0].highlight.to_string(), "field.declaration"); assert_eq!(&highlights[0].highlight.to_string(), "field.declaration");

View file

@ -75,18 +75,15 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use test_utils::{assert_eq_text, extract_offset}; use test_utils::assert_eq_text;
use crate::mock_analysis::single_file; use crate::mock_analysis::single_file_with_position;
use super::*;
fn apply_on_enter(before: &str) -> Option<String> { fn apply_on_enter(before: &str) -> Option<String> {
let (offset, before) = extract_offset(before); let (analysis, position) = single_file_with_position(&before);
let (analysis, file_id) = single_file(&before); let result = analysis.on_enter(position).unwrap()?;
let result = analysis.on_enter(FilePosition { offset, file_id }).unwrap()?;
let mut actual = before.to_string(); let mut actual = analysis.file_text(position.file_id).unwrap().to_string();
result.apply(&mut actual); result.apply(&mut actual);
Some(actual) Some(actual)
} }