use hjkl_engine::Editor;
use hjkl_engine::types::{DefaultHost, Options};
use hjkl_vim::VimEditorExt;
use hjkl_vim::vim::Operator;
fn ed_with(content: &str) -> Editor<hjkl_buffer::View, DefaultHost> {
let mut e = hjkl_vim::vim_editor(
hjkl_buffer::View::new(),
DefaultHost::new(),
Options::default(),
);
e.set_content(content);
e
}
fn line0(e: &Editor<hjkl_buffer::View, DefaultHost>) -> String {
hjkl_buffer::rope_line_str(&e.buffer().rope(), 0)
}
#[test]
fn diw_ascii_word_baseline() {
let mut e = ed_with("hello world");
e.jump_cursor(0, 6);
e.apply_op_text_obj(Operator::Delete, 'w', true, 1);
assert_eq!(line0(&e), "hello ");
}
#[test]
fn diw_multibyte_word() {
let mut e = ed_with("héllo wörld");
e.jump_cursor(0, 6); e.apply_op_text_obj(Operator::Delete, 'w', true, 1);
assert_eq!(line0(&e), "héllo ");
}
#[test]
fn daw_multibyte_absorbs_leading_ws() {
let mut e = ed_with("héllo wörld");
e.jump_cursor(0, 6);
e.apply_op_text_obj(Operator::Delete, 'w', false, 1);
assert_eq!(line0(&e), "héllo");
}
#[test]
fn di_quote_multibyte_second_pair() {
let mut e = ed_with("\"日日日\" \"x\"");
e.jump_cursor(0, 7); e.apply_op_text_obj(Operator::Delete, '"', true, 1);
assert_eq!(line0(&e), "\"日日日\" \"\"");
}
#[test]
fn di_quote_multibyte_content() {
let mut e = ed_with("\"日日日\" \"x\"");
e.jump_cursor(0, 2); e.apply_op_text_obj(Operator::Delete, '"', true, 1);
assert_eq!(line0(&e), "\"\" \"x\"");
}
#[test]
fn count_prefix_digits_clamp_at_vim_max() {
let mut e = ed_with("one\ntwo\nthree");
for _ in 0..40 {
e.accumulate_count_digit(9);
}
assert_eq!(e.count(), hjkl_vim::vim::MAX_COUNT);
assert_eq!(e.count(), 999_999_999);
let count = e.take_count();
assert_eq!(count, 999_999_999);
e.goto_percent(count);
}
#[test]
fn set_count_clamps_at_vim_max() {
let mut e = ed_with("one\ntwo\nthree");
e.set_count(usize::MAX);
assert_eq!(e.count(), 999_999_999);
}
#[test]
fn pathological_count_apply_loop_is_bounded() {
let mut e = ed_with("one two three");
for _ in 0..20 {
e.accumulate_count_digit(9);
}
let count = e.take_count();
assert_eq!(count, 999_999_999);
e.apply_op_motion(Operator::Delete, 'w', count);
assert_eq!(line0(&e), "");
}
#[test]
fn folded_operator_count_product_is_bounded() {
let mut e = ed_with("one two three");
e.apply_op_motion(Operator::Delete, 'w', usize::MAX);
assert_eq!(line0(&e), "");
}