diff --git a/src/event.rs b/src/event.rs index 852196e..fde57f4 100644 --- a/src/event.rs +++ b/src/event.rs @@ -272,3 +272,14 @@ where I: Iterator> } } } + +#[test] +fn test_parse_utf8() { + let st = "abcéŷ¤£€ù%323"; + let ref mut bytes = st.bytes().map(|x| Ok(x)); + let chars = st.chars(); + for c in chars { + let b = bytes.next().unwrap().unwrap(); + assert!(c == parse_utf8_char(b, bytes).unwrap()); + } +} diff --git a/src/input.rs b/src/input.rs index 060226f..e2f2ea0 100644 --- a/src/input.rs +++ b/src/input.rs @@ -100,6 +100,7 @@ impl TermRead for R { mod test { use super::*; use std::io; + use event::{Key, Event, MouseEvent, MouseButton}; #[test] fn test_keys() { @@ -113,6 +114,25 @@ mod test { assert!(i.next().is_none()); } + #[test] + fn test_events() { + let mut i = b"\x1B[\x00bc\x7F\x1B[D\ + \x1B[M\x00\x22\x24\x1B[<0;2;4;M\x1B[32;2;4M\x1B[<0;2;4;m\x1B[35;2;4Mb".events(); + + assert_eq!(i.next().unwrap().unwrap(), Event::Unsupported); + assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Char('b'))); + assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Char('c'))); + assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Backspace)); + assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Left)); + assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::WheelUp, 1, 3))); + assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::Left, 1, 3))); + assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Press(MouseButton::Left, 1, 3))); + assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Release(1, 3))); + assert_eq!(i.next().unwrap().unwrap(), Event::Mouse(MouseEvent::Release(1, 3))); + assert_eq!(i.next().unwrap().unwrap(), Event::Key(Key::Char('b'))); + assert!(i.next().is_none()); + } + #[test] fn test_function_keys() { let mut st = b"\x1BOP\x1BOQ\x1BOR\x1BOS".keys(); diff --git a/src/raw.rs b/src/raw.rs index b8c6c89..2bb9991 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -177,4 +177,10 @@ mod test { out.write(b"this is a test, muahhahahah").unwrap(); } + + #[test] + fn test_enable_mouse() { + let mut out = stdout().into_raw_mode().unwrap().with_mouse().unwrap(); + out.write(b"abcde\x1B[<1;1;0;Mfgh").unwrap(); + } }