Fix test following change to fixture parsing (d016cb4867)

This commit is contained in:
David Lattimore 2020-06-27 11:31:15 +10:00
parent f4dc549582
commit fc46c12e36

View file

@ -209,6 +209,11 @@ fn assert_ssr_transform(rule: &str, input: &str, result: &str) {
assert_ssr_transforms(&[rule], input, result); assert_ssr_transforms(&[rule], input, result);
} }
fn normalize_code(code: &str) -> String {
let (db, file_id) = single_file(code);
db.file_text(file_id).to_string()
}
fn assert_ssr_transforms(rules: &[&str], input: &str, result: &str) { fn assert_ssr_transforms(rules: &[&str], input: &str, result: &str) {
let (db, file_id) = single_file(input); let (db, file_id) = single_file(input);
let mut match_finder = MatchFinder::new(&db); let mut match_finder = MatchFinder::new(&db);
@ -217,8 +222,13 @@ fn assert_ssr_transforms(rules: &[&str], input: &str, result: &str) {
match_finder.add_rule(rule); match_finder.add_rule(rule);
} }
if let Some(edits) = match_finder.edits_for_file(file_id) { if let Some(edits) = match_finder.edits_for_file(file_id) {
let mut after = input.to_string(); // Note, db.file_text is not necessarily the same as `input`, since fixture parsing alters
// stuff.
let mut after = db.file_text(file_id).to_string();
edits.apply(&mut after); edits.apply(&mut after);
// Likewise, we need to make sure that whatever transformations fixture parsing applies,
// also get appplied to our expected result.
let result = normalize_code(result);
assert_eq!(after, result); assert_eq!(after, result);
} else { } else {
panic!("No edits were made"); panic!("No edits were made");