2017-03-18 16:49:46 -04:00
|
|
|
package terminal;
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import static terminal.LispTerminal.END_OF_SEGMENT;
|
2017-03-18 16:49:46 -04:00
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
|
|
|
import com.googlecode.lanterna.*;
|
|
|
|
import com.googlecode.lanterna.input.*;
|
|
|
|
import com.googlecode.lanterna.terminal.virtual.*;
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
public class LispTerminalTest {
|
2017-03-18 16:49:46 -04:00
|
|
|
|
|
|
|
private PipedInputStream inputReader;
|
|
|
|
private PipedOutputStream inputWriter;
|
|
|
|
private PipedInputStream outputReader;
|
|
|
|
private PipedOutputStream outputWriter;
|
2017-03-19 12:54:35 -04:00
|
|
|
private FlushListener flushListener;
|
2017-03-18 16:49:46 -04:00
|
|
|
private VirtualTerminal virtualTerminal;
|
|
|
|
private LispTerminal lispTerminal;
|
|
|
|
|
|
|
|
private void pressKey(KeyType keyType) {
|
|
|
|
virtualTerminal.addInput(new KeyStroke(keyType));
|
2017-03-19 12:54:35 -04:00
|
|
|
waitForFlushes(1);
|
|
|
|
}
|
|
|
|
|
2017-03-20 11:18:36 -04:00
|
|
|
private void pressKeyTimes(KeyType keyType, int times) {
|
|
|
|
for (int i = times; i > 0; i--)
|
|
|
|
virtualTerminal.addInput(new KeyStroke(keyType));
|
|
|
|
|
|
|
|
waitForFlushes(times);
|
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
private void pressControlKey(KeyType keyType) {
|
|
|
|
virtualTerminal.addInput(new KeyStroke(keyType, true, false));
|
|
|
|
waitForFlushes(1);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void enterCharacter(char character) {
|
|
|
|
virtualTerminal.addInput(new KeyStroke(character, false, false));
|
2017-03-19 12:54:35 -04:00
|
|
|
waitForFlushes(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void enterControlCharacter(char character) {
|
|
|
|
virtualTerminal.addInput(new KeyStroke(character, true, false));
|
|
|
|
waitForFlushes(1);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void enterCharacters(String characters) {
|
|
|
|
for (char c : characters.toCharArray())
|
|
|
|
virtualTerminal.addInput(new KeyStroke(c, false, false));
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
waitForFlushes(characters.length());
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
private void produceOutput(String output) {
|
2017-03-18 16:49:46 -04:00
|
|
|
try {
|
2017-03-19 12:54:35 -04:00
|
|
|
for (char c : output.toCharArray())
|
|
|
|
outputWriter.write(c);
|
|
|
|
|
|
|
|
outputWriter.write(END_OF_SEGMENT);
|
|
|
|
outputWriter.flush();
|
|
|
|
waitForFlushes(1);
|
2017-03-20 11:18:36 -04:00
|
|
|
} catch (IOException ignored) {}
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void waitForFlushes(int flushCount) {
|
|
|
|
try {
|
|
|
|
synchronized (flushListener) {
|
|
|
|
while (flushListener.getFlushCount() < flushCount)
|
|
|
|
flushListener.wait();
|
|
|
|
|
|
|
|
flushListener.resetFlushCount();
|
|
|
|
}
|
2017-03-20 11:18:36 -04:00
|
|
|
} catch (InterruptedException ignored) {}
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
private void setColumns(int columns) {
|
2017-03-20 16:20:28 -04:00
|
|
|
int rows = virtualTerminal.getTerminalSize().getRows();
|
|
|
|
virtualTerminal.setTerminalSize(new TerminalSize(columns, rows));
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 17:17:34 -04:00
|
|
|
private void setRows(int rows) {
|
2017-03-20 16:20:28 -04:00
|
|
|
int columns = virtualTerminal.getTerminalSize().getColumns();
|
|
|
|
virtualTerminal.setTerminalSize(new TerminalSize(columns, rows));
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
|
|
|
|
2017-03-18 16:49:46 -04:00
|
|
|
private void assertCursorPosition(int column, int row) {
|
2017-03-19 17:17:34 -04:00
|
|
|
assertEquals(column, virtualTerminal.getCursorPosition().getColumn());
|
|
|
|
assertEquals(row, virtualTerminal.getCursorPosition().getRow());
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertCharacterAtPosition(char character, int column, int row) {
|
|
|
|
TerminalPosition position = new TerminalPosition(column, row);
|
2017-03-20 16:20:28 -04:00
|
|
|
String expected = String.valueOf(character);
|
|
|
|
String actual = String.valueOf(virtualTerminal.getCharacter(position).getCharacter());
|
|
|
|
assertEquals(expected, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertCharacterPositions(char[][] positions) {
|
|
|
|
for (int row = 0; row < positions.length; row++)
|
|
|
|
for (int column = 0; column < positions[row].length; column++)
|
|
|
|
assertCharacterAtPosition(positions[row][column], column, row);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
private void assertInputWritten(String expected) {
|
|
|
|
String actual = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
inputWriter.close();
|
|
|
|
|
2017-03-20 16:20:28 -04:00
|
|
|
for (int c = inputReader.read(); c != -1; c = inputReader.read())
|
2017-03-19 12:54:35 -04:00
|
|
|
actual += (char) c;
|
2017-03-20 11:18:36 -04:00
|
|
|
} catch (IOException ignored) {}
|
2017-03-19 12:54:35 -04:00
|
|
|
|
|
|
|
assertEquals(expected, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertInputStreamClosed() {
|
|
|
|
try {
|
|
|
|
inputWriter.write(0);
|
|
|
|
fail("input stream not closed");
|
2017-03-20 11:18:36 -04:00
|
|
|
} catch (IOException ignored) {}
|
|
|
|
}
|
|
|
|
|
2017-03-18 16:49:46 -04:00
|
|
|
@Before
|
|
|
|
public void setUp() throws IOException {
|
|
|
|
inputReader = new PipedInputStream();
|
|
|
|
inputWriter = new PipedOutputStream(inputReader);
|
|
|
|
outputReader = new PipedInputStream();
|
|
|
|
outputWriter = new PipedOutputStream(outputReader);
|
|
|
|
virtualTerminal = new DefaultVirtualTerminal();
|
2017-03-19 12:54:35 -04:00
|
|
|
flushListener = new FlushListener();
|
|
|
|
virtualTerminal.addVirtualTerminalListener(flushListener);
|
2017-03-18 16:49:46 -04:00
|
|
|
lispTerminal = new LispTerminal(virtualTerminal, inputWriter, outputReader);
|
2017-03-21 09:25:40 -04:00
|
|
|
lispTerminal.start();
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() throws IOException {
|
2017-03-21 09:25:40 -04:00
|
|
|
lispTerminal.stop();
|
2017-03-18 16:49:46 -04:00
|
|
|
outputWriter.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void leftArrowDoesNotMovePastOrigin() {
|
|
|
|
pressKey(KeyType.ArrowLeft);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void leftArrowWorksAfterEnteringCharacters() {
|
|
|
|
enterCharacters("abc");
|
|
|
|
assertCursorPosition(3, 0);
|
|
|
|
pressKey(KeyType.ArrowLeft);
|
|
|
|
assertCursorPosition(2, 0);
|
|
|
|
pressKey(KeyType.ArrowLeft);
|
|
|
|
assertCursorPosition(1, 0);
|
|
|
|
pressKey(KeyType.ArrowLeft);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
pressKey(KeyType.ArrowLeft);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void leftArrowWorksAcrossRows() {
|
|
|
|
setColumns(5);
|
|
|
|
enterCharacters("123451");
|
|
|
|
assertCursorPosition(1, 1);
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
2017-03-18 16:49:46 -04:00
|
|
|
assertCursorPosition(4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void rightArrowDoesNotMovePastEndOfInput() {
|
|
|
|
pressKey(KeyType.ArrowRight);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void rightArrowWorksAfterMovingLeft() {
|
|
|
|
enterCharacters("12");
|
|
|
|
assertCursorPosition(2, 0);
|
|
|
|
pressKey(KeyType.ArrowLeft);
|
|
|
|
assertCursorPosition(1, 0);
|
|
|
|
pressKey(KeyType.ArrowRight);
|
|
|
|
assertCursorPosition(2, 0);
|
|
|
|
pressKey(KeyType.ArrowRight);
|
|
|
|
assertCursorPosition(2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void rightArrowWorksAcrossRow() {
|
|
|
|
setColumns(5);
|
|
|
|
enterCharacters("123451");
|
|
|
|
assertCursorPosition(1, 1);
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 3);
|
2017-03-18 16:49:46 -04:00
|
|
|
assertCursorPosition(3, 0);
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowRight, 3);
|
2017-03-18 16:49:46 -04:00
|
|
|
assertCursorPosition(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void characterKeyIsEchoed() {
|
|
|
|
enterCharacter('a');
|
|
|
|
assertCursorPosition(1, 0);
|
|
|
|
assertCharacterAtPosition('a', 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void characterIsInserted() {
|
|
|
|
enterCharacters("abcd");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
2017-03-18 16:49:46 -04:00
|
|
|
enterCharacter('x');
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { 'a', 'b', 'x', 'c', 'd' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void characterIsInserted_PushesInputToNextRow() {
|
|
|
|
setColumns(4);
|
|
|
|
enterCharacters("abcd");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
2017-03-18 16:49:46 -04:00
|
|
|
enterCharacter('x');
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { 'a', 'b', 'x', 'c' }, { 'd', ' ', ' ', ' ' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceDoesNothingAtOrigin() {
|
|
|
|
pressKey(KeyType.Backspace);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceWorksAfterInput() {
|
|
|
|
enterCharacters("12345");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.Backspace, 2);
|
2017-03-18 16:49:46 -04:00
|
|
|
assertCursorPosition(3, 0);
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { '1', '2', '3', ' ', ' ', ' ' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceWorksAcrossRow() {
|
|
|
|
setColumns(4);
|
|
|
|
enterCharacters("1234567");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.Backspace, 5);
|
2017-03-18 16:49:46 -04:00
|
|
|
assertCursorPosition(2, 0);
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { '1', '2', ' ', ' ' }, { ' ', ' ', ' ', ' ' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceWorksInMiddleOfInput() {
|
|
|
|
enterCharacters("12345");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
2017-03-18 16:49:46 -04:00
|
|
|
pressKey(KeyType.Backspace);
|
|
|
|
assertCursorPosition(2, 0);
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { '1', '2', '4', '5' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
@Test
|
|
|
|
public void deleteDoesNothingAtOrigin() {
|
|
|
|
pressKey(KeyType.Delete);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void deleteDoesNothingAtEndOfInput() {
|
|
|
|
enterCharacters("del");
|
|
|
|
pressKey(KeyType.Delete);
|
|
|
|
assertCursorPosition(3, 0);
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { 'd', 'e', 'l' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void deleteWorksAtStartOfInput() {
|
|
|
|
enterCharacters("del");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 3);
|
|
|
|
pressKeyTimes(KeyType.Delete, 3);
|
2017-03-19 12:54:35 -04:00
|
|
|
assertCursorPosition(0, 0);
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { ' ', ' ', ' ' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void deleteWorksAcrossRow() {
|
|
|
|
setColumns(4);
|
|
|
|
enterCharacters("delete");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 5);
|
2017-03-19 12:54:35 -04:00
|
|
|
pressKey(KeyType.Delete);
|
|
|
|
assertCursorPosition(1, 0);
|
2017-03-20 16:20:28 -04:00
|
|
|
assertCharacterPositions(new char[][] { { 'd', 'l', 'e', 't' }, { 'e', ' ' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterMovesToNextLine() {
|
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
assertCursorPosition(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterWritesLineToPipedStream() {
|
|
|
|
enterCharacters("enter");
|
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
assertInputWritten("enter\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterPressedInMiddleOfInput_WritesEntireLineToPipedStream() {
|
|
|
|
enterCharacters("enter");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
2017-03-19 12:54:35 -04:00
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
assertInputWritten("enter\n");
|
|
|
|
}
|
|
|
|
|
2017-03-20 16:20:28 -04:00
|
|
|
@Test
|
|
|
|
public void enterAfterInsertedText_WritesLineToPipedStream() {
|
|
|
|
enterCharacters("enter");
|
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
|
|
|
enterCharacters("||");
|
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
assertInputWritten("ent||er\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterAfterBackspace_WritesLineToPipedStream() {
|
|
|
|
enterCharacters("enter");
|
|
|
|
pressKeyTimes(KeyType.Backspace, 2);
|
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
assertInputWritten("ent\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterAfterDelete_WritesLineToPipedStream() {
|
|
|
|
enterCharacters("enter");
|
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
|
|
|
pressKeyTimes(KeyType.Delete, 2);
|
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
assertInputWritten("ent\n");
|
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
@Test
|
|
|
|
public void controlDWorks() {
|
|
|
|
enterCharacters("control-d");
|
|
|
|
enterControlCharacter('d');
|
|
|
|
assertInputStreamClosed();
|
|
|
|
assertInputWritten("control-d\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void controlDWorksInMiddleOfInput() {
|
|
|
|
enterCharacters("control-d");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 2);
|
2017-03-19 12:54:35 -04:00
|
|
|
enterControlCharacter('d');
|
|
|
|
assertInputStreamClosed();
|
|
|
|
assertInputWritten("control-d\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void escapeDoesNothing() {
|
|
|
|
pressKey(KeyType.Escape);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
assertInputWritten("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void controlQDoesNothing() {
|
|
|
|
enterControlCharacter('q');
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
assertInputWritten("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void controlEnterDoesNothing() {
|
|
|
|
pressControlKey(KeyType.Enter);
|
|
|
|
assertCursorPosition(0, 0);
|
|
|
|
assertInputWritten("");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void outputIsWritten() {
|
|
|
|
produceOutput("output");
|
2017-03-19 17:17:34 -04:00
|
|
|
assertCursorPosition(6, 0);
|
2017-03-20 11:18:36 -04:00
|
|
|
assertCharacterPositions(new char[][] { { 'o', 'u', 't', 'p', 'u', 't' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void endOfSegmentCharacterIsNotPrinted() {
|
|
|
|
produceOutput("> " + END_OF_SEGMENT);
|
|
|
|
assertCursorPosition(2, 0);
|
2017-03-20 11:18:36 -04:00
|
|
|
assertCharacterPositions(new char[][] { { '>', ' ', ' ' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 17:17:34 -04:00
|
|
|
@Test
|
|
|
|
public void enterTextPastLastLineOfBuffer() {
|
|
|
|
setColumns(3);
|
|
|
|
setRows(2);
|
|
|
|
enterCharacters("01201201");
|
|
|
|
assertCursorPosition(2, 1);
|
2017-03-20 11:18:36 -04:00
|
|
|
assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '0', '1', ' ' } });
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
|
|
|
|
2017-03-20 16:20:28 -04:00
|
|
|
@Test
|
|
|
|
public void insertingTextPushesInputPastEndOfBuffer() {
|
|
|
|
setColumns(3);
|
|
|
|
setRows(4);
|
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
enterCharacters("00011122");
|
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 4);
|
|
|
|
assertCursorPosition(1, 2);
|
|
|
|
enterCharacters("zz");
|
|
|
|
assertCursorPosition(0, 2);
|
|
|
|
assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', 'z', 'z' }, { '1', '1', '2' },
|
|
|
|
{ '2', ' ', ' ' } });
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void insertingTextDoesNothingWhenBufferFilled() {
|
|
|
|
setColumns(3);
|
|
|
|
setRows(3);
|
|
|
|
enterCharacters("00011122");
|
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 4);
|
|
|
|
assertCursorPosition(1, 1);
|
|
|
|
enterCharacters("zz");
|
|
|
|
assertCursorPosition(1, 1);
|
|
|
|
assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', '1', '1' }, { '2', '2', ' ' } });
|
|
|
|
}
|
2017-03-19 17:17:34 -04:00
|
|
|
|
2017-03-21 09:25:40 -04:00
|
|
|
@Test
|
|
|
|
public void appendingTextDoesNothingWhenBufferFilled() {
|
|
|
|
setColumns(3);
|
|
|
|
setRows(3);
|
|
|
|
enterCharacters("000111222333444");
|
|
|
|
assertCursorPosition(2, 2);
|
|
|
|
assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', '1', '1' }, { '2', '2', ' ' } });
|
|
|
|
}
|
|
|
|
|
2017-03-19 17:17:34 -04:00
|
|
|
@Test
|
|
|
|
public void printedOutputToEndOfRow_MovesCursorToNextRow() {
|
|
|
|
setColumns(3);
|
|
|
|
produceOutput("out");
|
|
|
|
assertCursorPosition(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void printedOutputToEndOfBuffer_MovesCursorToNewRow() {
|
|
|
|
setColumns(3);
|
|
|
|
setRows(2);
|
|
|
|
produceOutput("output");
|
|
|
|
assertCursorPosition(0, 1);
|
2017-03-20 11:18:36 -04:00
|
|
|
assertCharacterPositions(new char[][] { { 'p', 'u', 't' }, { ' ', ' ', ' ' } });
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void printedOutputDoesNotOverwriteInput() {
|
|
|
|
setColumns(3);
|
|
|
|
enterCharacters("01201201");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 5);
|
2017-03-19 17:17:34 -04:00
|
|
|
produceOutput("out");
|
|
|
|
assertCursorPosition(0, 4);
|
2017-03-20 11:18:36 -04:00
|
|
|
assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '0', '1', '2' }, { '0', '1', 'o' },
|
|
|
|
{ 'u', 't', ' ' } });
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
2017-03-20 11:18:36 -04:00
|
|
|
|
2017-03-19 17:17:34 -04:00
|
|
|
@Test
|
|
|
|
public void printedOutputDoesNotOverwriteInput_AfterEnter() {
|
|
|
|
setColumns(3);
|
|
|
|
enterCharacters("01201201");
|
2017-03-20 11:18:36 -04:00
|
|
|
pressKeyTimes(KeyType.ArrowLeft, 5);
|
2017-03-19 17:17:34 -04:00
|
|
|
pressKey(KeyType.Enter);
|
|
|
|
produceOutput("out");
|
|
|
|
assertCursorPosition(0, 4);
|
2017-03-20 11:18:36 -04:00
|
|
|
assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '0', '1', '2' }, { '0', '1', ' ' },
|
|
|
|
{ 'o', 'u', 't' } });
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
|
|
|
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|