1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
use tui_textarea::{Input, Key, TextArea};
// Sanity test for checking textarea does not crash against all combination of inputs
#[test]
fn test_input_all_combinations_sanity() {
use Key::*;
fn push_all_modifiers_combination(inputs: &mut Vec<Input>, key: Key) {
for ctrl in [true, false] {
for alt in [true, false] {
for shift in [true, false] {
inputs.push(Input {
key,
ctrl,
alt,
shift,
});
}
}
}
}
let mut inputs = vec![];
for c in ' '..='~' {
push_all_modifiers_combination(&mut inputs, Char(c));
}
for i in 0..=15 {
push_all_modifiers_combination(&mut inputs, F(i));
}
for k in [
Null,
Char('ใ'),
Char('๐ถ'),
Backspace,
Enter,
Left,
Right,
Up,
Down,
Tab,
Delete,
Home,
End,
PageUp,
PageDown,
Esc,
MouseScrollDown,
MouseScrollUp,
Copy,
Cut,
Paste,
] {
push_all_modifiers_combination(&mut inputs, k);
}
let mut t = TextArea::from(["abc", "def", "ghi", "jkl", "mno", "pqr"]);
for input in inputs {
t.input(input.clone());
t.undo();
t.redo();
t.input_without_shortcuts(input);
t.undo();
t.redo();
}
}
#[test]
fn test_insert_multi_code_unit_emoji() {
let mut t = TextArea::default();
for c in "๐จโ๐ฉโ๐งโ๐ฆ".chars() {
let input = Input {
key: Key::Char(c),
ctrl: false,
alt: false,
shift: false,
};
assert!(t.input(input), "{c:?}");
}
assert_eq!(t.lines(), ["๐จโ๐ฉโ๐งโ๐ฆ"]);
}
|