Skip to content

Commit

Permalink
Fix some editor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed Feb 22, 2025
1 parent bb13799 commit 67a4955
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 262 deletions.
4 changes: 0 additions & 4 deletions crates/editor/src/display_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,10 +1285,6 @@ impl DisplaySnapshot {
self.inlay_highlights.get(&type_id)
}

pub fn buffer_header_height(&self) -> u32 {
self.block_snapshot.buffer_header_height
}

pub fn excerpt_footer_height(&self) -> u32 {
self.block_snapshot.excerpt_footer_height
}
Expand Down
55 changes: 16 additions & 39 deletions crates/editor/src/display_map/block_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2270,10 +2270,7 @@ mod tests {
let snapshot = block_map.read(wraps_snapshot, Default::default());

// Each excerpt has a header above and footer below. Excerpts are also *separated* by a newline.
assert_eq!(
snapshot.text(),
"\n\nBuff\ner 1\n\n\n\nBuff\ner 2\n\n\n\nBuff\ner 3\n"
);
assert_eq!(snapshot.text(), "\nBuff\ner 1\n\nBuff\ner 2\n\nBuff\ner 3");

let blocks: Vec<_> = snapshot
.blocks_in_range(0..u32::MAX)
Expand All @@ -2282,10 +2279,9 @@ mod tests {
assert_eq!(
blocks,
vec![
(0..2, BlockId::ExcerptBoundary(Some(excerpt_ids[0]))), // path, header
(4..7, BlockId::ExcerptBoundary(Some(excerpt_ids[1]))), // footer, path, header
(9..12, BlockId::ExcerptBoundary(Some(excerpt_ids[2]))), // footer, path, header
(14..15, BlockId::ExcerptBoundary(None)), // footer
(0..1, BlockId::ExcerptBoundary(Some(excerpt_ids[0]))),
(3..4, BlockId::ExcerptBoundary(Some(excerpt_ids[1]))),
(6..7, BlockId::ExcerptBoundary(Some(excerpt_ids[2]))),
]
);
}
Expand Down Expand Up @@ -2623,15 +2619,14 @@ mod tests {

assert_eq!(
blocks_snapshot.text(),
"\n\n\n111\n\n\n\n\n222\n\n\n333\n\n\n444\n\n\n\n\n555\n\n\n666\n"
"\n\n111\n\n\n\n\n222\n\n\n333\n\n\n444\n\n\n\n\n555\n\n\n666"
);
assert_eq!(
blocks_snapshot
.row_infos(BlockRow(0))
.map(|i| i.buffer_row)
.collect::<Vec<_>>(),
vec![
None,
None,
None,
Some(0),
Expand All @@ -2654,7 +2649,6 @@ mod tests {
None,
None,
Some(5),
None,
]
);

Expand Down Expand Up @@ -2702,15 +2696,14 @@ mod tests {
let blocks_snapshot = block_map.read(wrap_snapshot.clone(), Patch::default());
assert_eq!(
blocks_snapshot.text(),
"\n\n\n111\n\n\n\n\n\n222\n\n\n\n333\n\n\n444\n\n\n\n\n\n\n555\n\n\n666\n\n"
"\n\n111\n\n\n\n\n\n222\n\n\n\n333\n\n\n444\n\n\n\n\n\n\n555\n\n\n666\n"
);
assert_eq!(
blocks_snapshot
.row_infos(BlockRow(0))
.map(|i| i.buffer_row)
.collect::<Vec<_>>(),
vec![
None,
None,
None,
Some(0),
Expand Down Expand Up @@ -2738,7 +2731,6 @@ mod tests {
None,
Some(5),
None,
None,
]
);

Expand Down Expand Up @@ -2780,7 +2772,7 @@ mod tests {
);
assert_eq!(
blocks_snapshot.text(),
"\n\n\n\n\n\n222\n\n\n\n333\n\n\n444\n\n\n\n\n\n\n555\n\n\n666\n\n"
"\n\n\n\n\n\n222\n\n\n\n333\n\n\n444\n\n\n\n\n\n\n555\n\n\n666\n"
);
assert_eq!(
blocks_snapshot
Expand Down Expand Up @@ -2813,7 +2805,6 @@ mod tests {
None,
Some(5),
None,
None,
]
);

Expand Down Expand Up @@ -2849,7 +2840,7 @@ mod tests {
.count(),
"Should have two folded blocks, producing headers"
);
assert_eq!(blocks_snapshot.text(), "\n\n\n\n\n\n\n\n555\n\n\n666\n\n");
assert_eq!(blocks_snapshot.text(), "\n\n\n\n\n\n\n\n555\n\n\n666\n");
assert_eq!(
blocks_snapshot
.row_infos(BlockRow(0))
Expand All @@ -2869,7 +2860,6 @@ mod tests {
None,
Some(5),
None,
None,
]
);

Expand Down Expand Up @@ -2904,7 +2894,7 @@ mod tests {
);
assert_eq!(
blocks_snapshot.text(),
"\n\n\n\n111\n\n\n\n\n\n\n\n555\n\n\n666\n\n",
"\n\n\n111\n\n\n\n\n\n\n\n555\n\n\n666\n",
"Should have extra newline for 111 buffer, due to a new block added when it was folded"
);
assert_eq!(
Expand All @@ -2916,7 +2906,6 @@ mod tests {
None,
None,
None,
None,
Some(0),
None,
None,
Expand All @@ -2930,7 +2919,6 @@ mod tests {
None,
Some(5),
None,
None,
]
);

Expand Down Expand Up @@ -2961,26 +2949,15 @@ mod tests {

assert_eq!(
blocks_snapshot.text(),
"\n\n\n\n111\n\n\n\n\n",
"\n\n\n111\n\n\n\n\n",
"Should have a single, first buffer left after folding"
);
assert_eq!(
blocks_snapshot
.row_infos(BlockRow(0))
.map(|i| i.buffer_row)
.collect::<Vec<_>>(),
vec![
None,
None,
None,
None,
Some(0),
None,
None,
None,
None,
None,
]
vec![None, None, None, Some(0), None, None, None, None, None,]
);
}

Expand Down Expand Up @@ -3461,16 +3438,16 @@ mod tests {
let expected_row_count = expected_lines.len();
log::info!("expected text: {expected_text:?}");

assert_eq!(
blocks_snapshot.max_point().row + 1,
expected_row_count as u32,
"actual row count != expected row count",
);
assert_eq!(
blocks_snapshot.text(),
expected_text,
"actual text != expected text",
);
assert_eq!(
blocks_snapshot.max_point().row + 1,
expected_row_count as u32,
"actual row count != expected row count",
);

for start_row in 0..expected_row_count {
let end_row = rng.gen_range(start_row + 1..=expected_row_count);
Expand Down
22 changes: 11 additions & 11 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15490,7 +15490,7 @@ async fn test_multi_buffer_folding(cx: &mut TestAppContext) {
)
});

let full_text = "\n\n\naaaa\nbbbb\ncccc\n\n\n\nffff\ngggg\n\n\n\njjjj\n\n\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n\n\n\nvvvv\nwwww\nxxxx\n\n\n\n1111\n2222\n\n\n\n5555\n";
let full_text = "\n\naaaa\nbbbb\ncccc\n\n\n\nffff\ngggg\n\n\n\njjjj\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n\nvvvv\nwwww\nxxxx\n\n\n\n1111\n2222\n\n\n\n5555";
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
full_text,
Expand All @@ -15501,7 +15501,7 @@ async fn test_multi_buffer_folding(cx: &mut TestAppContext) {
});
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n\n\n\nvvvv\nwwww\nxxxx\n\n\n\n1111\n2222\n\n\n\n5555\n",
"\n\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n\nvvvv\nwwww\nxxxx\n\n\n\n1111\n2222\n\n\n\n5555",
"After folding the first buffer, its text should not be displayed"
);

Expand All @@ -15510,7 +15510,7 @@ async fn test_multi_buffer_folding(cx: &mut TestAppContext) {
});
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\n\n\n\n\nvvvv\nwwww\nxxxx\n\n\n\n1111\n2222\n\n\n\n5555\n",
"\n\n\n\n\n\nvvvv\nwwww\nxxxx\n\n\n\n1111\n2222\n\n\n\n5555",
"After folding the second buffer, its text should not be displayed"
);

Expand All @@ -15535,7 +15535,7 @@ async fn test_multi_buffer_folding(cx: &mut TestAppContext) {
});
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n\n",
"\n\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n",
"After unfolding the second buffer, its text should be displayed"
);

