Test longest row only when tabs are not present or the tab size is 1

This is because the longest row calculation is best-effort at the moment,
since this information is not indexed in the `TabMap`.
This commit is contained in:
Antonio Scandurra 2021-11-18 10:41:47 +01:00
parent 5a9dea5299
commit 572e571927
2 changed files with 34 additions and 26 deletions

View file

@ -506,14 +506,14 @@ mod tests {
.map(|c| c.text) .map(|c| c.text)
.collect::<String>() .collect::<String>()
); );
assert_eq!(
TextSummary { let mut actual_summary = tabs_snapshot.text_summary_for_range(start..end);
longest_row: expected_summary.longest_row, if tab_size > 1 && folds_snapshot.text().contains('\t') {
longest_row_chars: expected_summary.longest_row_chars, actual_summary.longest_row = expected_summary.longest_row;
..tabs_snapshot.text_summary_for_range(start..end) actual_summary.longest_row_chars = expected_summary.longest_row_chars;
}, }
expected_summary,
); assert_eq!(actual_summary, expected_summary,);
} }
} }
} }

View file

@ -1214,26 +1214,34 @@ mod tests {
log::info!("{} summary: {:?}", ix, item.summary.output,); log::info!("{} summary: {:?}", ix, item.summary.output,);
} }
let mut expected_longest_rows = Vec::new(); if tab_size == 1
let mut longest_line_len = -1; || !wrapped_snapshot
for (row, line) in expected_text.split('\n').enumerate() { .tab_snapshot
let line_char_count = line.chars().count() as isize; .fold_snapshot
if line_char_count > longest_line_len { .text()
expected_longest_rows.clear(); .contains('\t')
longest_line_len = line_char_count; {
let mut expected_longest_rows = Vec::new();
let mut longest_line_len = -1;
for (row, line) in expected_text.split('\n').enumerate() {
let line_char_count = line.chars().count() as isize;
if line_char_count > longest_line_len {
expected_longest_rows.clear();
longest_line_len = line_char_count;
}
if line_char_count >= longest_line_len {
expected_longest_rows.push(row as u32);
}
} }
if line_char_count >= longest_line_len {
expected_longest_rows.push(row as u32);
}
}
assert!( assert!(
expected_longest_rows.contains(&actual_longest_row), expected_longest_rows.contains(&actual_longest_row),
"incorrect longest row {}. expected {:?} with length {}", "incorrect longest row {}. expected {:?} with length {}",
actual_longest_row, actual_longest_row,
expected_longest_rows, expected_longest_rows,
longest_line_len, longest_line_len,
) )
}
} }
} }