Skip to content

Commit

Permalink
add sanity test for all combination of key inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Nov 12, 2023
1 parent 18610dc commit cb868a1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ mod tests {

#[test]
#[rustfmt::skip]
fn test_line_display_text() {
fn line_display_text() {
assert_eq!(&build( "", 0, None), "");
assert_eq!(&build( "", 4, None), "");
assert_eq!(&build( "", 8, None), "");
Expand Down
75 changes: 75 additions & 0 deletions tests/input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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,
] {
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.input_without_shortcuts(input);
}
}

#[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(), ["👨‍👩‍👧‍👦"]);
}

0 comments on commit cb868a1

Please sign in to comment.