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