refactor: deepen conflict History alignment ownership
This commit is contained in:
@@ -4,6 +4,67 @@ std::thread_local! {
|
||||
pub(super) static WIDTH_SCANS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conflict_history_preserves_source_gaps_base_changes_and_native_eof_rows() {
|
||||
let history = HistoryComparison::new([
|
||||
"xbc def\nkeep\n",
|
||||
"abc def\nkeep\n",
|
||||
"abc deg\nadded\nkeep\n",
|
||||
]);
|
||||
let rows: Vec<_> = (0..history.row_count())
|
||||
.map(|row| {
|
||||
std::array::from_fn::<_, 3, _>(|column| history.column(column).source_row(row))
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
rows,
|
||||
[
|
||||
[Some(0), Some(0), Some(0)],
|
||||
[None, None, Some(1)],
|
||||
[Some(1), Some(1), Some(2)],
|
||||
[Some(2), Some(2), Some(3)],
|
||||
]
|
||||
);
|
||||
for column in 0..3 {
|
||||
let projection = history.column(column);
|
||||
for (display, row) in rows.iter().enumerate() {
|
||||
if let Some(source) = row[column] {
|
||||
assert_eq!(projection.display_row(source), Some(display));
|
||||
}
|
||||
}
|
||||
}
|
||||
let base = history.column(1);
|
||||
let changed = &base.diff.rows[0].changes;
|
||||
for column in [0, 6] {
|
||||
assert!(changed.iter().any(|range| range[0].contains(&column)));
|
||||
}
|
||||
assert!(!changed.iter().any(|range| range[0].contains(&4)));
|
||||
assert_eq!(base.diff.rows[2].kind, RowKind::Equal);
|
||||
assert!(base.diff.rows[2].changes.is_empty());
|
||||
assert_eq!(history.column(2).lines[1], "added");
|
||||
|
||||
// Rebuilding for a new input/base choice must not retain old source mappings.
|
||||
let history = HistoryComparison::new([
|
||||
"abc def\nkeep\n",
|
||||
"abc deg\nadded\nkeep\n",
|
||||
"xbc def\nkeep\n",
|
||||
]);
|
||||
assert_eq!(history.column(1).source_row(1), Some(1));
|
||||
assert_eq!(history.column(0).source_row(1), None);
|
||||
assert_eq!(history.column(2).source_row(1), None);
|
||||
for text in ["", "\n", "same", "same\n"] {
|
||||
let history = HistoryComparison::new([text; 3]);
|
||||
let native_rows = text.split('\n').count();
|
||||
assert_eq!(history.row_count(), native_rows);
|
||||
for column in 0..3 {
|
||||
for row in 0..native_rows {
|
||||
assert_eq!(history.column(column).source_row(row), Some(row));
|
||||
assert_eq!(history.column(column).display_row(row), Some(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolver_equal_text_retains_native_rows_and_cached_viewport() {
|
||||
for text in ["", "\n", "same\n", "same"] {
|
||||
|
||||
Reference in New Issue
Block a user