Expand All @@ -15544,7 +15544,7 @@ async fn test_multi_buffer_folding(cx: &mut TestAppContext) {
});
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\naaaa\nbbbb\ncccc\n\n\n\nffff\ngggg\n\n\n\njjjj\n\n\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n\n",
"\n\naaaa\nbbbb\ncccc\n\n\n\nffff\ngggg\n\n\n\njjjj\n\n\nllll\nmmmm\nnnnn\n\n\n\nqqqq\nrrrr\n\n\n\nuuuu\n\n",
"After unfolding the first buffer, its and 2nd buffer's text should be displayed"
);

Expand Down Expand Up @@ -15645,7 +15645,7 @@ async fn test_multi_buffer_single_excerpts_folding(cx: &mut TestAppContext) {
)
});

let full_text = "\n\n\n1111\n2222\n3333\n\n\n\n\n4444\n5555\n6666\n\n\n\n\n7777\n8888\n9999\n";
let full_text = "\n\n1111\n2222\n3333\n\n\n4444\n5555\n6666\n\n\n7777\n8888\n9999";
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
full_text,
Expand All @@ -15656,7 +15656,7 @@ async fn test_multi_buffer_single_excerpts_folding(cx: &mut TestAppContext) {
});
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\n\n\n4444\n5555\n6666\n\n\n\n\n7777\n8888\n9999\n",
"\n\n\n\n4444\n5555\n6666\n\n\n7777\n8888\n9999",
"After folding the first buffer, its text should not be displayed"
);

