space commands here we go again
This commit is contained in:
39
client/tests/input/engine_leader_e2e.rs
Normal file
39
client/tests/input/engine_leader_e2e.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use client::config::binds::config::Config;
|
||||
use client::input::engine::{InputEngine, InputContext, InputOutcome};
|
||||
use client::modes::handlers::mode_manager::AppMode;
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
|
||||
fn ctx() -> InputContext {
|
||||
InputContext {
|
||||
app_mode: AppMode::General,
|
||||
overlay_active: false,
|
||||
allow_navigation_capture: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn key(c: char) -> KeyEvent {
|
||||
KeyEvent::new(KeyCode::Char(c), KeyModifiers::empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn engine_collects_space_b_r() {
|
||||
let toml_str = r#"
|
||||
[keybindings]
|
||||
revert = ["space+b+r"]
|
||||
"#;
|
||||
let config: Config = toml::from_str(toml_str).unwrap();
|
||||
|
||||
let mut eng = InputEngine::new(400, 5_000);
|
||||
|
||||
// space -> Pending (leader started)
|
||||
let out1 = eng.process_key(key(' '), &ctx(), &config);
|
||||
assert!(matches!(out1, InputOutcome::Pending));
|
||||
|
||||
// b -> Pending (prefix)
|
||||
let out2 = eng.process_key(key('b'), &ctx(), &config);
|
||||
assert!(matches!(out2, InputOutcome::Pending));
|
||||
|
||||
// r -> Action(revert)
|
||||
let out3 = eng.process_key(key('r'), &ctx(), &config);
|
||||
assert!(matches!(out3, InputOutcome::Action(_)));
|
||||
}
|
||||
25
client/tests/input/leader_sequences.rs
Normal file
25
client/tests/input/leader_sequences.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use client::config::binds::config::Config;
|
||||
use client::input::leader::leader_match_action;
|
||||
use client::config::binds::key_sequences::parse_binding;
|
||||
use crossterm::event::KeyCode;
|
||||
|
||||
#[test]
|
||||
fn test_space_b_d_binding() {
|
||||
// Minimal fake config TOML
|
||||
let toml_str = r#"
|
||||
[keybindings]
|
||||
close_buffer = ["space+b+d"]
|
||||
"#;
|
||||
let config: Config = toml::from_str(toml_str).unwrap();
|
||||
|
||||
let seq = vec![KeyCode::Char(' '), KeyCode::Char('b'), KeyCode::Char('d')];
|
||||
let action = leader_match_action(&config, &seq);
|
||||
assert_eq!(action, Some("close_buffer"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_space_b_r() {
|
||||
let seq = parse_binding("space+b+r");
|
||||
let codes: Vec<KeyCode> = seq.iter().map(|p| p.code).collect();
|
||||
assert_eq!(codes, vec![KeyCode::Char(' '), KeyCode::Char('b'), KeyCode::Char('r')]);
|
||||
}
|
||||
4
client/tests/input/mod.rs
Normal file
4
client/tests/input/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
// tests/input/mod.rs
|
||||
|
||||
pub mod engine_leader_e2e;
|
||||
pub mod leader_sequences;
|
||||
Reference in New Issue
Block a user