Skip to content

Commit

Permalink
Add a unit test for #168
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 19, 2017
1 parent 2012f13 commit aaad984
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2002-2016, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* http://www.opensource.org/licenses/bsd-license.php
*/
package org.jline.terminal.impl;

import org.jline.terminal.Size;
import org.jline.terminal.Terminal;
import org.jline.utils.AnsiWriter;
import org.junit.Test;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;

import static org.junit.Assert.assertEquals;

public class AbstractWindowsTerminalTest {

@Test
public void testWriterBuffering() throws Exception {
StringWriter sw = new StringWriter();
Terminal terminal = new AbstractWindowsTerminal(new AnsiWriter(new BufferedWriter(sw)), "name", 0,
false, Terminal.SignalHandler.SIG_DFL) {
@Override
protected int getConsoleOutputCP() {
return 0;
}
@Override
protected int getConsoleMode() {
return 0;
}
@Override
protected void setConsoleMode(int mode) {
}
@Override
protected String readConsoleInput() throws IOException {
return "";
}
@Override
public Size getSize() {
return new Size(80, 25);
}
};
terminal.output().write("This is a char.\n".getBytes());
assertEquals("This is a char.\n", sw.toString());
terminal.writer().print("This is a string.\n");
assertEquals("This is a char.\n", sw.toString());
terminal.writer().flush();
assertEquals("This is a char.\nThis is a string.\n", sw.toString());
}

}

0 comments on commit aaad984

Please sign in to comment.