added tests

This commit is contained in:
TimonPost 2018-09-21 22:22:25 +02:00
parent 9bda408e43
commit a2bb9ecff5
9 changed files with 129 additions and 91 deletions

View File

@ -23,13 +23,18 @@ use crossterm::terminal::terminal;
use crossterm::Screen;
use crossterm::output::TerminalOutput;
use crossterm::cursor::TerminalCursor;
fn main()
{
let screen = Screen::default();
let output = TerminalOutput::new(false);
let cursor = TerminalCursor::new(&screen.stdout);
let bytes = "test".as_bytes();
let result = output.write_str("test");
println!("bytes: {} written: {}", bytes.len(), result.unwrap());
cursor.goto(5, 5);
let (x, y) = cursor.pos();
assert_eq!(x, 5);
assert_eq!(y, 5);
println!("x: {} y: {}", x,y);
}

View File

@ -2,6 +2,8 @@
//! Like moving the cursor position;saving and resetting the cursor position; hiding showing and control the blinking of the cursor.
mod cursor;
#[cfg(test)]
mod test;
mod ansi_cursor;

View File

@ -6,38 +6,41 @@ use modules::cursor::ITerminalCursor;
use Screen;
/* ======================== WinApi =========================== */
#[test]
fn goto_winapi()
{
#[cfg(windows)]
mod winapi_tests {
use super::*;
#[test]
fn goto_winapi()
{
let screen = Screen::default();
let cursor = WinApiCursor::new();
cursor.goto(5,5,&screen.stdout);
let (x,y) = cursor.pos(&screen.stdout);
cursor.goto(5, 5, &screen.stdout);
let (x, y) = cursor.pos(&screen.stdout);
assert_eq!(x, 5);
assert_eq!(y, 5);
}
}
#[test]
fn reset_safe_winapi()
{
#[test]
fn reset_safe_winapi()
{
let screen = Screen::default();
let cursor = WinApiCursor::new();
let (x,y) = cursor.pos(&screen.stdout);
let (x, y) = cursor.pos(&screen.stdout);
cursor.save_position(&screen.stdout);
cursor.goto(5,5,&screen.stdout);
cursor.goto(5, 5, &screen.stdout);
cursor.reset_position(&screen.stdout);
let (x_saved,y_saved) = cursor.pos(&screen.stdout);
let (x_saved, y_saved) = cursor.pos(&screen.stdout);
assert_eq!(x, x_saved);
assert_eq!(y, y_saved);
}
}
/* ======================== ANSI =========================== */
#[test]
fn reset_safe_ansi()

View File

@ -1,6 +1,8 @@
//! This module provides a way to work with an handle to an screen on different platforms.
mod output;
#[cfg(test)]
mod test;
mod ansi_output;

View File

@ -5,18 +5,33 @@ use modules::output::IStdout;
use Screen;
/* ======================== WinApi =========================== */
#[test]
fn write_winapi()
{
#[cfg(windows)]
mod winapi_tests {
use super::*;
/* ======================== WinApi =========================== */
#[test]
fn write_winapi()
{
let screen = Screen::default();
let output = WinApiOutput::new();
let bytes = "test".as_bytes();
let result = output.write(bytes);
is_valid_write(result, bytes.len());
}
}
#[test]
fn write_str_winapi()
{
let screen = Screen::default();
let output = WinApiOutput::new();
let bytes = "test".as_bytes();
let result = output.write_str("test");
is_valid_write(result, bytes.len());
}
}
/* ======================== ANSI =========================== */
#[test]
@ -27,10 +42,10 @@ fn write_ansi()
let bytes = "test".as_bytes();
let result = output.write(bytes);
println!("bytes: {} written: {}", bytes.len(), result.unwrap());
is_valid_write(result, bytes.len());
}
#[test]
fn write_str_ansi()
{
let screen = Screen::default();
@ -41,7 +56,6 @@ fn write_str_ansi()
is_valid_write(result, bytes.len());
}
fn is_valid_write(result: ::std::io::Result<usize>, str_length: usize)
{
match result {

View File

@ -1,6 +1,5 @@
//! Module that contains all the actions related to the styling of the terminal. like coloring adding attributes etc.
mod test;
pub mod color;
pub mod objectstyle;
pub mod styledobject;

View File

@ -1,46 +0,0 @@
//use modules::style::winapi_color::WinApiColor;
//use modules::style::ansi_color::AnsiColor;
//
//use modules::style::ITerminalColor;
//
//use Screen;
//
//* ======================== WinApi =========================== */
//#[test]
//fn goto_winapi()
//{
// let screen = Screen::default();
// let color = WinApiColor::new();
//
// assert_eq!(x, 5);
// assert_eq!(y, 5);
//}
//
//
//
//* ======================== ANSI =========================== */
//#[test]
//fn reset_safe_ansi()
//{
// if try_enable_ansi() {
// let screen = Screen::default();
// let cursor = AnsiColor::new();
//
// assert_eq!(x, x_saved);
// assert_eq!(y, y_saved);
// }
//}
//
//
//fn try_enable_ansi() -> bool
//{
// if cfg!(target_os = "windows") {
// #[cfg(windows)]
// use kernel::windows_kernel::ansi_support::try_enable_ansi_support;
//
// if !try_enable_ansi_support()
// { return false; }
// }
//
// return true;
//}

View File

@ -1,5 +1,8 @@
//! Module that contains all the actions related to the terminal. like clearing, resizing and scrolling the terminal.
#[cfg(test)]
mod test;
pub mod terminal;
mod ansi_terminal;

View File

@ -0,0 +1,56 @@
use modules::terminal::winapi_terminal::WinApiTerminal;
use modules::terminal::ansi_terminal::AnsiTerminal;
use modules::terminal::ITerminal;
use Screen;
/* ======================== WinApi =========================== */
#[cfg(windows)]
mod winapi_tests {
use super::*;
#[test]
fn resize_winapi()
{
let screen = Screen::default();
let terminal = WinApiTerminal::new();
terminal.set_size(10, 10, &screen.stdout);
let (x, y) = terminal.terminal_size(&screen.stdout);
assert_eq!(x, 10);
assert_eq!(y, 10);
}
}
/* ======================== ANSI =========================== */
#[test]
fn resize_ansi()
{
if try_enable_ansi() {
let screen = Screen::default();
let terminal = WinApiTerminal::new();
terminal.set_size(10,10, &screen.stdout);
let (x, y) = terminal.terminal_size(&screen.stdout);
assert_eq!(x, 10);
assert_eq!(y, 10);
}
}
fn try_enable_ansi() -> bool
{
if cfg!(target_os = "windows") {
#[cfg(windows)]
use kernel::windows_kernel::ansi_support::try_enable_ansi_support;
if !try_enable_ansi_support()
{ return false; }
}
return true;
}