diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /vendor/anes/tests/parser | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/anes/tests/parser')
-rw-r--r-- | vendor/anes/tests/parser/cursor.rs | 8 | ||||
-rw-r--r-- | vendor/anes/tests/parser/key.rs | 158 | ||||
-rw-r--r-- | vendor/anes/tests/parser/mod.rs | 25 | ||||
-rw-r--r-- | vendor/anes/tests/parser/mouse/mod.rs | 2 | ||||
-rw-r--r-- | vendor/anes/tests/parser/mouse/rxvt.rs | 152 | ||||
-rw-r--r-- | vendor/anes/tests/parser/mouse/xterm.rs | 154 |
6 files changed, 499 insertions, 0 deletions
diff --git a/vendor/anes/tests/parser/cursor.rs b/vendor/anes/tests/parser/cursor.rs new file mode 100644 index 000000000..250ee48a6 --- /dev/null +++ b/vendor/anes/tests/parser/cursor.rs @@ -0,0 +1,8 @@ +use anes::parser::Sequence; + +use crate::test_sequences; + +#[test] +fn position() { + test_sequences!(b"\x1B[20;10R", Sequence::CursorPosition(10, 20),); +} diff --git a/vendor/anes/tests/parser/key.rs b/vendor/anes/tests/parser/key.rs new file mode 100644 index 000000000..cd87c9dd1 --- /dev/null +++ b/vendor/anes/tests/parser/key.rs @@ -0,0 +1,158 @@ +use anes::parser::{KeyCode, KeyModifiers, Sequence}; + +use crate::test_sequences; + +#[test] +fn esc_o_f_keys() { + test_sequences!( + b"\x1BOP", + Sequence::Key(KeyCode::F(1), KeyModifiers::empty()), + b"\x1BOQ", + Sequence::Key(KeyCode::F(2), KeyModifiers::empty()), + b"\x1BOR", + Sequence::Key(KeyCode::F(3), KeyModifiers::empty()), + b"\x1BOS", + Sequence::Key(KeyCode::F(4), KeyModifiers::empty()), + ); +} + +#[test] +fn csi_key_codes() { + test_sequences!( + b"\x1B[A", + Sequence::Key(KeyCode::Up, KeyModifiers::empty()), + b"\x1B[B", + Sequence::Key(KeyCode::Down, KeyModifiers::empty()), + b"\x1B[C", + Sequence::Key(KeyCode::Right, KeyModifiers::empty()), + b"\x1B[D", + Sequence::Key(KeyCode::Left, KeyModifiers::empty()), + b"\x1B[H", + Sequence::Key(KeyCode::Home, KeyModifiers::empty()), + b"\x1B[F", + Sequence::Key(KeyCode::End, KeyModifiers::empty()), + b"\x1B[Z", + Sequence::Key(KeyCode::BackTab, KeyModifiers::empty()), + ); +} + +#[test] +fn csi_arrow_key_modifiers() { + test_sequences!( + b"\x1B[50A", + Sequence::Key(KeyCode::Up, KeyModifiers::SHIFT), + b"\x1B[53A", + Sequence::Key(KeyCode::Up, KeyModifiers::CONTROL), + ); +} + +#[test] +fn csi_tilde_key_modifiers() { + test_sequences!( + b"\x1B[1~", + Sequence::Key(KeyCode::Home, KeyModifiers::empty()), + b"\x1B[1;0~", + Sequence::Key(KeyCode::Home, KeyModifiers::empty()), + b"\x1B[1;1~", + Sequence::Key(KeyCode::Home, KeyModifiers::empty()), + b"\x1B[1;2~", + Sequence::Key(KeyCode::Home, KeyModifiers::SHIFT), + b"\x1B[1;3~", + Sequence::Key(KeyCode::Home, KeyModifiers::ALT), + b"\x1B[1;4~", + Sequence::Key(KeyCode::Home, KeyModifiers::SHIFT | KeyModifiers::ALT), + b"\x1B[1;5~", + Sequence::Key(KeyCode::Home, KeyModifiers::CONTROL), + b"\x1B[1;6~", + Sequence::Key(KeyCode::Home, KeyModifiers::SHIFT | KeyModifiers::CONTROL), + b"\x1B[1;7~", + Sequence::Key(KeyCode::Home, KeyModifiers::ALT | KeyModifiers::CONTROL), + b"\x1B[1;8~", + Sequence::Key( + KeyCode::Home, + KeyModifiers::SHIFT | KeyModifiers::ALT | KeyModifiers::CONTROL + ), + b"\x1B[1;9~", + Sequence::Key(KeyCode::Home, KeyModifiers::META), + b"\x1B[1;10~", + Sequence::Key(KeyCode::Home, KeyModifiers::META | KeyModifiers::SHIFT), + b"\x1B[1;11~", + Sequence::Key(KeyCode::Home, KeyModifiers::META | KeyModifiers::ALT), + b"\x1B[1;12~", + Sequence::Key( + KeyCode::Home, + KeyModifiers::META | KeyModifiers::SHIFT | KeyModifiers::ALT + ), + b"\x1B[1;13~", + Sequence::Key(KeyCode::Home, KeyModifiers::META | KeyModifiers::CONTROL), + b"\x1B[1;14~", + Sequence::Key( + KeyCode::Home, + KeyModifiers::META | KeyModifiers::SHIFT | KeyModifiers::CONTROL + ), + b"\x1B[1;15~", + Sequence::Key( + KeyCode::Home, + KeyModifiers::META | KeyModifiers::ALT | KeyModifiers::CONTROL + ), + b"\x1B[1;16~", + Sequence::Key( + KeyCode::Home, + KeyModifiers::META | KeyModifiers::SHIFT | KeyModifiers::ALT | KeyModifiers::CONTROL + ), + b"\x1B[1;17~", + Sequence::Key(KeyCode::Home, KeyModifiers::empty()), + ); +} + +#[test] +fn csi_tilde_f_keys() { + test_sequences!( + b"\x1B[11~", + Sequence::Key(KeyCode::F(1), KeyModifiers::empty()), + b"\x1B[12~", + Sequence::Key(KeyCode::F(2), KeyModifiers::empty()), + b"\x1B[13~", + Sequence::Key(KeyCode::F(3), KeyModifiers::empty()), + b"\x1B[14~", + Sequence::Key(KeyCode::F(4), KeyModifiers::empty()), + b"\x1B[15~", + Sequence::Key(KeyCode::F(5), KeyModifiers::empty()), + b"\x1B[17~", + Sequence::Key(KeyCode::F(6), KeyModifiers::empty()), + b"\x1B[18~", + Sequence::Key(KeyCode::F(7), KeyModifiers::empty()), + b"\x1B[19~", + Sequence::Key(KeyCode::F(8), KeyModifiers::empty()), + b"\x1B[20~", + Sequence::Key(KeyCode::F(9), KeyModifiers::empty()), + b"\x1B[21~", + Sequence::Key(KeyCode::F(10), KeyModifiers::empty()), + b"\x1B[23~", + Sequence::Key(KeyCode::F(11), KeyModifiers::empty()), + b"\x1B[24~", + Sequence::Key(KeyCode::F(12), KeyModifiers::empty()), + ); +} + +#[test] +fn csi_tilde_key_codes() { + test_sequences!( + b"\x1B[1~", + Sequence::Key(KeyCode::Home, KeyModifiers::empty()), + b"\x1B[2~", + Sequence::Key(KeyCode::Insert, KeyModifiers::empty()), + b"\x1B[3~", + Sequence::Key(KeyCode::Delete, KeyModifiers::empty()), + b"\x1B[4~", + Sequence::Key(KeyCode::End, KeyModifiers::empty()), + b"\x1B[5~", + Sequence::Key(KeyCode::PageUp, KeyModifiers::empty()), + b"\x1B[6~", + Sequence::Key(KeyCode::PageDown, KeyModifiers::empty()), + b"\x1B[7~", + Sequence::Key(KeyCode::Home, KeyModifiers::empty()), + b"\x1B[8~", + Sequence::Key(KeyCode::End, KeyModifiers::empty()), + ); +} diff --git a/vendor/anes/tests/parser/mod.rs b/vendor/anes/tests/parser/mod.rs new file mode 100644 index 000000000..ecddcddb6 --- /dev/null +++ b/vendor/anes/tests/parser/mod.rs @@ -0,0 +1,25 @@ +#[macro_export] +macro_rules! test_sequence { + ($bytes:expr, $seq:expr) => { + let mut parser = ::anes::parser::Parser::default(); + parser.advance($bytes, false); + assert_eq!(parser.next(), Some($seq)); + }; +} + +#[macro_export] +macro_rules! test_sequences { + ( + $( + $bytes:expr, $seq:expr, + )* + ) => { + $( + test_sequence!($bytes, $seq); + )* + }; +} + +mod cursor; +mod key; +mod mouse; diff --git a/vendor/anes/tests/parser/mouse/mod.rs b/vendor/anes/tests/parser/mouse/mod.rs new file mode 100644 index 000000000..dc53361e4 --- /dev/null +++ b/vendor/anes/tests/parser/mouse/mod.rs @@ -0,0 +1,2 @@ +mod rxvt; +mod xterm; diff --git a/vendor/anes/tests/parser/mouse/rxvt.rs b/vendor/anes/tests/parser/mouse/rxvt.rs new file mode 100644 index 000000000..47f43a51c --- /dev/null +++ b/vendor/anes/tests/parser/mouse/rxvt.rs @@ -0,0 +1,152 @@ +use anes::parser::{KeyModifiers, Mouse, MouseButton, Sequence}; + +use crate::test_sequences; + +#[test] +fn button_down() { + test_sequences!( + b"\x1B[0;30;40;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Left, 30, 40), + KeyModifiers::empty() + ), + b"\x1B[1;30;40;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Middle, 30, 40), + KeyModifiers::empty() + ), + b"\x1B[2;30;40;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Right, 30, 40), + KeyModifiers::empty() + ), + ); +} + +#[test] +fn button_down_with_modifiers() { + test_sequences!( + b"\x1B[4;30;40;M", + Sequence::Mouse(Mouse::Down(MouseButton::Left, 30, 40), KeyModifiers::SHIFT), + b"\x1B[5;30;40;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Middle, 30, 40), + KeyModifiers::SHIFT + ), + b"\x1B[6;30;40;M", + Sequence::Mouse(Mouse::Down(MouseButton::Right, 30, 40), KeyModifiers::SHIFT), + ); +} + +#[test] +fn button_up() { + test_sequences!( + b"\x1B[3;30;40;M", + Sequence::Mouse(Mouse::Up(MouseButton::Any, 30, 40), KeyModifiers::empty()), + ); +} + +#[test] +fn button_up_with_modifiers() { + test_sequences!( + b"\x1B[7;30;40;M", + Sequence::Mouse(Mouse::Up(MouseButton::Any, 30, 40), KeyModifiers::SHIFT), + ); +} + +#[test] +fn scroll() { + test_sequences!( + b"\x1B[96;30;40;M", + Sequence::Mouse(Mouse::ScrollUp(30, 40), KeyModifiers::empty()), + b"\x1B[97;30;40;M", + Sequence::Mouse(Mouse::ScrollDown(30, 40), KeyModifiers::empty()), + ); +} + +#[test] +fn scroll_with_modifiers() { + test_sequences!( + b"\x1B[100;30;40;M", + Sequence::Mouse(Mouse::ScrollUp(30, 40), KeyModifiers::SHIFT), + b"\x1B[101;30;40;M", + Sequence::Mouse(Mouse::ScrollDown(30, 40), KeyModifiers::SHIFT), + ); +} + +#[test] +fn drag() { + test_sequences!( + b"\x1B[64;30;40;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Left, 30, 40), + KeyModifiers::empty() + ), + b"\x1B[65;30;40;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Middle, 30, 40), + KeyModifiers::empty() + ), + b"\x1B[66;30;40;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Right, 30, 40), + KeyModifiers::empty() + ), + ); +} + +#[test] +fn drag_with_modifiers() { + test_sequences!( + b"\x1B[64;30;40;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Left, 30, 40), + KeyModifiers::empty() + ), + b"\x1B[65;30;40;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Middle, 30, 40), + KeyModifiers::empty() + ), + b"\x1B[66;30;40;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Right, 30, 40), + KeyModifiers::empty() + ), + ); +} + +#[test] +fn key_modifier_combinations() { + test_sequences!( + b"\x1B[4;20;10M", + Sequence::Mouse(Mouse::Down(MouseButton::Left, 20, 10), KeyModifiers::SHIFT), + b"\x1B[8;20;10M", + Sequence::Mouse(Mouse::Down(MouseButton::Left, 20, 10), KeyModifiers::ALT), + b"\x1B[16;20;10M", + Sequence::Mouse( + Mouse::Down(MouseButton::Left, 20, 10), + KeyModifiers::CONTROL + ), + b"\x1B[12;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Left, 20, 10), + KeyModifiers::SHIFT | KeyModifiers::ALT + ), + b"\x1B[20;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Left, 20, 10), + KeyModifiers::SHIFT | KeyModifiers::CONTROL + ), + b"\x1B[24;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Left, 20, 10), + KeyModifiers::ALT | KeyModifiers::CONTROL + ), + b"\x1B[28;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Left, 20, 10), + KeyModifiers::SHIFT | KeyModifiers::ALT | KeyModifiers::CONTROL + ), + ); +} diff --git a/vendor/anes/tests/parser/mouse/xterm.rs b/vendor/anes/tests/parser/mouse/xterm.rs new file mode 100644 index 000000000..47293d69e --- /dev/null +++ b/vendor/anes/tests/parser/mouse/xterm.rs @@ -0,0 +1,154 @@ +use anes::parser::{KeyModifiers, Mouse, MouseButton, Sequence}; + +use crate::test_sequences; + +#[test] +fn button_down() { + test_sequences!( + b"\x1B[<0;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Left, 20, 10), + KeyModifiers::empty() + ), + b"\x1B[<1;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Middle, 20, 10), + KeyModifiers::empty() + ), + b"\x1B[<2;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Right, 20, 10), + KeyModifiers::empty() + ), + ); +} + +#[test] +fn button_down_with_key_modifiers() { + test_sequences!( + b"\x1B[<4;20;10;M", + Sequence::Mouse(Mouse::Down(MouseButton::Left, 20, 10), KeyModifiers::SHIFT), + b"\x1B[<5;20;10;M", + Sequence::Mouse( + Mouse::Down(MouseButton::Middle, 20, 10), + KeyModifiers::SHIFT + ), + b"\x1B[<6;20;10;M", + Sequence::Mouse(Mouse::Down(MouseButton::Right, 20, 10), KeyModifiers::SHIFT), + ); +} + +#[test] +fn button_up() { + test_sequences!( + b"\x1B[<0;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Left, 20, 10), KeyModifiers::empty()), + b"\x1B[<1;20;10;m", + Sequence::Mouse( + Mouse::Up(MouseButton::Middle, 20, 10), + KeyModifiers::empty() + ), + b"\x1B[<2;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Right, 20, 10), KeyModifiers::empty()), + ); +} + +#[test] +fn button_up_with_key_modifiers() { + test_sequences!( + b"\x1B[<4;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Left, 20, 10), KeyModifiers::SHIFT), + b"\x1B[<5;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Middle, 20, 10), KeyModifiers::SHIFT), + b"\x1B[<6;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Right, 20, 10), KeyModifiers::SHIFT), + ); +} + +#[test] +fn scroll() { + test_sequences!( + b"\x1B[<64;20;10;m", + Sequence::Mouse(Mouse::ScrollUp(20, 10), KeyModifiers::empty()), + b"\x1B[<65;20;10;m", + Sequence::Mouse(Mouse::ScrollDown(20, 10), KeyModifiers::empty()), + ); +} + +#[test] +fn scroll_with_key_modifiers() { + test_sequences!( + b"\x1B[<68;20;10;m", + Sequence::Mouse(Mouse::ScrollUp(20, 10), KeyModifiers::SHIFT), + b"\x1B[<69;20;10;m", + Sequence::Mouse(Mouse::ScrollDown(20, 10), KeyModifiers::SHIFT), + ); +} + +#[test] +fn drag() { + test_sequences!( + b"\x1B[<32;20;10;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Left, 20, 10), + KeyModifiers::empty() + ), + b"\x1B[<33;20;10;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Middle, 20, 10), + KeyModifiers::empty() + ), + b"\x1B[<34;20;10;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Right, 20, 10), + KeyModifiers::empty() + ), + ); +} + +#[test] +fn drag_with_key_modifiers() { + test_sequences!( + b"\x1B[<36;20;10;M", + Sequence::Mouse(Mouse::Drag(MouseButton::Left, 20, 10), KeyModifiers::SHIFT), + b"\x1B[<37;20;10;M", + Sequence::Mouse( + Mouse::Drag(MouseButton::Middle, 20, 10), + KeyModifiers::SHIFT, + ), + b"\x1B[<38;20;10;M", + Sequence::Mouse(Mouse::Drag(MouseButton::Right, 20, 10), KeyModifiers::SHIFT), + ); +} + +#[test] +fn key_modifier_combinations() { + test_sequences!( + b"\x1B[<4;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Left, 20, 10), KeyModifiers::SHIFT), + b"\x1B[<8;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Left, 20, 10), KeyModifiers::ALT), + b"\x1B[<16;20;10;m", + Sequence::Mouse(Mouse::Up(MouseButton::Left, 20, 10), KeyModifiers::CONTROL), + b"\x1B[<12;20;10;m", + Sequence::Mouse( + Mouse::Up(MouseButton::Left, 20, 10), + KeyModifiers::SHIFT | KeyModifiers::ALT + ), + b"\x1B[<20;20;10;m", + Sequence::Mouse( + Mouse::Up(MouseButton::Left, 20, 10), + KeyModifiers::SHIFT | KeyModifiers::CONTROL + ), + b"\x1B[<24;20;10;m", + Sequence::Mouse( + Mouse::Up(MouseButton::Left, 20, 10), + KeyModifiers::ALT | KeyModifiers::CONTROL + ), + b"\x1B[<28;20;10;m", + Sequence::Mouse( + Mouse::Up(MouseButton::Left, 20, 10), + KeyModifiers::SHIFT | KeyModifiers::ALT | KeyModifiers::CONTROL + ), + ); +} |