Clean up terminal tests
This commit is contained in:
parent
63fd890ac6
commit
cbbcb4fe3e
|
@ -82,7 +82,7 @@ public class LispTerminalTest {
|
|||
public void characterKeyIsEchoed() {
|
||||
terminal.enterCharacter('a');
|
||||
terminal.assertCursorPosition(1, 0);
|
||||
terminal.assertCharacterAtPosition('a', 0, 0);
|
||||
terminal.assertScreenText("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -90,7 +90,7 @@ public class LispTerminalTest {
|
|||
terminal.enterCharacters("abcd");
|
||||
terminal.pressKeyTimes(ArrowLeft, 2);
|
||||
terminal.enterCharacter('x');
|
||||
terminal.assertCharacterPositions(new char[][] { { 'a', 'b', 'x', 'c', 'd' } });
|
||||
terminal.assertScreenText("abxcd");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -99,7 +99,7 @@ public class LispTerminalTest {
|
|||
terminal.enterCharacters("abcd");
|
||||
terminal.pressKeyTimes(ArrowLeft, 2);
|
||||
terminal.enterCharacter('x');
|
||||
terminal.assertCharacterPositions(new char[][] { { 'a', 'b', 'x', 'c' }, { 'd', ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("abxc", "d ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -113,7 +113,7 @@ public class LispTerminalTest {
|
|||
terminal.enterCharacters("12345");
|
||||
terminal.pressKeyTimes(Backspace, 2);
|
||||
terminal.assertCursorPosition(3, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { '1', '2', '3', ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("123 ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -122,7 +122,7 @@ public class LispTerminalTest {
|
|||
terminal.enterCharacters("1234567");
|
||||
terminal.pressKeyTimes(Backspace, 5);
|
||||
terminal.assertCursorPosition(2, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { '1', '2', ' ', ' ' }, { ' ', ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("12 ", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,7 +131,7 @@ public class LispTerminalTest {
|
|||
terminal.pressKeyTimes(ArrowLeft, 2);
|
||||
terminal.pressKey(Backspace);
|
||||
terminal.assertCursorPosition(2, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { '1', '2', '4', '5' } });
|
||||
terminal.assertScreenText("1245");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,7 +145,7 @@ public class LispTerminalTest {
|
|||
terminal.enterCharacters("del");
|
||||
terminal.pressKey(Delete);
|
||||
terminal.assertCursorPosition(3, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { 'd', 'e', 'l' } });
|
||||
terminal.assertScreenText("del");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -154,7 +154,7 @@ public class LispTerminalTest {
|
|||
terminal.pressKeyTimes(ArrowLeft, 3);
|
||||
terminal.pressKeyTimes(Delete, 3);
|
||||
terminal.assertCursorPosition(0, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText(" ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -164,7 +164,7 @@ public class LispTerminalTest {
|
|||
terminal.pressKeyTimes(ArrowLeft, 5);
|
||||
terminal.pressKey(Delete);
|
||||
terminal.assertCursorPosition(1, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { 'd', 'l', 'e', 't' }, { 'e', ' ' } });
|
||||
terminal.assertScreenText("dlet", "e ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -229,8 +229,7 @@ public class LispTerminalTest {
|
|||
terminal.produceOutput("");
|
||||
terminal.assertInputStreamClosed();
|
||||
terminal.assertInputWritten("");
|
||||
terminal.assertCharacterPositions(new char[][] { { 'c', 't', 'r', 'l', '-', 'c', ' ', ' ', ' ' },
|
||||
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("ctrl-c ", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -267,14 +266,14 @@ public class LispTerminalTest {
|
|||
public void outputIsWritten() {
|
||||
terminal.produceOutput("output");
|
||||
terminal.assertCursorPosition(6, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { 'o', 'u', 't', 'p', 'u', 't' } });
|
||||
terminal.assertScreenText("output");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endOfSegmentCharacterIsNotPrinted() {
|
||||
terminal.produceOutput("> " + END_OF_SEGMENT);
|
||||
terminal.assertCursorPosition(2, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { '>', ' ', ' ' } });
|
||||
terminal.assertScreenText("> ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -283,7 +282,7 @@ public class LispTerminalTest {
|
|||
terminal.setRows(2);
|
||||
terminal.enterCharacters("01201201");
|
||||
terminal.assertCursorPosition(2, 1);
|
||||
terminal.assertCharacterPositions(new char[][] { { '0', '1', '2' }, { '0', '1', ' ' } });
|
||||
terminal.assertScreenText("012", "01 ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -296,8 +295,7 @@ public class LispTerminalTest {
|
|||
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', ' ', ' ' } });
|
||||
terminal.assertScreenText("000", "1zz", "112", "2 ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -309,7 +307,7 @@ public class LispTerminalTest {
|
|||
terminal.assertCursorPosition(1, 1);
|
||||
terminal.enterCharacters("zz");
|
||||
terminal.assertCursorPosition(1, 1);
|
||||
terminal.assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', '1', '1' }, { '2', '2', ' ' } });
|
||||
terminal.assertScreenText("000", "111", "22 ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -318,7 +316,7 @@ public class LispTerminalTest {
|
|||
terminal.setRows(3);
|
||||
terminal.enterCharacters("000111222333444");
|
||||
terminal.assertCursorPosition(2, 2);
|
||||
terminal.assertCharacterPositions(new char[][] { { '0', '0', '0' }, { '1', '1', '1' }, { '2', '2', ' ' } });
|
||||
terminal.assertScreenText("000", "111", "22 ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -334,7 +332,7 @@ public class LispTerminalTest {
|
|||
terminal.setRows(2);
|
||||
terminal.produceOutput("output");
|
||||
terminal.assertCursorPosition(0, 1);
|
||||
terminal.assertCharacterPositions(new char[][] { { 'p', 'u', 't' }, { ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("put", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -344,8 +342,7 @@ public class LispTerminalTest {
|
|||
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', ' ' }, { ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("012", "3ou", "t01", "23 ", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -355,8 +352,7 @@ public class LispTerminalTest {
|
|||
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', ' ' } });
|
||||
terminal.assertScreenText("012", "34o", "ut ", "012", "34 ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -366,8 +362,7 @@ public class LispTerminalTest {
|
|||
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' }, { ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("012", "345", "out", "012", "345", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -378,8 +373,7 @@ public class LispTerminalTest {
|
|||
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', ' ' } });
|
||||
terminal.assertScreenText("34o", "ut ", "012");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -390,8 +384,7 @@ public class LispTerminalTest {
|
|||
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' }, { ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText("012", "012", "01 ", "out", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -401,7 +394,7 @@ public class LispTerminalTest {
|
|||
terminal.enterCharacters("test");
|
||||
terminal.setColumns(3);
|
||||
terminal.assertCursorPosition(1, 1);
|
||||
terminal.assertCharacterPositions(new char[][] { { 't', 'e', 's' }, { 't', ' ', ' ' } });
|
||||
terminal.assertScreenText("tes", "t ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -412,7 +405,7 @@ public class LispTerminalTest {
|
|||
terminal.setColumns(3);
|
||||
terminal.pressKeyTimes(Backspace, 20);
|
||||
terminal.assertCursorPosition(0, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { ' ', ' ', ' ' }, { ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText(" ", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -425,13 +418,13 @@ public class LispTerminalTest {
|
|||
terminal.pressKeyTimes(Delete, 20);
|
||||
terminal.pressKeyTimes(ArrowRight, 20);
|
||||
terminal.assertCursorPosition(0, 0);
|
||||
terminal.assertCharacterPositions(new char[][] { { ' ', ' ', ' ' }, { ' ', ' ', ' ' } });
|
||||
terminal.assertScreenText(" ", " ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void controlSequencesAreNotPrinted() {
|
||||
terminal.produceOutput("\u001B[32mcontrol\u001B[0mseq");
|
||||
terminal.assertCharacterPositions(new char[][] { { 'c', 'o', 'n', 't', 'r', 'o', 'l', 's', 'e', 'q' } });
|
||||
terminal.assertScreenText("controlseq");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -134,6 +134,12 @@ public class VirtualTerminalInteractor {
|
|||
assertEquals(row, virtualTerminal.getCursorPosition().getRow());
|
||||
}
|
||||
|
||||
public void assertScreenText(String... rows) {
|
||||
for (int row = 0; row < rows.length; row++)
|
||||
for (int column = 0; column < rows[row].length(); column++)
|
||||
assertCharacterAtPosition(rows[row].charAt(column), column, row);
|
||||
}
|
||||
|
||||
public void assertCharacterAtPosition(char character, int column, int row) {
|
||||
TerminalPosition position = new TerminalPosition(column, row);
|
||||
String expected = String.valueOf(character);
|
||||
|
@ -141,18 +147,6 @@ public class VirtualTerminalInteractor {
|
|||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
|
||||
public void assertScreenText(String... rows) {
|
||||
for (int row = 0; row < rows.length; row++)
|
||||
for (int column = 0; column < rows[row].length(); column++)
|
||||
assertCharacterAtPosition(rows[row].charAt(column), column, row);
|
||||
}
|
||||
|
||||
public void assertInputWritten(String expected) {
|
||||
String actual = "";
|
||||
|
||||
|
|
Loading…
Reference in New Issue