Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests #242

Merged
merged 5 commits into from
Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crossterm_cursor/src/cursor/ansi_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ mod tests {

// TODO - Test is ingored, because it's stalled on Travis CI
#[test]
#[ignore]
fn test_ansi_save_restore_position() {
if try_enable_ansi() {
let cursor = AnsiCursor::new();
Expand All @@ -130,7 +129,6 @@ mod tests {

// TODO - Test is ingored, because it's stalled on Travis CI
#[test]
#[ignore]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't work on TCI, should be disabled. See the comment above (in the code).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I saw the comments, just wanted to try it again. Unfortunately...

fn test_ansi_goto() {
if try_enable_ansi() {
let cursor = AnsiCursor::new();
Expand Down
8 changes: 6 additions & 2 deletions crossterm_terminal/src/sys/winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pub fn exit() {

#[cfg(windows)]
pub fn get_terminal_size() -> Result<(u16, u16)> {
let buffer = ScreenBuffer::current()?;
Ok(buffer.info()?.terminal_size().into())
let terminal_size = ScreenBuffer::current()?.info()?.terminal_size();
// windows starts counting at 0, unix at 1, add one to replicated unix behaviour.
Ok((
(terminal_size.width + 1) as u16,
(terminal_size.height + 1) as u16,
))
}
7 changes: 3 additions & 4 deletions crossterm_terminal/src/terminal/ansi_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,19 @@ mod tests {
use super::{AnsiTerminal, ITerminal};

/* ======================== ANSI =========================== */
// TODO - Test is disabled, because it's failing on Travis CI
#[test]
#[ignore]
fn test_resize_ansi() {
if try_enable_ansi() {
let terminal = AnsiTerminal::new();

let (width, height) = terminal.size().unwrap();

terminal.set_size(30, 30).unwrap();
terminal.set_size(35, 35).unwrap();
// see issue: https://github.com/eminence/terminal-size/issues/11
thread::sleep(time::Duration::from_millis(30));
assert_eq!((30, 30), terminal.size().unwrap());
assert_eq!((35, 35), terminal.size().unwrap());

// reset to previous size
terminal.set_size(width, height).unwrap();
// see issue: https://github.com/eminence/terminal-size/issues/11
thread::sleep(time::Duration::from_millis(30));
Expand Down
16 changes: 10 additions & 6 deletions crossterm_terminal/src/terminal/winapi_terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ impl ITerminal for WinApiTerminal {
resize_buffer = true;
}

println!("{:?}", new_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed.

println!("{:?}", current_size);
println!("{:?}", window);

if resize_buffer {
if let Err(_) = screen_buffer.set_size(new_size.width, new_size.height) {
if let Err(_) = screen_buffer.set_size(new_size.width - 1, new_size.height - 1) {
return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Something went wrong when setting screen buffer size.",
)));
Expand All @@ -138,13 +142,14 @@ impl ITerminal for WinApiTerminal {

let mut window = window.clone();
// Preserve the position, but change the size.
window.bottom = window.top + height;
window.right = window.left + width;
window.bottom = window.top + height - 1;
window.right = window.left + width - 1;
console.set_console_info(true, window)?;

// If we resized the buffer, un-resize it.
if resize_buffer {
if let Err(_) = screen_buffer.set_size(current_size.width, current_size.height) {
if let Err(_) = screen_buffer.set_size(current_size.width - 1, current_size.height - 1)
{
return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Something went wrong when setting screen buffer size.",
)));
Expand Down Expand Up @@ -280,9 +285,7 @@ fn clear(start_location: Coord, cells_to_write: u32, current_attribute: u16) ->
mod tests {
use super::{ITerminal, WinApiTerminal};

// TODO - Test is ignored, because it returns wrong result (31 != 30)
#[test]
#[ignore]
fn test_resize_winapi() {
let terminal = WinApiTerminal::new();

Expand All @@ -291,6 +294,7 @@ mod tests {
terminal.set_size(30, 30).unwrap();
assert_eq!((30, 30), terminal.size().unwrap());

// reset to previous size
terminal.set_size(width, height).unwrap();
assert_eq!((width, height), terminal.size().unwrap());
}
Expand Down