2017-03-18 16:49:46 -04:00
|
|
|
package terminal;
|
|
|
|
|
2017-03-21 15:03:16 -04:00
|
|
|
import static com.googlecode.lanterna.input.KeyType.*;
|
2017-03-19 12:54:35 -04:00
|
|
|
import static terminal.LispTerminal.END_OF_SEGMENT;
|
2017-03-18 16:49:46 -04:00
|
|
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
public class LispTerminalTest {
|
2017-03-18 16:49:46 -04:00
|
|
|
|
2017-03-23 16:14:26 -04:00
|
|
|
private VirtualTerminalInteractor terminal;
|
2017-03-20 11:18:36 -04:00
|
|
|
|
2017-03-18 16:49:46 -04:00
|
|
|
@Before
|
2017-03-23 16:14:26 -04:00
|
|
|
public void setUp() {
|
|
|
|
terminal = new VirtualTerminalInteractor();
|
|
|
|
terminal.start();
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
2017-03-23 16:14:26 -04:00
|
|
|
public void tearDown() {
|
|
|
|
terminal.stop();
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void leftArrowDoesNotMovePastOrigin() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.pressKey(ArrowLeft);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void leftArrowWorksAfterEnteringCharacters() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("abc");
|
|
|
|
terminal.assertCursorPosition(3, 0);
|
|
|
|
terminal.pressKey(ArrowLeft);
|
|
|
|
terminal.assertCursorPosition(2, 0);
|
|
|
|
terminal.pressKey(ArrowLeft);
|
|
|
|
terminal.assertCursorPosition(1, 0);
|
|
|
|
terminal.pressKey(ArrowLeft);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
terminal.pressKey(ArrowLeft);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void leftArrowWorksAcrossRows() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(5);
|
|
|
|
terminal.enterCharacters("123451");
|
|
|
|
terminal.assertCursorPosition(1, 1);
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.assertCursorPosition(4, 0);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void rightArrowDoesNotMovePastEndOfInput() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.pressKey(ArrowRight);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void rightArrowWorksAfterMovingLeft() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("12");
|
|
|
|
terminal.assertCursorPosition(2, 0);
|
|
|
|
terminal.pressKey(ArrowLeft);
|
|
|
|
terminal.assertCursorPosition(1, 0);
|
|
|
|
terminal.pressKey(ArrowRight);
|
|
|
|
terminal.assertCursorPosition(2, 0);
|
|
|
|
terminal.pressKey(ArrowRight);
|
|
|
|
terminal.assertCursorPosition(2, 0);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void rightArrowWorksAcrossRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(5);
|
|
|
|
terminal.enterCharacters("123451");
|
|
|
|
terminal.assertCursorPosition(1, 1);
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 3);
|
|
|
|
terminal.assertCursorPosition(3, 0);
|
|
|
|
terminal.pressKeyTimes(ArrowRight, 3);
|
|
|
|
terminal.assertCursorPosition(1, 1);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void characterKeyIsEchoed() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacter('a');
|
|
|
|
terminal.assertCursorPosition(1, 0);
|
|
|
|
terminal.assertCharacterAtPosition('a', 0, 0);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void characterIsInserted() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("abcd");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.enterCharacter('x');
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'a', 'b', 'x', 'c', 'd' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void characterIsInserted_PushesInputToNextRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(4);
|
|
|
|
terminal.enterCharacters("abcd");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.enterCharacter('x');
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'a', 'b', 'x', 'c' }, { 'd', ' ', ' ', ' ' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceDoesNothingAtOrigin() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.pressKey(Backspace);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceWorksAfterInput() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("12345");
|
|
|
|
terminal.pressKeyTimes(Backspace, 2);
|
|
|
|
terminal.assertCursorPosition(3, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '1', '2', '3', ' ', ' ', ' ' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceWorksAcrossRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(4);
|
|
|
|
terminal.enterCharacters("1234567");
|
|
|
|
terminal.pressKeyTimes(Backspace, 5);
|
|
|
|
terminal.assertCursorPosition(2, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '1', '2', ' ', ' ' }, { ' ', ' ', ' ', ' ' } });
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceWorksInMiddleOfInput() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("12345");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.pressKey(Backspace);
|
|
|
|
terminal.assertCursorPosition(2, 0);
|
|
|
|
terminal.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() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.pressKey(Delete);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void deleteDoesNothingAtEndOfInput() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("del");
|
|
|
|
terminal.pressKey(Delete);
|
|
|
|
terminal.assertCursorPosition(3, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'd', 'e', 'l' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void deleteWorksAtStartOfInput() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("del");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 3);
|
|
|
|
terminal.pressKeyTimes(Delete, 3);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { ' ', ' ', ' ' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void deleteWorksAcrossRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(4);
|
|
|
|
terminal.enterCharacters("delete");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 5);
|
|
|
|
terminal.pressKey(Delete);
|
|
|
|
terminal.assertCursorPosition(1, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'd', 'l', 'e', 't' }, { 'e', ' ' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterMovesToNextLine() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.assertCursorPosition(0, 1);
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterWritesLineToPipedStream() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("enter");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.assertInputWritten("enter\n");
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterPressedInMiddleOfInput_WritesEntireLineToPipedStream() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("enter");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.assertInputWritten("enter\n");
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
2017-03-20 16:20:28 -04:00
|
|
|
@Test
|
|
|
|
public void enterAfterInsertedText_WritesLineToPipedStream() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("enter");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.enterCharacters("||");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.assertInputWritten("ent||er\n");
|
2017-03-20 16:20:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterAfterBackspace_WritesLineToPipedStream() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("enter");
|
|
|
|
terminal.pressKeyTimes(Backspace, 2);
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.assertInputWritten("ent\n");
|
2017-03-20 16:20:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void enterAfterDelete_WritesLineToPipedStream() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("enter");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.pressKeyTimes(Delete, 2);
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.assertInputWritten("ent\n");
|
2017-03-20 16:20:28 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
@Test
|
|
|
|
public void controlDWorks() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("control-d");
|
|
|
|
terminal.enterControlCharacter('d');
|
|
|
|
terminal.assertInputStreamClosed();
|
|
|
|
terminal.assertInputWritten("control-d\n");
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
2017-03-23 12:14:44 -04:00
|
|
|
@Test
|
|
|
|
public void controlCWorks() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("ctrl-c");
|
|
|
|
terminal.enterControlCharacter('c');
|
|
|
|
terminal.produceOutput("");
|
|
|
|
terminal.assertInputStreamClosed();
|
|
|
|
terminal.assertInputWritten("");
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'c', 't', 'r', 'l', '-', 'c', ' ', ' ', ' ' },
|
|
|
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' } });
|
2017-03-23 12:14:44 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 12:54:35 -04:00
|
|
|
@Test
|
|
|
|
public void controlDWorksInMiddleOfInput() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("control-d");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 2);
|
|
|
|
terminal.enterControlCharacter('d');
|
|
|
|
terminal.assertInputStreamClosed();
|
|
|
|
terminal.assertInputWritten("control-d\n");
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void escapeDoesNothing() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.pressKey(Escape);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
terminal.assertInputWritten("");
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void controlQDoesNothing() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterControlCharacter('q');
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
terminal.assertInputWritten("");
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void controlEnterDoesNothing() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.pressControlKey(Enter);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
terminal.assertInputWritten("");
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void outputIsWritten() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.produceOutput("output");
|
|
|
|
terminal.assertCursorPosition(6, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'o', 'u', 't', 'p', 'u', 't' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void endOfSegmentCharacterIsNotPrinted() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.produceOutput("> " + END_OF_SEGMENT);
|
|
|
|
terminal.assertCursorPosition(2, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '>', ' ', ' ' } });
|
2017-03-19 12:54:35 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 17:17:34 -04:00
|
|
|
@Test
|
|
|
|
public void enterTextPastLastLineOfBuffer() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.setRows(2);
|
|
|
|
terminal.enterCharacters("01201201");
|
|
|
|
terminal.assertCursorPosition(2, 1);
|
|
|
|
terminal.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() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.setRows(4);
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("00011122");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 4);
|
|
|
|
terminal.assertCursorPosition(1, 2);
|
|
|
|
terminal.enterCharacters("zz");
|
|
|
|
terminal.assertCursorPosition(0, 2);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', 'z', 'z' }, { '1', '1', '2' },
|
|
|
|
{ '2', ' ', ' ' } });
|
2017-03-20 16:20:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void insertingTextDoesNothingWhenBufferFilled() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.setRows(3);
|
|
|
|
terminal.enterCharacters("00011122");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 4);
|
|
|
|
terminal.assertCursorPosition(1, 1);
|
|
|
|
terminal.enterCharacters("zz");
|
|
|
|
terminal.assertCursorPosition(1, 1);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', '1', '1' }, { '2', '2', ' ' } });
|
2017-03-20 16:20:28 -04:00
|
|
|
}
|
2017-03-19 17:17:34 -04:00
|
|
|
|
2017-03-21 09:25:40 -04:00
|
|
|
@Test
|
|
|
|
public void appendingTextDoesNothingWhenBufferFilled() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.setRows(3);
|
|
|
|
terminal.enterCharacters("000111222333444");
|
|
|
|
terminal.assertCursorPosition(2, 2);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', '1', '1' }, { '2', '2', ' ' } });
|
2017-03-21 09:25:40 -04:00
|
|
|
}
|
|
|
|
|
2017-03-19 17:17:34 -04:00
|
|
|
@Test
|
|
|
|
public void printedOutputToEndOfRow_MovesCursorToNextRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.produceOutput("out");
|
|
|
|
terminal.assertCursorPosition(0, 1);
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void printedOutputToEndOfBuffer_MovesCursorToNewRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.setRows(2);
|
|
|
|
terminal.produceOutput("output");
|
|
|
|
terminal.assertCursorPosition(0, 1);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'p', 'u', 't' }, { ' ', ' ', ' ' } });
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-03-22 15:26:00 -04:00
|
|
|
public void outputDoesNotOverwriteInput_AndRedisplaysInput() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.enterCharacters("0123");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 3);
|
|
|
|
terminal.produceOutput("out");
|
|
|
|
terminal.assertCursorPosition(2, 3);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '3', 'o', 'u' }, { 't', '0', '1' },
|
|
|
|
{ '2', '3', ' ' }, { ' ', ' ', ' ' } });
|
2017-03-22 15:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void outputEndsOnSecondToLastColumn_MovesToNewRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.enterCharacters("01234");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 3);
|
|
|
|
terminal.produceOutput("out");
|
|
|
|
terminal.assertCursorPosition(2, 4);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '3', '4', 'o' }, { 'u', 't', ' ' },
|
|
|
|
{ '0', '1', '2' }, { '3', '4', ' ' } });
|
2017-03-22 15:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void outputEndsOnLastColumn_MovesToNewRow() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.enterCharacters("012345");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 3);
|
|
|
|
terminal.produceOutput("out");
|
|
|
|
terminal.assertCursorPosition(0, 5);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '3', '4', '5' }, { 'o', 'u', 't' },
|
|
|
|
{ '0', '1', '2' }, { '3', '4', '5' }, { ' ', ' ', ' ' } });
|
2017-03-22 15:26:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void outputRedisplaysInputAtEndOfBuffer() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.setRows(4);
|
|
|
|
terminal.enterCharacters("01234");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 3);
|
|
|
|
terminal.produceOutput("out");
|
|
|
|
terminal.assertCursorPosition(2, 3);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '3', '4', 'o' }, { 'u', 't', ' ' }, { '0', '1', '2' },
|
|
|
|
{ '3', '4', ' ' } });
|
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
|
2017-03-22 15:26:00 -04:00
|
|
|
public void outputDoesNotOverwriteInput_AfterEnter() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.enterCharacters("01201201");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 5);
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.produceOutput("out");
|
|
|
|
terminal.assertCursorPosition(0, 4);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '0', '1', '2' }, { '0', '1', ' ' },
|
|
|
|
{ 'o', 'u', 't' }, { ' ', ' ', ' ' } });
|
2017-03-19 17:17:34 -04:00
|
|
|
}
|
|
|
|
|
2017-03-21 12:07:22 -04:00
|
|
|
@Test
|
|
|
|
public void resizeIsHandledGracefully() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("resize");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("test");
|
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.assertCursorPosition(1, 1);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 't', 'e', 's' }, { 't', ' ', ' ' } });
|
2017-03-21 15:03:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void backspaceWorksAfterResize() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("resize");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("test");
|
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.pressKeyTimes(Backspace, 20);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { ' ', ' ', ' ' }, { ' ', ' ', ' ' } });
|
2017-03-21 12:07:22 -04:00
|
|
|
}
|
|
|
|
|
2017-03-21 15:03:16 -04:00
|
|
|
@Test
|
|
|
|
public void deleteWorksAfterResize() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.enterCharacters("resize");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("test");
|
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 20);
|
|
|
|
terminal.pressKeyTimes(Delete, 20);
|
|
|
|
terminal.pressKeyTimes(ArrowRight, 20);
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { ' ', ' ', ' ' }, { ' ', ' ', ' ' } });
|
2017-03-21 15:03:16 -04:00
|
|
|
}
|
2017-03-22 11:26:53 -04:00
|
|
|
|
|
|
|
@Test
|
2017-03-22 15:26:00 -04:00
|
|
|
public void controlSequencesAreNotPrinted() {
|
2017-03-23 16:14:26 -04:00
|
|
|
terminal.produceOutput("\u001B[32mcontrol\u001B[0mseq");
|
|
|
|
terminal.assertCharacterPositions(new char[][] { { 'c', 'o', 'n', 't', 'r', 'o', 'l', 's', 'e', 'q' } });
|
2017-03-22 11:26:53 -04:00
|
|
|
}
|
|
|
|
|
2017-04-04 15:37:57 -04:00
|
|
|
@Test
|
|
|
|
public void upArrowWorks() {
|
|
|
|
terminal.enterCharacters("(one)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("(two)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.pressKey(ArrowUp);
|
|
|
|
terminal.assertScreenText("(one)", "(two)", "(two)");
|
|
|
|
terminal.assertCursorPosition(5, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void upArrowErasesCurrentLine() {
|
|
|
|
terminal.enterCharacters("(one)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("(two)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("(three)");
|
|
|
|
terminal.pressKey(ArrowUp);
|
|
|
|
terminal.assertScreenText("(one)", "(two)", "(two) ");
|
|
|
|
terminal.assertCursorPosition(5, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void upArrowStopsAtFirstLine() {
|
|
|
|
terminal.enterCharacters("(one)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("(two)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.pressKeyTimes(ArrowUp, 5);
|
|
|
|
terminal.assertScreenText("(one)", "(two)", "(one)");
|
|
|
|
terminal.assertCursorPosition(5, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void originIsUpdatedWhenPreviousLineMovesPastEndOfBuffer() {
|
|
|
|
terminal.setRows(3);
|
|
|
|
terminal.setColumns(3);
|
|
|
|
terminal.enterCharacters("12345");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.pressKey(ArrowUp);
|
|
|
|
terminal.assertScreenText("45 ", "123", "45 ");
|
|
|
|
terminal.pressKeyTimes(ArrowLeft, 10);
|
|
|
|
terminal.assertCursorPosition(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void downArrowWorks() {
|
|
|
|
terminal.enterCharacters("(one)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("(two)");
|
|
|
|
terminal.pressKey(Enter);
|
|
|
|
terminal.enterCharacters("(three)");
|
|
|
|
terminal.pressKey(ArrowUp);
|
|
|
|
terminal.pressKey(ArrowDown);
|
|
|
|
terminal.assertScreenText("(one)", "(two)", "(three)");
|
|
|
|
terminal.assertCursorPosition(7, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void downArrowStopsAtLastLine() {
|
|
|
|
terminal.pressKeyTimes(ArrowDown, 5);
|
|
|
|
terminal.assertScreenText(" ");
|
|
|
|
terminal.assertCursorPosition(0, 0);
|
|
|
|
}
|
|
|
|
|
2017-03-18 16:49:46 -04:00
|
|
|
}
|