78 lines
2.0 KiB
Rust
78 lines
2.0 KiB
Rust
extern crate alloc;
|
|
|
|
use tui_orchestrator::input::{Action, Bindings, Key};
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
#[allow(dead_code)]
|
|
enum TestAction {
|
|
Quit,
|
|
Save,
|
|
Open,
|
|
}
|
|
|
|
impl Action for TestAction {}
|
|
|
|
#[test]
|
|
fn test_bindings_new() {
|
|
let _bindings: Bindings<TestAction> = Bindings::new();
|
|
}
|
|
|
|
#[test]
|
|
fn test_bindings_bind() {
|
|
let mut bindings: Bindings<TestAction> = Bindings::new();
|
|
bindings.bind(Key::char('q'), TestAction::Quit);
|
|
assert_eq!(bindings.get(&Key::char('q')), Some(&TestAction::Quit));
|
|
}
|
|
|
|
#[test]
|
|
fn test_bindings_get_not_found() {
|
|
let mut bindings: Bindings<TestAction> = Bindings::new();
|
|
bindings.bind(Key::char('q'), TestAction::Quit);
|
|
assert_eq!(bindings.get(&Key::char('x')), None);
|
|
}
|
|
|
|
#[test]
|
|
fn test_bindings_remove() {
|
|
let mut bindings: Bindings<TestAction> = Bindings::new();
|
|
bindings.bind(Key::char('q'), TestAction::Quit);
|
|
bindings.remove(&Key::char('q'));
|
|
assert_eq!(bindings.get(&Key::char('q')), None);
|
|
}
|
|
|
|
#[test]
|
|
fn test_bindings_is_empty() {
|
|
let mut bindings: Bindings<TestAction> = Bindings::new();
|
|
assert!(bindings.is_empty());
|
|
|
|
bindings.bind(Key::char('q'), TestAction::Quit);
|
|
assert!(!bindings.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn test_bindings_len() {
|
|
let mut bindings: Bindings<TestAction> = Bindings::new();
|
|
assert_eq!(bindings.len(), 0);
|
|
|
|
bindings.bind(Key::char('q'), TestAction::Quit);
|
|
assert_eq!(bindings.len(), 1);
|
|
|
|
bindings.bind(Key::char('s'), TestAction::Save);
|
|
assert_eq!(bindings.len(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn test_bindings_iter() {
|
|
let mut bindings: Bindings<TestAction> = Bindings::new();
|
|
bindings.bind(Key::char('q'), TestAction::Quit);
|
|
bindings.bind(Key::char('s'), TestAction::Save);
|
|
|
|
let actions: Vec<_> = bindings.iter().map(|(_, a)| *a).collect();
|
|
assert!(actions.contains(&TestAction::Quit));
|
|
assert!(actions.contains(&TestAction::Save));
|
|
}
|
|
|
|
#[test]
|
|
fn test_bindings_default() {
|
|
let _bindings: Bindings<TestAction> = Bindings::default();
|
|
}
|