File: input.rs

package info (click to toggle)
rust-tui-textarea 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 572 kB
  • sloc: makefile: 2
file content (82 lines) | stat: -rw-r--r-- 1,906 bytes parent folder | download | duplicates (2)
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(), ["๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"]);
}