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)
.collect::<String>()
);
assert_eq!(
TextSummary {
longest_row: expected_summary.longest_row,
longest_row_chars: expected_summary.longest_row_chars,
..tabs_snapshot.text_summary_for_range(start..end)
},
expected_summary,
);
let mut actual_summary = tabs_snapshot.text_summary_for_range(start..end);
if tab_size > 1 && folds_snapshot.text().contains('\t') {
actual_summary.longest_row = expected_summary.longest_row;
actual_summary.longest_row_chars = expected_summary.longest_row_chars;
}
assert_eq!(actual_summary, expected_summary,);
}
}
}

View File

@ -1214,26 +1214,34 @@ mod tests {
log::info!("{} summary: {:?}", ix, item.summary.output,);
}
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 tab_size == 1
|| !wrapped_snapshot
.tab_snapshot
.fold_snapshot
.text()
.contains('\t')
{
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!(
expected_longest_rows.contains(&actual_longest_row),
"incorrect longest row {}. expected {:?} with length {}",
actual_longest_row,
expected_longest_rows,
longest_line_len,
)
assert!(
expected_longest_rows.contains(&actual_longest_row),
"incorrect longest row {}. expected {:?} with length {}",
actual_longest_row,
expected_longest_rows,
longest_line_len,
)
}
}
}