From a0bb412127701afb845bf432a9a8d922d1544f96 Mon Sep 17 00:00:00 2001 From: gwenn <gtreguier@gmail.com> Date: Thu, 24 May 2018 19:37:06 +0200 Subject: [PATCH] More tests --- src/test/common.rs | 8 ++-- src/test/emacs.rs | 113 ++++++++++++++++++++++++++++++++++++++++++++ src/test/history.rs | 42 ++++++++++++++-- 3 files changed, 156 insertions(+), 7 deletions(-) diff --git a/src/test/common.rs b/src/test/common.rs index cddeb91c..2d5a9596 100644 --- a/src/test/common.rs +++ b/src/test/common.rs @@ -97,14 +97,14 @@ fn ctrl_t() { #[test] fn ctrl_u() { assert_cursor( - ("a", "b"), + ("start of line ", "end"), &[KeyPress::Ctrl('U'), KeyPress::Enter], - ("", "b"), + ("", "end"), ); assert_cursor( - ("", "a"), + ("", "end"), &[KeyPress::Ctrl('U'), KeyPress::Enter], - ("", "a"), + ("", "end"), ); } diff --git a/src/test/emacs.rs b/src/test/emacs.rs index 736fd430..6494b1a9 100644 --- a/src/test/emacs.rs +++ b/src/test/emacs.rs @@ -27,6 +27,21 @@ fn ctrl_b() { &[KeyPress::Ctrl('B'), KeyPress::Enter], ("H", "i"), ); + assert_cursor( + ("Hi", ""), + &[KeyPress::Meta('2'), KeyPress::Ctrl('B'), KeyPress::Enter], + ("", "Hi"), + ); + assert_cursor( + ("", "Hi"), + &[ + KeyPress::Meta('-'), + KeyPress::Meta('2'), + KeyPress::Ctrl('B'), + KeyPress::Enter, + ], + ("Hi", ""), + ); } #[test] @@ -36,6 +51,21 @@ fn ctrl_f() { &[KeyPress::Ctrl('F'), KeyPress::Enter], ("H", "i"), ); + assert_cursor( + ("", "Hi"), + &[KeyPress::Meta('2'), KeyPress::Ctrl('F'), KeyPress::Enter], + ("Hi", ""), + ); + assert_cursor( + ("Hi", ""), + &[ + KeyPress::Meta('-'), + KeyPress::Meta('2'), + KeyPress::Ctrl('F'), + KeyPress::Enter, + ], + ("", "Hi"), + ); } #[test] @@ -45,6 +75,21 @@ fn ctrl_h() { &[KeyPress::Ctrl('H'), KeyPress::Enter], ("H", ""), ); + assert_cursor( + ("Hi", ""), + &[KeyPress::Meta('2'), KeyPress::Ctrl('H'), KeyPress::Enter], + ("", ""), + ); + assert_cursor( + ("", "Hi"), + &[ + KeyPress::Meta('-'), + KeyPress::Meta('2'), + KeyPress::Ctrl('H'), + KeyPress::Enter, + ], + ("", ""), + ); } #[test] @@ -104,6 +149,16 @@ fn ctrl_p() { ); } +#[test] +fn ctrl_t() { + /* FIXME + assert_cursor( + ("ab", "cd"), + &[KeyPress::Meta('2'), KeyPress::Ctrl('T'), KeyPress::Enter], + ("acdb", ""), + );*/ +} + #[test] fn ctrl_x_ctrl_u() { assert_cursor( @@ -125,6 +180,16 @@ fn meta_b() { &[KeyPress::Meta('B'), KeyPress::Enter], ("Hello, ", "world!"), ); + assert_cursor( + ("Hello, world!", ""), + &[KeyPress::Meta('2'), KeyPress::Meta('B'), KeyPress::Enter], + ("", "Hello, world!"), + ); + assert_cursor( + ("", "Hello, world!"), + &[KeyPress::Meta('-'), KeyPress::Meta('B'), KeyPress::Enter], + ("Hello", ", world!"), + ); } #[test] @@ -134,6 +199,16 @@ fn meta_f() { &[KeyPress::Meta('F'), KeyPress::Enter], ("Hello", ", world!"), ); + assert_cursor( + ("", "Hello, world!"), + &[KeyPress::Meta('2'), KeyPress::Meta('F'), KeyPress::Enter], + ("Hello, world", "!"), + ); + assert_cursor( + ("Hello, world!", ""), + &[KeyPress::Meta('-'), KeyPress::Meta('F'), KeyPress::Enter], + ("Hello, ", "world!"), + ); } #[test] @@ -148,6 +223,12 @@ fn meta_c() { &[KeyPress::Meta('C'), KeyPress::Enter], ("Hi", ""), ); + /* FIXME + assert_cursor( + ("", "hi test"), + &[KeyPress::Meta('2'), KeyPress::Meta('C'), KeyPress::Enter], + ("Hi Test", ""), + );*/ } #[test] @@ -162,6 +243,12 @@ fn meta_l() { &[KeyPress::Meta('L'), KeyPress::Enter], ("hi", ""), ); + /* FIXME + assert_cursor( + ("", "HI TEST"), + &[KeyPress::Meta('2'), KeyPress::Meta('L'), KeyPress::Enter], + ("hi test", ""), + );*/ } #[test] @@ -176,6 +263,12 @@ fn meta_u() { &[KeyPress::Meta('U'), KeyPress::Enter], ("HI", ""), ); + /* FIXME + assert_cursor( + ("", "hi test"), + &[KeyPress::Meta('2'), KeyPress::Meta('U'), KeyPress::Enter], + ("HI TEST", ""), + );*/ } #[test] @@ -185,6 +278,11 @@ fn meta_d() { &[KeyPress::Meta('D'), KeyPress::Enter], ("Hello", "!"), ); + assert_cursor( + ("Hello", ", world!"), + &[KeyPress::Meta('2'), KeyPress::Meta('D'), KeyPress::Enter], + ("Hello", ""), + ); } #[test] @@ -194,6 +292,12 @@ fn meta_t() { &[KeyPress::Meta('T'), KeyPress::Enter], ("world, Hello", "!"), ); + /* FIXME + assert_cursor( + ("One Two", " Three Four"), + &[KeyPress::Meta('T'), KeyPress::Enter], + ("One Four Three Two", ""), + );*/ } #[test] @@ -220,3 +324,12 @@ fn meta_backspace() { ("Hello, ", "ld!"), ); } + +#[test] +fn meta_digit() { + assert_cursor( + ("", ""), + &[KeyPress::Meta('3'), KeyPress::Char('h'), KeyPress::Enter], + ("hhh", ""), + ); +} diff --git a/src/test/history.rs b/src/test/history.rs index aa9e9c63..23978842 100644 --- a/src/test/history.rs +++ b/src/test/history.rs @@ -15,7 +15,16 @@ fn down_key() { &[ KeyPress::Char('a'), KeyPress::Up, - KeyPress::Down, + KeyPress::Down, // restore original line + KeyPress::Enter, + ], + ("a", ""), + ); + assert_history( + &["line1"], + &[ + KeyPress::Char('a'), + KeyPress::Down, // noop KeyPress::Enter, ], ("a", ""), @@ -76,10 +85,21 @@ fn ctrl_r() { &[ KeyPress::Ctrl('R'), KeyPress::Char('r'), - KeyPress::Char('z'), // no match + KeyPress::Ctrl('R'), KeyPress::Right, // just to assert cursor pos KeyPress::Enter, ], + ("r", "ustc"), + ); + assert_history( + &["rustc", "cargo"], + &[ + KeyPress::Ctrl('R'), + KeyPress::Char('r'), + KeyPress::Char('z'), // no match + KeyPress::Right, // just to assert cursor pos + KeyPress::Enter, + ], ("car", "go"), ); assert_history( @@ -95,6 +115,22 @@ fn ctrl_r() { ); } +#[test] +fn ctrl_s() { + assert_history( + &["rustc", "cargo"], + &[ + KeyPress::Ctrl('R'), + KeyPress::Char('r'), + KeyPress::Ctrl('R'), + KeyPress::Ctrl('S'), + KeyPress::Right, // just to assert cursor pos + KeyPress::Enter, + ], + ("car", "go"), + ); +} + #[test] fn meta_lt() { assert_history(&[""], &[KeyPress::Meta('<'), KeyPress::Enter], ("", "")); @@ -118,7 +154,7 @@ fn meta_gt() { &[ KeyPress::Char('a'), KeyPress::Meta('<'), - KeyPress::Meta('>'), + KeyPress::Meta('>'), // restore original line KeyPress::Enter, ], ("a", ""), -- GitLab