use revue::event::{Key, KeyEvent};
use revue::widget::autocomplete::Autocomplete;
#[test]
fn test_autocomplete_value_with_emoji_sets_correct_cursor() {
let a = Autocomplete::new().value("Hello π");
assert_eq!(a.get_value(), "Hello π");
}
#[test]
fn test_autocomplete_type_emoji_then_backspace_no_panic() {
let mut a = Autocomplete::new();
a.handle_key(KeyEvent::new(Key::Char('π')));
assert_eq!(a.get_value(), "π");
a.handle_key(KeyEvent::new(Key::Backspace));
assert_eq!(a.get_value(), "");
}
#[test]
fn test_autocomplete_type_cjk_then_backspace() {
let mut a = Autocomplete::new();
a.handle_key(KeyEvent::new(Key::Char('ν')));
a.handle_key(KeyEvent::new(Key::Char('κΈ')));
assert_eq!(a.get_value(), "νκΈ");
a.handle_key(KeyEvent::new(Key::Backspace));
assert_eq!(a.get_value(), "ν");
a.handle_key(KeyEvent::new(Key::Backspace));
assert_eq!(a.get_value(), "");
}
#[test]
fn test_autocomplete_delete_key_cjk() {
let mut a = Autocomplete::new();
a.handle_key(KeyEvent::new(Key::Char('κ°')));
a.handle_key(KeyEvent::new(Key::Char('λ')));
assert_eq!(a.get_value(), "κ°λ");
a.handle_key(KeyEvent::new(Key::Home));
a.handle_key(KeyEvent::new(Key::Delete));
assert_eq!(a.get_value(), "λ");
}
#[test]
fn test_autocomplete_arrow_keys_with_cjk() {
let mut a = Autocomplete::new();
a.handle_key(KeyEvent::new(Key::Char('A')));
a.handle_key(KeyEvent::new(Key::Char('ν')));
a.handle_key(KeyEvent::new(Key::Char('B')));
assert_eq!(a.get_value(), "AνB");
a.handle_key(KeyEvent::new(Key::Left));
a.handle_key(KeyEvent::new(Key::Left));
a.handle_key(KeyEvent::new(Key::Char('X')));
assert_eq!(a.get_value(), "AXνB");
}
#[test]
fn test_autocomplete_end_key_with_multibyte() {
let mut a = Autocomplete::new().value("μλ
π");
a.handle_key(KeyEvent::new(Key::Home));
a.handle_key(KeyEvent::new(Key::End));
a.handle_key(KeyEvent::new(Key::Char('!')));
assert_eq!(a.get_value(), "μλ
π!");
}