MCPcopy Create free account
hub / github.com/TyberiusPrime/KeyToKey / test_longtab

Function test_longtab

src/handlers/longtap.rs:83–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81
82 #[test]
83 fn test_longtab() {
84 struct Short();
85 struct Long();
86 impl Action for Short {
87 fn on_trigger(&mut self, output: &mut dyn USBKeyOut) {
88 output.send_keys(&[KeyCode::A]);
89 }
90 }
91 impl Action for Long {
92 fn on_trigger(&mut self, output: &mut dyn USBKeyOut) {
93 output.send_keys(&[KeyCode::B]);
94 }
95 }
96
97 let mut keyboard = Keyboard::new(KeyOutCatcher::new());
98 let timeout: u16 = 1000;
99 keyboard.add_handler(Box::new(LongTap::new(
100 UserKey::UK0,
101 Short {},
102 Long {},
103 timeout,
104 )));
105 keyboard.add_handler(Box::new(USBKeyboard::new()));
106
107 keyboard.add_keypress(UserKey::UK0, 0);
108 keyboard.handle_keys().unwrap();
109 check_output(&keyboard, &[&[]]);
110 keyboard.output.clear();
111
112 keyboard.add_keyrelease(UserKey::UK0, timeout - 1);
113 keyboard.handle_keys().unwrap();
114 dbg!(&keyboard.output.reports);
115 check_output(&keyboard, &[&[KeyCode::A], &[]]);
116 keyboard.output.clear();
117
118 keyboard.add_keypress(UserKey::UK0, 0);
119 keyboard.handle_keys().unwrap();
120 check_output(&keyboard, &[&[]]);
121 keyboard.output.clear();
122
123 keyboard.add_keyrelease(UserKey::UK0, timeout);
124 keyboard.handle_keys().unwrap();
125 dbg!(&keyboard.output.reports);
126 check_output(&keyboard, &[&[KeyCode::B], &[]]);
127 keyboard.output.clear();
128 }
129
130 #[test]
131 fn test_longtab_plus_mod() {

Callers

nothing calls this directly

Calls 6

check_outputFunction · 0.85
add_handlerMethod · 0.80
add_keypressMethod · 0.80
handle_keysMethod · 0.80
clearMethod · 0.80
add_keyreleaseMethod · 0.80

Tested by

no test coverage detected