Expand All @@ -15666,7 +15666,7 @@ async fn test_multi_buffer_single_excerpts_folding(cx: &mut TestAppContext) {

assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\n\n\n\n\n7777\n8888\n9999\n",
"\n\n\n\n\n\n7777\n8888\n9999",
"After folding the second buffer, its text should not be displayed"
);

Expand All @@ -15684,7 +15684,7 @@ async fn test_multi_buffer_single_excerpts_folding(cx: &mut TestAppContext) {
});
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\n\n\n4444\n5555\n6666\n\n\n",
"\n\n\n\n4444\n5555\n6666\n\n",
"After unfolding the second buffer, its text should be displayed"
);

Expand All @@ -15693,7 +15693,7 @@ async fn test_multi_buffer_single_excerpts_folding(cx: &mut TestAppContext) {
});
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
"\n\n\n1111\n2222\n3333\n\n\n\n\n4444\n5555\n6666\n\n\n",
"\n\n1111\n2222\n3333\n\n\n4444\n5555\n6666\n\n",
"After unfolding the first buffer, its text should be displayed"
);

Expand Down Expand Up @@ -15778,7 +15778,7 @@ async fn test_multi_buffer_with_single_excerpt_folding(cx: &mut TestAppContext)
editor.change_selections(None, window, cx, |s| s.select_ranges(Some(highlight_range)));
});

let full_text = format!("\n\n\n{sample_text}\n");
let full_text = format!("\n\n{sample_text}");
assert_eq!(
multi_buffer_editor.update(cx, |editor, cx| editor.display_text(cx)),
full_text,
Expand Down
51 changes: 25 additions & 26 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8769,26 +8769,25 @@ mod tests {
// multi-buffer support
// in DisplayPoint coordinates, this is what we're dealing with:
// 0: [[file
// 1: header
// 2: section]]
// 3: aaaaaa
// 4: bbbbbb
// 5: cccccc
// 6:
// 7: [[footer]]
// 8: [[header]]
// 9: ffffff
// 10: gggggg
// 11: hhhhhh
// 12:
// 13: [[footer]]
// 14: [[file
// 15: header
// 16: section]]
// 17: bbbbbb
// 18: cccccc
// 19: dddddd
// 20: [[footer]]
// 1: header]]
// 2: aaaaaa
// 3: bbbbbb
// 4: cccccc
// 5:
// 6: [[footer]]
// 7: [[header]]
// 8: ffffff
// 9: gggggg
// 10: hhhhhh
// 11:
// 12: [[footer]]
// 13: [[file
// 14: header
// 15: section]]
// 16: bbbbbb
// 17: cccccc
// 18: dddddd
// 19: [[footer]]
let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_multi(
[
Expand All @@ -8814,8 +8813,8 @@ mod tests {
editor.cursor_shape = CursorShape::Block;
editor.change_selections(None, window, cx, |s| {
s.select_display_ranges([
DisplayPoint::new(DisplayRow(4), 0)..DisplayPoint::new(DisplayRow(7), 0),
DisplayPoint::new(DisplayRow(10), 0)..DisplayPoint::new(DisplayRow(13), 0),
DisplayPoint::new(DisplayRow(4), 0)..DisplayPoint::new(DisplayRow(6), 0),
DisplayPoint::new(DisplayRow(10), 0)..DisplayPoint::new(DisplayRow(12), 0),
]);
});
});
Expand All @@ -8833,21 +8832,21 @@ mod tests {
// and doesn't allow selection to bleed through
assert_eq!(
local_selections[0].range,
DisplayPoint::new(DisplayRow(4), 0)..DisplayPoint::new(DisplayRow(7), 0)
DisplayPoint::new(DisplayRow(4), 0)..DisplayPoint::new(DisplayRow(6), 0)
);
assert_eq!(
local_selections[0].head,
DisplayPoint::new(DisplayRow(6), 0)
DisplayPoint::new(DisplayRow(5), 0)
);
// moves cursor on buffer boundary back two lines
// and doesn't allow selection to bleed through
assert_eq!(
local_selections[1].range,
DisplayPoint::new(DisplayRow(10), 0)..DisplayPoint::new(DisplayRow(13), 0)
DisplayPoint::new(DisplayRow(10), 0)..DisplayPoint::new(DisplayRow(12), 0)
);
assert_eq!(
local_selections[1].head,
DisplayPoint::new(DisplayRow(12), 0)
DisplayPoint::new(DisplayRow(11), 0)
);
}

Expand Down
Loading

0 comments on commit 67a4955

Please sign in to comment.