From e06d010aab8e3b67efea0131d1cdbd7e3c28b203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Fri, 7 Mar 2025 13:19:12 -0300 Subject: [PATCH] Test folded buffers navigation (#26286) #25944 but now with Vim mode off. Release Notes: - N/A --- crates/editor/src/editor_tests.rs | 193 ++++++++++++++++++ crates/editor/src/test/editor_test_context.rs | 10 +- 2 files changed, 199 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 02da8d38ff..451f2ede88 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -16413,6 +16413,199 @@ async fn test_folding_buffer_when_multibuffer_has_only_one_excerpt(cx: &mut Test ); } +#[gpui::test] +async fn test_multi_buffer_navigation_with_folded_buffers(cx: &mut TestAppContext) { + init_test(cx, |_| {}); + cx.update(|cx| { + let default_key_bindings = settings::KeymapFile::load_asset_allow_partial_failure( + "keymaps/default-linux.json", + cx, + ) + .unwrap(); + cx.bind_keys(default_key_bindings); + }); + + let (editor, cx) = cx.add_window_view(|window, cx| { + let multi_buffer = MultiBuffer::build_multi( + [ + ("a0\nb0\nc0\nd0\ne0\n", vec![Point::row_range(0..2)]), + ("a1\nb1\nc1\nd1\ne1\n", vec![Point::row_range(0..2)]), + ("a2\nb2\nc2\nd2\ne2\n", vec![Point::row_range(0..2)]), + ("a3\nb3\nc3\nd3\ne3\n", vec![Point::row_range(0..2)]), + ], + cx, + ); + let mut editor = Editor::new( + EditorMode::Full, + multi_buffer.clone(), + None, + true, + window, + cx, + ); + + let buffer_ids = multi_buffer.read(cx).excerpt_buffer_ids(); + // fold all but the second buffer, so that we test navigating between two + // adjacent folded buffers, as well as folded buffers at the start and + // end the multibuffer + editor.fold_buffer(buffer_ids[0], cx); + editor.fold_buffer(buffer_ids[2], cx); + editor.fold_buffer(buffer_ids[3], cx); + + editor + }); + cx.simulate_resize(size(px(1000.), px(1000.))); + + let mut cx = EditorTestContext::for_editor_in(editor.clone(), cx).await; + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + ˇ[FOLDED] + [EXCERPT] + a1 + b1 + [EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + cx.simulate_keystroke("down"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + ˇa1 + b1 + [EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + cx.simulate_keystroke("down"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + a1 + ˇb1 + [EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + cx.simulate_keystroke("down"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + a1 + b1 + ˇ[EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + cx.simulate_keystroke("down"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + a1 + b1 + [EXCERPT] + ˇ[FOLDED] + [EXCERPT] + [FOLDED] + " + }); + for _ in 0..5 { + cx.simulate_keystroke("down"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + a1 + b1 + [EXCERPT] + [FOLDED] + [EXCERPT] + ˇ[FOLDED] + " + }); + } + + cx.simulate_keystroke("up"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + a1 + b1 + [EXCERPT] + ˇ[FOLDED] + [EXCERPT] + [FOLDED] + " + }); + cx.simulate_keystroke("up"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + a1 + b1 + ˇ[EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + cx.simulate_keystroke("up"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + a1 + ˇb1 + [EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + cx.simulate_keystroke("up"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + [FOLDED] + [EXCERPT] + ˇa1 + b1 + [EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + for _ in 0..5 { + cx.simulate_keystroke("up"); + cx.assert_excerpts_with_selections(indoc! {" + [EXCERPT] + ˇ[FOLDED] + [EXCERPT] + a1 + b1 + [EXCERPT] + [FOLDED] + [EXCERPT] + [FOLDED] + " + }); + } +} + #[gpui::test] async fn test_inline_completion_text(cx: &mut TestAppContext) { init_test(cx, |_| {}); diff --git a/crates/editor/src/test/editor_test_context.rs b/crates/editor/src/test/editor_test_context.rs index c5132773e3..26a5819ec6 100644 --- a/crates/editor/src/test/editor_test_context.rs +++ b/crates/editor/src/test/editor_test_context.rs @@ -429,12 +429,14 @@ impl EditorTestContext { if expected_selections.len() > 0 { assert!( is_selected, - "excerpt {} should be selected. Got {:?}", - ix, - self.editor_state() + "excerpt {ix} should be selected. got {:?}", + self.editor_state(), ); } else { - assert!(!is_selected, "excerpt {} should not be selected", ix); + assert!( + !is_selected, + "excerpt {ix} should not be selected, got: {selections:?}", + ); } continue; }