2024-01-22 04:40:43 +08:00
|
|
|
use crate::input::{input_mappings, Inputter, DEFAULT_BIND_MODE};
|
|
|
|
use crate::input_common::{CharEvent, ReadlineCmd};
|
2024-03-30 23:10:12 +08:00
|
|
|
use crate::key::Key;
|
2024-01-22 04:40:43 +08:00
|
|
|
use crate::parser::Parser;
|
|
|
|
use crate::tests::prelude::*;
|
|
|
|
use crate::wchar::prelude::*;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[serial]
|
|
|
|
fn test_input() {
|
2024-03-24 18:55:03 +08:00
|
|
|
let _cleanup = test_init();
|
2024-01-22 04:40:43 +08:00
|
|
|
use crate::env::EnvStack;
|
|
|
|
let parser = Parser::new(Arc::pin(EnvStack::new()), false);
|
|
|
|
let mut input = Inputter::new(parser, libc::STDIN_FILENO);
|
|
|
|
// Ensure sequences are order independent. Here we add two bindings where the first is a prefix
|
|
|
|
// of the second, and then emit the second key list. The second binding should be invoked, not
|
|
|
|
// the first!
|
2024-03-30 23:10:12 +08:00
|
|
|
let prefix_binding: Vec<Key> = "qqqqqqqa".chars().map(Key::from_raw).collect();
|
|
|
|
let mut desired_binding = prefix_binding.clone();
|
|
|
|
desired_binding.push(Key::from_raw('a'));
|
2024-01-22 04:40:43 +08:00
|
|
|
|
|
|
|
let default_mode = || DEFAULT_BIND_MODE.to_owned();
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut input_mapping = input_mappings();
|
|
|
|
input_mapping.add1(
|
|
|
|
prefix_binding,
|
2024-03-30 23:10:12 +08:00
|
|
|
None,
|
2024-01-22 04:40:43 +08:00
|
|
|
WString::from_str("up-line"),
|
|
|
|
default_mode(),
|
2024-01-22 05:41:48 +08:00
|
|
|
None,
|
2024-01-22 04:40:43 +08:00
|
|
|
true,
|
|
|
|
);
|
|
|
|
input_mapping.add1(
|
|
|
|
desired_binding.clone(),
|
2024-03-30 23:10:12 +08:00
|
|
|
None,
|
2024-01-22 04:40:43 +08:00
|
|
|
WString::from_str("down-line"),
|
|
|
|
default_mode(),
|
2024-01-22 05:41:48 +08:00
|
|
|
None,
|
2024-01-22 04:40:43 +08:00
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the desired binding to the queue.
|
2024-03-30 23:10:12 +08:00
|
|
|
for c in desired_binding {
|
|
|
|
input.queue_char(CharEvent::from_key(c));
|
2024-01-22 04:40:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now test.
|
2024-03-02 14:58:01 +08:00
|
|
|
let evt = input.read_char();
|
2024-01-22 04:40:43 +08:00
|
|
|
if !evt.is_readline() {
|
|
|
|
panic!("Event is not a readline");
|
|
|
|
} else if evt.get_readline() != ReadlineCmd::DownLine {
|
|
|
|
panic!("Expected to read char down_line");
|
|
|
|
}
|
|
|
|
}
|