use reovim_testing::{IntegrationTest, StepTest};
#[tokio::test]
async fn test_diw_delete_inner_word() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("hello world test")
.with_cursor_at(0, 7) .send_keys("diw")
.run()
.await;
result.assert_buffer_eq("hello test");
}
#[tokio::test]
async fn test_daw_delete_a_word() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("hello world test")
.with_cursor_at(0, 6) .send_keys("daw")
.run()
.await;
result.assert_buffer_eq("hello test");
}
#[tokio::test]
async fn test_di_double_quote_delete_inside() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer(r#"say "hello" please"#)
.with_cursor_at(0, 5) .send_keys("di\"")
.run()
.await;
result.assert_buffer_eq(r#"say "" please"#);
}
#[tokio::test]
async fn test_ci_brace_change_inside() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("fn() { old }")
.with_cursor_at(0, 7) .send_keys("ci{new<Esc>")
.run()
.await;
result.assert_buffer_eq("fn() {new}");
}
#[tokio::test]
async fn test_di_big_word() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("hello foo.bar test")
.with_cursor_at(0, 7) .send_keys("diW")
.run()
.await;
result.assert_buffer_eq("hello test");
}
#[tokio::test]
async fn test_da_big_word() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("hello foo.bar test")
.with_cursor_at(0, 7) .send_keys("daW")
.run()
.await;
result.assert_buffer_eq("hello test");
}
#[tokio::test]
async fn test_da_double_quote() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer(r#"say "hello" please"#)
.with_cursor_at(0, 5) .send_keys("da\"")
.run()
.await;
result.assert_buffer_eq("say please");
}
#[tokio::test]
async fn test_di_single_quote() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("say 'hello' please")
.with_cursor_at(0, 5) .send_keys("di'")
.run()
.await;
result.assert_buffer_eq("say '' please");
}
#[tokio::test]
async fn test_da_single_quote() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("say 'hello' please")
.with_cursor_at(0, 5) .send_keys("da'")
.run()
.await;
result.assert_buffer_eq("say please");
}
#[tokio::test]
async fn test_di_backtick() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("say `hello` please")
.with_cursor_at(0, 5) .send_keys("di`")
.run()
.await;
result.assert_buffer_eq("say `` please");
}
#[tokio::test]
async fn test_di_paren() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("fn(arg1, arg2)")
.with_cursor_at(0, 4) .send_keys("di(")
.run()
.await;
result.assert_buffer_eq("fn()");
}
#[tokio::test]
async fn test_da_paren() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("fn(arg1, arg2) end")
.with_cursor_at(0, 4) .send_keys("da(")
.run()
.await;
result.assert_buffer_eq("fn end");
}
#[tokio::test]
async fn test_di_bracket() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("arr[1, 2, 3]")
.with_cursor_at(0, 5) .send_keys("di[")
.run()
.await;
result.assert_buffer_eq("arr[]");
}
#[tokio::test]
async fn test_da_bracket() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("arr[1, 2, 3] end")
.with_cursor_at(0, 5) .send_keys("da[")
.run()
.await;
result.assert_buffer_eq("arr end");
}
#[tokio::test]
async fn test_di_brace() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("fn() { body }")
.with_cursor_at(0, 7) .send_keys("di{")
.run()
.await;
result.assert_buffer_eq("fn() {}");
}
#[tokio::test]
async fn test_da_brace() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("fn() { body } end")
.with_cursor_at(0, 7) .send_keys("da{")
.run()
.await;
result.assert_buffer_eq("fn() end");
}
#[tokio::test]
async fn test_di_angle() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("<div>content</div>")
.with_cursor_at(0, 1) .send_keys("di<lt>")
.run()
.await;
result.assert_buffer_eq("<>content</div>");
}
#[tokio::test]
async fn test_da_angle() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("<div> rest")
.with_cursor_at(0, 1) .send_keys("da<lt>")
.run()
.await;
result.assert_buffer_eq(" rest");
}
#[tokio::test]
async fn test_dip_paragraph() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("line1\nline2\n\nline3")
.send_keys("dip")
.run()
.await;
result.assert_buffer_contains("line3");
}
#[tokio::test]
async fn test_dap_paragraph() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("line1\nline2\n\nline3")
.send_keys("dap")
.run()
.await;
result.assert_buffer_eq("line3");
}
#[tokio::test]
async fn test_ciw_change_word() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("old word here")
.with_cursor_at(0, 4) .send_keys("ciwnew<Esc>")
.run()
.await;
result.assert_buffer_eq("old new here");
}
#[tokio::test]
async fn test_ci_double_quote() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer(r#"say "old" please"#)
.with_cursor_at(0, 5) .send_keys("ci\"new<Esc>")
.run()
.await;
result.assert_buffer_eq(r#"say "new" please"#);
}
#[tokio::test]
async fn test_ci_paren() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("fn(old)")
.with_cursor_at(0, 3) .send_keys("ci(x<Esc>")
.run()
.await;
result.assert_buffer_eq("fn(x)");
}
#[tokio::test]
async fn test_ci_bracket() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("a[old]")
.with_cursor_at(0, 2) .send_keys("ci[x<Esc>")
.run()
.await;
result.assert_buffer_eq("a[x]");
}
#[tokio::test]
async fn test_yiw_paste() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer("hello world")
.send_keys("yiw$p")
.run()
.await;
result.assert_buffer_contains("hello");
let content = &result.buffer_content;
assert!(
content.matches("hello").count() >= 2,
"Expected 'hello' to appear at least twice after yiw$p, got: {content}"
);
}
#[tokio::test]
async fn test_yi_quote_paste() {
let result = IntegrationTest::with_modules(&["textobjects"])
.await
.with_buffer(r#"say "hi" end"#)
.with_cursor_at(0, 5) .send_keys("yi\"$p")
.run()
.await;
result.assert_buffer_contains("hi");
}
#[tokio::test]
async fn test_delete_textobj_mode_transition() {
let trace = StepTest::with_modules(&["textobjects"])
.await
.with_buffer("hello world test")
.with_cursor_at(0, 6)
.step("d")
.expect_mode_contains("delete")
.step("iw")
.expect_buffer("hello test")
.run()
.await;
trace.assert_ok();
}
#[tokio::test]
async fn test_change_textobj_enters_insert() {
let trace = StepTest::with_modules(&["textobjects"])
.await
.with_buffer("hello world test")
.with_cursor_at(0, 6)
.step("c")
.expect_mode_contains("change")
.step("iw")
.expect_mode_contains("insert")
.run()
.await;
trace.assert_ok();
}