Remove supported exception

(and refactor tests to be more linear)
This commit is contained in:
Conrad Irwin 2023-09-12 10:13:24 -06:00
parent 7daed1b2c3
commit dcaba9d9e7
3 changed files with 123 additions and 105 deletions

View File

@ -121,7 +121,7 @@ fn expand_changed_word_selection(
mod test {
use indoc::indoc;
use crate::test::{ExemptionFeatures, NeovimBackedTestContext};
use crate::test::NeovimBackedTestContext;
#[gpui::test]
async fn test_change_h(cx: &mut gpui::TestAppContext) {
@ -239,150 +239,178 @@ mod test {
#[gpui::test]
async fn test_change_0(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "0"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
indoc! {"
The qˇuick
brown fox"})
.await;
cx.assert(indoc! {"
brown fox"},
["c", "0"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
ˇ
brown fox"})
.await;
brown fox"},
["c", "0"],
)
.await;
}
#[gpui::test]
async fn test_change_k(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "k"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown ˇfox
jumps over"})
.await;
cx.assert(indoc! {"
jumps over"},
["c", "k"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
jumps ˇover"})
.await;
cx.assert_exempted(
jumps ˇover"},
["c", "k"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The qˇuick
brown fox
jumps over"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "k"],
)
.await;
cx.assert_exempted(
cx.assert_neovim_compatible(
indoc! {"
ˇ
brown fox
jumps over"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "k"],
)
.await;
}
#[gpui::test]
async fn test_change_j(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "j"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown ˇfox
jumps over"})
.await;
cx.assert_exempted(
jumps over"},
["c", "j"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
jumps ˇover"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "j"],
)
.await;
cx.assert(indoc! {"
cx.assert_neovim_compatible(
indoc! {"
The qˇuick
brown fox
jumps over"})
.await;
cx.assert_exempted(
jumps over"},
["c", "j"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
ˇ"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "j"],
)
.await;
}
#[gpui::test]
async fn test_change_end_of_document(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx)
.await
.binding(["c", "shift-g"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"})
.await;
cx.assert(indoc! {"
the lazy"},
["c", "shift-g"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"})
.await;
cx.assert_exempted(
the lazy"},
["c", "shift-g"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
jumps over
the lˇazy"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "shift-g"],
)
.await;
cx.assert_exempted(
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
jumps over
ˇ"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "shift-g"],
)
.await;
}
#[gpui::test]
async fn test_change_gg(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx)
.await
.binding(["c", "g", "g"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"})
.await;
cx.assert(indoc! {"
the lazy"},
["c", "g", "g"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
jumps over
the lˇazy"})
.await;
cx.assert_exempted(
the lˇazy"},
["c", "g", "g"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The qˇuick
brown fox
jumps over
the lazy"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "g", "g"],
)
.await;
cx.assert_exempted(
cx.assert_neovim_compatible(
indoc! {"
ˇ
brown fox
jumps over
the lazy"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["c", "g", "g"],
)
.await;
}
@ -427,27 +455,17 @@ mod test {
async fn test_repeated_cb(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.add_initial_state_exemptions(
indoc! {"
ˇThe quick brown
fox jumps-over
the lazy dog
"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
);
for count in 1..=5 {
cx.assert_binding_matches_all(
["c", &count.to_string(), "b"],
indoc! {"
ˇThe quˇickˇ browˇn
ˇ
ˇfox ˇjumpsˇ-ˇoˇver
ˇthe lazy dog
"},
)
.await;
for marked_text in cx.each_marked_position(indoc! {"
ˇThe quˇickˇ browˇn
ˇ
ˇfox ˇjumpsˇ-ˇoˇver
ˇthe lazy dog
"})
{
cx.assert_neovim_compatible(&marked_text, ["c", &count.to_string(), "b"])
.await;
}
}
}

View File

@ -278,37 +278,41 @@ mod test {
#[gpui::test]
async fn test_delete_end_of_document(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx)
.await
.binding(["d", "shift-g"]);
cx.assert(indoc! {"
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"})
.await;
cx.assert(indoc! {"
the lazy"},
["d", "shift-g"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brownˇ fox
jumps over
the lazy"})
.await;
cx.assert_exempted(
the lazy"},
["d", "shift-g"],
)
.await;
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
jumps over
the lˇazy"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["d", "shift-g"],
)
.await;
cx.assert_exempted(
cx.assert_neovim_compatible(
indoc! {"
The quick
brown fox
jumps over
ˇ"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
["d", "shift-g"],
)
.await;
}
@ -318,34 +322,32 @@ mod test {
let mut cx = NeovimBackedTestContext::new(cx)
.await
.binding(["d", "g", "g"]);
cx.assert(indoc! {"
cx.assert_neovim_compatible(indoc! {"
The quick
brownˇ fox
jumps over
the lazy"})
the lazy"}, ["d", "g", "g"])
.await;
cx.assert(indoc! {"
cx.assert_neovim_compatible(indoc! {"
The quick
brown fox
jumps over
the lˇazy"})
the lˇazy"}, ["d", "g", "g"])
.await;
cx.assert_exempted(
cx.assert_neovim_compatible(
indoc! {"
The qˇuick
brown fox
jumps over
the lazy"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
the lazy"},["d", "g", "g"]
)
.await;
cx.assert_exempted(
cx.assert_neovim_compatible(
indoc! {"
ˇ
brown fox
jumps over
the lazy"},
ExemptionFeatures::OperatorAbortsOnFailedMotion,
the lazy"},["d", "g", "g"]
)
.await;
}

View File

@ -13,10 +13,7 @@ use util::test::{generate_marked_text, marked_text_offsets};
use super::{neovim_connection::NeovimConnection, NeovimBackedBindingTestContext, VimTestContext};
use crate::state::Mode;
pub const SUPPORTED_FEATURES: &[ExemptionFeatures] = &[
ExemptionFeatures::DeletionOnEmptyLine,
ExemptionFeatures::OperatorAbortsOnFailedMotion,
];
pub const SUPPORTED_FEATURES: &[ExemptionFeatures] = &[ExemptionFeatures::DeletionOnEmptyLine];
/// Enum representing features we have tests for but which don't work, yet. Used
/// to add exemptions and automatically
@ -25,8 +22,6 @@ pub enum ExemptionFeatures {
// MOTIONS
// Deletions on empty lines miss some newlines
DeletionOnEmptyLine,
// When a motion fails, it should should not apply linewise operations
OperatorAbortsOnFailedMotion,
// When an operator completes at the end of the file, an extra newline is left
OperatorLastNewlineRemains,
// Deleting a word on an empty line doesn't remove the newline
@ -389,6 +384,9 @@ impl<'a> DerefMut for NeovimBackedTestContext<'a> {
}
}
// a common mistake in tests is to call set_shared_state when
// you mean asswert_shared_state. This notices that and lets
// you know.
impl<'a> Drop for NeovimBackedTestContext<'a> {
fn drop(&mut self) {
if self.is_dirty {