use super::*;
#[test]
fn alt_arrows_are_word_motion() {
assert_eq!(
word_intent(Key::Left, Mods::ALT),
Some(WordIntent::Left),
"Alt+Left"
);
assert_eq!(word_intent(Key::Right, Mods::ALT), Some(WordIntent::Right));
}
#[test]
fn ctrl_arrows_are_word_motion() {
assert_eq!(word_intent(Key::Left, Mods::CTRL), Some(WordIntent::Left));
assert_eq!(word_intent(Key::Right, Mods::CTRL), Some(WordIntent::Right));
}
#[test]
fn readline_letters_are_word_motion() {
assert_eq!(
word_intent(Key::Char('b'), Mods::ALT),
Some(WordIntent::Left)
);
assert_eq!(
word_intent(Key::Char('f'), Mods::ALT),
Some(WordIntent::Right)
);
}
#[test]
fn shift_extends_rather_than_disqualifying() {
assert_eq!(
word_intent(Key::Left, Mods::ALT | Mods::SHIFT),
Some(WordIntent::Left)
);
assert_eq!(
word_intent(Key::Right, Mods::CTRL | Mods::SHIFT),
Some(WordIntent::Right)
);
}
#[test]
fn delete_word_family() {
assert_eq!(
word_intent(Key::Backspace, Mods::ALT),
Some(WordIntent::DeleteBack)
);
assert_eq!(
word_intent(Key::Char('w'), Mods::CTRL),
Some(WordIntent::DeleteBack)
);
assert_eq!(
word_intent(Key::Char('d'), Mods::ALT),
Some(WordIntent::DeleteForward)
);
assert_eq!(
word_intent(Key::Delete, Mods::CTRL),
Some(WordIntent::DeleteForward)
);
}
#[test]
fn bare_keys_are_never_word_gestures() {
for key in [
Key::Left,
Key::Right,
Key::Backspace,
Key::Delete,
Key::Char('b'),
Key::Char('f'),
Key::Char('d'),
Key::Char('w'),
] {
assert_eq!(word_intent(key, Mods::NONE), None, "{key:?} unmodified");
assert_eq!(
word_intent(key, Mods::SHIFT),
None,
"{key:?} with Shift alone"
);
}
}
#[test]
fn letters_do_not_answer_to_the_other_modifier() {
assert_eq!(word_intent(Key::Char('b'), Mods::CTRL), None);
assert_eq!(word_intent(Key::Char('f'), Mods::CTRL), None);
assert_eq!(word_intent(Key::Char('d'), Mods::CTRL), None);
assert_eq!(word_intent(Key::Char('w'), Mods::ALT), None);
assert_eq!(word_intent(Key::Char('b'), Mods::ALT | Mods::CTRL), None);
assert_eq!(word_intent(Key::Char('w'), Mods::ALT | Mods::CTRL), None);
assert_eq!(word_intent(Key::Left, Mods::ALT | Mods::CTRL), None);
assert_eq!(word_intent(Key::Backspace, Mods::ALT | Mods::CTRL), None);
}
#[test]
fn unrelated_chords_fall_through() {
for ch in ['a', 'c', 'e', 'l', 'q', 't', 'x', 'z'] {
assert_eq!(word_intent(Key::Char(ch), Mods::ALT), None, "Alt+{ch}");
assert_eq!(word_intent(Key::Char(ch), Mods::CTRL), None, "Ctrl+{ch}");
}
}