diff options
| author | Teddy Wing | 2018-09-29 17:44:46 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-09-29 17:44:46 +0200 |
| commit | d73107314398e9aeb4540d96854d58728b874dbe (patch) | |
| tree | 0b38711ba2cc656c2c6f509773f4c0a63006353b /src | |
| parent | cf4736db68e9d797f489c87bf3c5b06913010e36 (diff) | |
| download | dome-key-map-d73107314398e9aeb4540d96854d58728b874dbe.tar.bz2 | |
Start filling new action parser tests
* Some stub ideas for test text
* Fill in the test for special keys
* Add some convenience methods to more easily create the expected test
result objects
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser.rs | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/parser.rs b/src/parser.rs index 50b15b3..21132b1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -39,6 +39,14 @@ impl PartialEq for Character { } } +impl Character { + fn new(ch: char) -> Self { + Character( + autopilot::key::Character(ch) + ) + } +} + #[derive(Debug)] struct KeyCode(autopilot::key::Code); @@ -48,6 +56,14 @@ impl PartialEq for KeyCode { } } +impl KeyCode { + fn new(code: autopilot::key::KeyCode) -> Self { + KeyCode( + autopilot::key::Code(code) + ) + } +} + #[derive(Debug, PartialEq)] enum KeyboardKey { Character(Character), @@ -57,7 +73,16 @@ enum KeyboardKey { #[derive(Debug, PartialEq)] struct KeyboardKeyWithModifiers { key: KeyboardKey, - flags: Vec<Flag>, + flags: Option<Vec<Flag>>, +} + +impl KeyboardKeyWithModifiers { + fn new(key: KeyboardKey, modifiers: Option<Vec<Flag>>) -> Self { + KeyboardKeyWithModifiers { + key: key, + flags: modifiers, + } + } } #[derive(Debug, PartialEq)] @@ -374,14 +399,63 @@ mod tests { #[test] fn action_parses_map_with_simple_characters() { + // "type hello!" } #[test] fn action_parses_map_with_modifier() { + // "one<C-l>two<D-s>three" + } + #[test] + fn action_parses_map_with_multiple_modifiers() { + // "one<C-l>two<D-s>three" } #[test] fn action_parses_map_with_special_key() { + let text = "ready<F2><space>go"; + + let expected = Action::Map(vec![ + KeyboardKeyWithModifiers::new( + KeyboardKey::Character(Character::new('r')), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::Character(Character::new('e')), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::Character(Character::new('a')), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::Character(Character::new('d')), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::Character(Character::new('y')), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::KeyCode(KeyCode::new(autopilot::key::KeyCode::F2)), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::KeyCode(KeyCode::new(autopilot::key::KeyCode::Space)), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::Character(Character::new('g')), + None, + ), + KeyboardKeyWithModifiers::new( + KeyboardKey::Character(Character::new('o')), + None, + ), + ]); + let result = action_map().parse(text).map(|t| t.0); + + assert_eq!(result, Ok(expected)); } #[test] @@ -394,6 +468,7 @@ mod tests { #[test] fn action_parses_command_to_vec_of_words() { + let text = "/usr/bin/say 'hello'"; } #[test] |
