vim test redux (#11709)

This cleans up the neovim-backed vim tests:
- removed exempted tests (we'll rely on bug reports to find missing edge
cases)
- moved all assertions into non-async fn's so that failures are
reporting on the right file/line
- removed the NeovimBackedBindingTestContext
- renamed a few things to make them clearer
- reduced the number of permutations tested in some cases to reduce
slowest test from 60s to 5s

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-05-11 12:04:05 -06:00 committed by GitHub
parent 48cba328f2
commit f550f23b97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 2311 additions and 6505 deletions

View file

@ -158,280 +158,358 @@ mod test {
use crate::{
state::Mode,
test::{ExemptionFeatures, NeovimBackedTestContext, VimTestContext},
test::{NeovimBackedTestContext, VimTestContext},
};
#[gpui::test]
async fn test_delete_h(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "h"]);
cx.assert("Teˇst").await;
cx.assert("Tˇest").await;
cx.assert("ˇTest").await;
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate("d h", "Teˇst").await.assert_matches();
cx.simulate("d h", "Tˇest").await.assert_matches();
cx.simulate("d h", "ˇTest").await.assert_matches();
cx.simulate(
"d h",
indoc! {"
Test
ˇtest"})
.await;
ˇtest"},
)
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_l(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "l"]);
cx.assert("ˇTest").await;
cx.assert("Teˇst").await;
cx.assert("Tesˇt").await;
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate("d l", "ˇTest").await.assert_matches();
cx.simulate("d l", "Teˇst").await.assert_matches();
cx.simulate("d l", "Tesˇt").await.assert_matches();
cx.simulate(
"d l",
indoc! {"
Tesˇt
test"})
.await;
test"},
)
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_w(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
cx.simulate(
"d w",
indoc! {"
Test tesˇt
test"},
["d", "w"],
)
.await;
.await
.assert_matches();
cx.assert_neovim_compatible("Teˇst", ["d", "w"]).await;
cx.assert_neovim_compatible("Tˇest test", ["d", "w"]).await;
cx.assert_neovim_compatible(
cx.simulate("d w", "Teˇst").await.assert_matches();
cx.simulate("d w", "Tˇest test").await.assert_matches();
cx.simulate(
"d w",
indoc! {"
Test teˇst
test"},
["d", "w"],
)
.await;
cx.assert_neovim_compatible(
.await
.assert_matches();
cx.simulate(
"d w",
indoc! {"
Test tesˇt
test"},
["d", "w"],
)
.await;
.await
.assert_matches();
cx.assert_neovim_compatible(
cx.simulate(
"d w",
indoc! {"
Test test
ˇ
test"},
["d", "w"],
)
.await;
.await
.assert_matches();
let mut cx = cx.binding(["d", "shift-w"]);
cx.assert_neovim_compatible("Test teˇst-test test", ["d", "shift-w"])
.await;
cx.simulate("d shift-w", "Test teˇst-test test")
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_next_word_end(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "e"]);
// cx.assert("Teˇst Test").await;
// cx.assert("Tˇest test").await;
cx.assert(indoc! {"
Test teˇst
test"})
.await;
cx.assert(indoc! {"
Test tesˇt
test"})
.await;
cx.assert_exempted(
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate("d e", "Teˇst Test\n").await.assert_matches();
cx.simulate("d e", "Tˇest test\n").await.assert_matches();
cx.simulate(
"d e",
indoc! {"
Test test
ˇ
Test teˇst
test"},
ExemptionFeatures::OperatorLastNewlineRemains,
)
.await;
.await
.assert_matches();
cx.simulate(
"d e",
indoc! {"
Test tesˇt
test"},
)
.await
.assert_matches();
let mut cx = cx.binding(["d", "shift-e"]);
cx.assert("Test teˇst-test test").await;
cx.simulate("d e", "Test teˇst-test test")
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_b(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "b"]);
cx.assert("Teˇst Test").await;
cx.assert("Test ˇtest").await;
cx.assert("Test1 test2 ˇtest3").await;
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate("d b", "Teˇst Test").await.assert_matches();
cx.simulate("d b", "Test ˇtest").await.assert_matches();
cx.simulate("d b", "Test1 test2 ˇtest3")
.await
.assert_matches();
cx.simulate(
"d b",
indoc! {"
Test test
ˇtest"})
.await;
cx.assert(indoc! {"
ˇtest"},
)
.await
.assert_matches();
cx.simulate(
"d b",
indoc! {"
Test test
ˇ
test"})
.await;
test"},
)
.await
.assert_matches();
let mut cx = cx.binding(["d", "shift-b"]);
cx.assert("Test test-test ˇtest").await;
cx.simulate("d shift-b", "Test test-test ˇtest")
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_end_of_line(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "$"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate(
"d $",
indoc! {"
The qˇuick
brown fox"})
.await;
cx.assert(indoc! {"
brown fox"},
)
.await
.assert_matches();
cx.simulate(
"d $",
indoc! {"
The quick
ˇ
brown fox"})
.await;
brown fox"},
)
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_0(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "0"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate(
"d 0",
indoc! {"
The qˇuick
brown fox"})
.await;
cx.assert(indoc! {"
brown fox"},
)
.await
.assert_matches();
cx.simulate(
"d 0",
indoc! {"
The quick
ˇ
brown fox"})
.await;
brown fox"},
)
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_k(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "k"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate(
"d k",
indoc! {"
The quick
brown ˇfox
jumps over"})
.await;
cx.assert(indoc! {"
jumps over"},
)
.await
.assert_matches();
cx.simulate(
"d k",
indoc! {"
The quick
brown fox
jumps ˇover"})
.await;
cx.assert(indoc! {"
jumps ˇover"},
)
.await
.assert_matches();
cx.simulate(
"d k",
indoc! {"
The qˇuick
brown fox
jumps over"})
.await;
cx.assert(indoc! {"
jumps over"},
)
.await
.assert_matches();
cx.simulate(
"d k",
indoc! {"
ˇbrown fox
jumps over"})
.await;
jumps over"},
)
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_j(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["d", "j"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate(
"d j",
indoc! {"
The quick
brown ˇfox
jumps over"})
.await;
cx.assert(indoc! {"
jumps over"},
)
.await
.assert_matches();
cx.simulate(
"d j",
indoc! {"
The quick
brown fox
jumps ˇover"})
.await;
cx.assert(indoc! {"
jumps ˇover"},
)
.await
.assert_matches();
cx.simulate(
"d j",
indoc! {"
The qˇuick
brown fox
jumps over"})
.await;
cx.assert(indoc! {"
jumps over"},
)
.await
.assert_matches();
cx.simulate(
"d j",
indoc! {"
The quick
brown fox
ˇ"})
.await;
ˇ"},
)
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_end_of_document(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
cx.simulate(
"d shift-g",
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"},
["d", "shift-g"],
)
.await;
cx.assert_neovim_compatible(
.await
.assert_matches();
cx.simulate(
"d shift-g",
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"},
["d", "shift-g"],
)
.await;
cx.assert_neovim_compatible(
.await
.assert_matches();
cx.simulate(
"d shift-g",
indoc! {"
The quick
brown fox
jumps over
the lˇazy"},
["d", "shift-g"],
)
.await;
cx.assert_neovim_compatible(
.await
.assert_matches();
cx.simulate(
"d shift-g",
indoc! {"
The quick
brown fox
jumps over
ˇ"},
["d", "shift-g"],
)
.await;
.await
.assert_matches();
}
#[gpui::test]
async fn test_delete_gg(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx)
.await
.binding(["d", "g", "g"]);
cx.assert_neovim_compatible(
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.simulate(
"d g g",
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"},
["d", "g", "g"],
)
.await;
cx.assert_neovim_compatible(
.await
.assert_matches();
cx.simulate(
"d g g",
indoc! {"
The quick
brown fox
jumps over
the lˇazy"},
["d", "g", "g"],
)
.await;
cx.assert_neovim_compatible(
.await
.assert_matches();
cx.simulate(
"d g g",
indoc! {"
The qˇuick
brown fox
jumps over
the lazy"},
["d", "g", "g"],
)
.await;
cx.assert_neovim_compatible(
.await
.assert_matches();
cx.simulate(
"d g g",
indoc! {"
ˇ
brown fox
jumps over
the lazy"},
["d", "g", "g"],
)
.await;
.await
.assert_matches();
}
#[gpui::test]
@ -446,7 +524,7 @@ mod test {
);
// Canceling operator twice reverts to normal mode with no active operator
cx.simulate_keystrokes(["d", "escape", "k"]);
cx.simulate_keystrokes("d escape k");
assert_eq!(cx.active_operator(), None);
assert_eq!(cx.mode(), Mode::Normal);
cx.assert_editor_state(indoc! {"
@ -467,7 +545,7 @@ mod test {
);
// Canceling operator twice reverts to normal mode with no active operator
cx.simulate_keystrokes(["d", "y"]);
cx.simulate_keystrokes("d y");
assert_eq!(cx.active_operator(), None);
assert_eq!(cx.mode(), Mode::Normal);
}
@ -480,20 +558,18 @@ mod test {
fox jumps over
the lazy dog"})
.await;
cx.simulate_shared_keystrokes(["d", "2", "d"]).await;
cx.assert_shared_state(indoc! {"
the ˇlazy dog"})
.await;
cx.simulate_shared_keystrokes("d 2 d").await;
cx.shared_state().await.assert_eq(indoc! {"
the ˇlazy dog"});
cx.set_shared_state(indoc! {"
The ˇquick brown
fox jumps over
the lazy dog"})
.await;
cx.simulate_shared_keystrokes(["2", "d", "d"]).await;
cx.assert_shared_state(indoc! {"
the ˇlazy dog"})
.await;
cx.simulate_shared_keystrokes("2 d d").await;
cx.shared_state().await.assert_eq(indoc! {"
the ˇlazy dog"});
cx.set_shared_state(indoc! {"
The ˇquick brown
@ -502,16 +578,15 @@ mod test {
a star, and
the lazy dog"})
.await;
cx.simulate_shared_keystrokes(["2", "d", "2", "d"]).await;
cx.assert_shared_state(indoc! {"
the ˇlazy dog"})
.await;
cx.simulate_shared_keystrokes("2 d 2 d").await;
cx.shared_state().await.assert_eq(indoc! {"
the ˇlazy dog"});
}
#[gpui::test]
async fn test_delete_to_adjacent_character(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible("ˇax", ["d", "t", "x"]).await;
cx.assert_neovim_compatible("aˇx", ["d", "t", "x"]).await;
cx.simulate("d t x", "ˇax").await.assert_matches();
cx.simulate("d t x", "x").await.assert_matches();
}
}