aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser.rs77
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]