Tests: emacs
diff --git a/src/test/common.rs b/src/test/common.rs
index 2950bd9..cddeb91 100644
--- a/src/test/common.rs
+++ b/src/test/common.rs
@@ -141,7 +141,7 @@
}
#[test]
-fn undo() {
+fn ctrl__() {
assert_cursor(
("Hello, ", "world"),
&[KeyPress::Ctrl('W'), KeyPress::Ctrl('_'), KeyPress::Enter],
diff --git a/src/test/emacs.rs b/src/test/emacs.rs
new file mode 100644
index 0000000..e0b8b6a
--- /dev/null
+++ b/src/test/emacs.rs
@@ -0,0 +1,213 @@
+//! Emacs specific key bindings
+use super::{assert_cursor, assert_history};
+use consts::KeyPress;
+
+#[test]
+fn ctrl_a() {
+ assert_cursor(
+ ("Hi", ""),
+ &[KeyPress::Ctrl('A'), KeyPress::Enter],
+ ("", "Hi"),
+ );
+}
+
+#[test]
+fn ctrl_e() {
+ assert_cursor(
+ ("", "Hi"),
+ &[KeyPress::Ctrl('E'), KeyPress::Enter],
+ ("Hi", ""),
+ );
+}
+
+#[test]
+fn ctrl_b() {
+ assert_cursor(
+ ("Hi", ""),
+ &[KeyPress::Ctrl('B'), KeyPress::Enter],
+ ("H", "i"),
+ );
+}
+
+#[test]
+fn ctrl_f() {
+ assert_cursor(
+ ("", "Hi"),
+ &[KeyPress::Ctrl('F'), KeyPress::Enter],
+ ("H", "i"),
+ );
+}
+
+#[test]
+fn ctrl_h() {
+ assert_cursor(
+ ("Hi", ""),
+ &[KeyPress::Ctrl('H'), KeyPress::Enter],
+ ("H", ""),
+ );
+}
+
+#[test]
+fn backspace() {
+ assert_cursor(("", ""), &[KeyPress::Backspace, KeyPress::Enter], ("", ""));
+ assert_cursor(
+ ("Hi", ""),
+ &[KeyPress::Backspace, KeyPress::Enter],
+ ("H", ""),
+ );
+ assert_cursor(
+ ("", "Hi"),
+ &[KeyPress::Backspace, KeyPress::Enter],
+ ("", "Hi"),
+ );
+}
+
+#[test]
+fn ctrl_k() {
+ assert_cursor(
+ ("Hi", ""),
+ &[KeyPress::Ctrl('K'), KeyPress::Enter],
+ ("Hi", ""),
+ );
+ assert_cursor(
+ ("", "Hi"),
+ &[KeyPress::Ctrl('K'), KeyPress::Enter],
+ ("", ""),
+ );
+ assert_cursor(
+ ("B", "ye"),
+ &[KeyPress::Ctrl('K'), KeyPress::Enter],
+ ("B", ""),
+ );
+}
+
+#[test]
+fn ctrl_n() {
+ assert_history(
+ &["line1", "line2"],
+ &[
+ KeyPress::Ctrl('P'),
+ KeyPress::Ctrl('P'),
+ KeyPress::Ctrl('N'),
+ KeyPress::Enter,
+ ],
+ ("line2", ""),
+ );
+}
+
+#[test]
+fn ctrl_p() {
+ assert_history(
+ &["line1"],
+ &[KeyPress::Ctrl('P'), KeyPress::Enter],
+ ("line1", ""),
+ );
+}
+
+#[test]
+fn ctrl_x_ctrl_u() {
+ assert_cursor(
+ ("Hello, ", "world"),
+ &[
+ KeyPress::Ctrl('W'),
+ KeyPress::Ctrl('X'),
+ KeyPress::Ctrl('U'),
+ KeyPress::Enter,
+ ],
+ ("Hello, ", "world"),
+ );
+}
+
+#[test]
+fn meta_b() {
+ assert_cursor(
+ ("Hello, world!", ""),
+ &[KeyPress::Meta('B'), KeyPress::Enter],
+ ("Hello, ", "world!"),
+ );
+}
+
+#[test]
+fn meta_f() {
+ assert_cursor(
+ ("", "Hello, world!"),
+ &[KeyPress::Meta('F'), KeyPress::Enter],
+ ("Hello", ", world!"),
+ );
+}
+
+#[test]
+fn meta_c() {
+ assert_cursor(
+ ("hi", ""),
+ &[KeyPress::Meta('C'), KeyPress::Enter],
+ ("hi", ""),
+ );
+ assert_cursor(
+ ("", "hi"),
+ &[KeyPress::Meta('C'), KeyPress::Enter],
+ ("Hi", ""),
+ );
+}
+
+#[test]
+fn meta_l() {
+ assert_cursor(
+ ("Hi", ""),
+ &[KeyPress::Meta('L'), KeyPress::Enter],
+ ("Hi", ""),
+ );
+ assert_cursor(
+ ("", "HI"),
+ &[KeyPress::Meta('L'), KeyPress::Enter],
+ ("hi", ""),
+ );
+}
+
+#[test]
+fn meta_u() {
+ assert_cursor(
+ ("hi", ""),
+ &[KeyPress::Meta('U'), KeyPress::Enter],
+ ("hi", ""),
+ );
+ assert_cursor(
+ ("", "hi"),
+ &[KeyPress::Meta('U'), KeyPress::Enter],
+ ("HI", ""),
+ );
+}
+
+#[test]
+fn meta_d() {
+ assert_cursor(
+ ("Hello", ", world!"),
+ &[KeyPress::Meta('D'), KeyPress::Enter],
+ ("Hello", "!"),
+ );
+}
+
+#[test]
+fn meta_t() {
+ assert_cursor(
+ ("Hello", ", world!"),
+ &[KeyPress::Meta('T'), KeyPress::Enter],
+ ("world, Hello", "!"),
+ );
+}
+
+#[test]
+fn meta_y() {
+ assert_cursor(
+ ("Hello, world", "!"),
+ &[
+ KeyPress::Ctrl('W'),
+ KeyPress::Left,
+ KeyPress::Ctrl('W'),
+ KeyPress::Ctrl('Y'),
+ KeyPress::Meta('Y'),
+ KeyPress::Enter,
+ ],
+ ("world", " !"),
+ );
+}
diff --git a/src/test/history.rs b/src/test/history.rs
index c6e1e16..8eeccbf 100644
--- a/src/test/history.rs
+++ b/src/test/history.rs
@@ -1,18 +1,7 @@
//! History related commands tests
-use super::init_editor;
+use super::assert_history;
use consts::KeyPress;
-fn assert_history(entries: &[&str], keys: &[KeyPress], expected: (&str, &str)) {
- let mut editor = init_editor(keys);
- for entry in entries {
- editor.history.add(*entry);
- }
- let actual_line = editor.readline("").unwrap();
- assert_eq!(expected.0.to_owned() + expected.1, actual_line);
- // FIXME
- //assert_eq!(expected.0.len(), editor.term.cursor);
-}
-
#[test]
fn down_key() {
assert_history(&["line1"], &[KeyPress::Down, KeyPress::Enter], ("", ""));
diff --git a/src/test/mod.rs b/src/test/mod.rs
index 2b2e590..9555119 100644
--- a/src/test/mod.rs
+++ b/src/test/mod.rs
@@ -11,6 +11,7 @@
use tty::Sink;
mod common;
+mod emacs;
mod history;
fn init_editor(keys: &[KeyPress]) -> Editor<()> {
@@ -64,6 +65,17 @@
assert_eq!(expected.0.len(), editor.term.cursor);
}
+fn assert_history(entries: &[&str], keys: &[KeyPress], expected: (&str, &str)) {
+ let mut editor = init_editor(keys);
+ for entry in entries {
+ editor.history.add(*entry);
+ }
+ let actual_line = editor.readline("").unwrap();
+ assert_eq!(expected.0.to_owned() + expected.1, actual_line);
+ // FIXME
+ //assert_eq!(expected.0.len(), editor.term.cursor);
+}
+
#[test]
fn meta_backspace_key() {
assert_line(&[KeyPress::Meta('\x08'), KeyPress::Enter], "");