added some tests

This commit is contained in:
IGI-111 2016-07-20 13:06:04 +02:00
parent ab12a8f8a6
commit 1c50a795f8
3 changed files with 37 additions and 0 deletions

View File

@ -272,3 +272,14 @@ where I: Iterator<Item = Result<u8, Error>>
} }
} }
} }
#[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());
}
}

View File

@ -100,6 +100,7 @@ impl<R: Read> TermRead for R {
mod test { mod test {
use super::*; use super::*;
use std::io; use std::io;
use event::{Key, Event, MouseEvent, MouseButton};
#[test] #[test]
fn test_keys() { fn test_keys() {
@ -113,6 +114,25 @@ mod test {
assert!(i.next().is_none()); 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] #[test]
fn test_function_keys() { fn test_function_keys() {
let mut st = b"\x1BOP\x1BOQ\x1BOR\x1BOS".keys(); let mut st = b"\x1BOP\x1BOQ\x1BOR\x1BOS".keys();

View File

@ -177,4 +177,10 @@ mod test {
out.write(b"this is a test, muahhahahah").unwrap(); 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();
}
} }