diff --git a/pom.xml b/pom.xml
index 685e2d2..1defd19 100644
--- a/pom.xml
+++ b/pom.xml
@@ -201,18 +201,10 @@
test
-
-
- org.hamcrest
- hamcrest-all
- 1.3
- test
-
-
org.fitnesse
fitnesse
- 20161106
+ 20180127
test
diff --git a/src/test/kotlin/recursion/TailCallTest.kt b/src/test/kotlin/recursion/TailCallTest.kt
index 82471a3..7dfdf84 100644
--- a/src/test/kotlin/recursion/TailCallTest.kt
+++ b/src/test/kotlin/recursion/TailCallTest.kt
@@ -8,7 +8,9 @@ class TailCallTest {
@Test
fun `tailCall does not support result`() {
- val tailCall = object : TailCall { override fun apply() = done(null) }
+ val tailCall = object : TailCall {
+ override fun apply() = done(null)
+ }
assertThrows(UnsupportedOperationException::class.java) { tailCall.result() }
}
diff --git a/src/test/kotlin/scanner/LispScannerTextTest.kt b/src/test/kotlin/scanner/LispScannerTextTest.kt
index 71c0161..edd4a6f 100644
--- a/src/test/kotlin/scanner/LispScannerTextTest.kt
+++ b/src/test/kotlin/scanner/LispScannerTextTest.kt
@@ -1,7 +1,7 @@
package scanner
import org.assertj.core.api.Assertions.assertThat
-import org.junit.Test
+import org.junit.jupiter.api.Test
import testutil.TestUtilities.createInputStreamFromString
class LispScannerTextTest {
diff --git a/src/test/kotlin/terminal/ControlSequenceHandlerTest.java b/src/test/kotlin/terminal/ControlSequenceHandlerTest.java
deleted file mode 100644
index cd4dae0..0000000
--- a/src/test/kotlin/terminal/ControlSequenceHandlerTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package terminal;
-
-import org.junit.Before;
-import org.junit.Test;
-import stream.SafeInputStream;
-import terminal.ControlSequence.NullControlSequence;
-import testutil.TestUtilities;
-import util.Characters;
-
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static terminal.ControlSequenceHandler.isEscape;
-import static terminal.SelectGraphicRendition.GREEN;
-import static terminal.SelectGraphicRendition.PURPLE;
-import static terminal.SelectGraphicRendition.RED;
-import static terminal.SelectGraphicRendition.RESET;
-import static terminal.SelectGraphicRendition.YELLOW;
-
-public class ControlSequenceHandlerTest {
-
- private ControlSequenceHandler handler;
-
- private Object readRemaining(SafeInputStream input) {
- String remaining = "";
-
- for (int c = input.read(); c != Characters.EOF; c = input.read())
- remaining += (char) c;
-
- return remaining;
- }
-
- private SafeInputStream createSafeInputStream(String data) {
- return new SafeInputStream(TestUtilities.INSTANCE.createInputStreamFromString(data));
- }
-
- @Before
- public void setUp() {
- handler = new ControlSequenceHandler();
- }
-
- @Test
- public void isEscapeDetectsNonEscapeCharacter() {
- assertThat(isEscape('x'), is(false));
- }
-
- @Test
- public void isEscapeDetectsEscapeCharacter() {
- assertThat(isEscape('\u001b'), is(true));
- }
-
- @Test
- public void correctlyParsesControlSequence_LeavesRestOfStreamIntact() {
- SafeInputStream input = createSafeInputStream("[32mdata");
- handler.parse(input);
- assertThat(readRemaining(input), is("data"));
- }
-
- @Test
- public void unterminatedControlSequence_OnlyConsumesFirstNonSequenceCharacter() {
- SafeInputStream input = createSafeInputStream("[32data");
- handler.parse(input);
- assertThat(readRemaining(input), is("ata"));
- }
-
- @Test
- public void malformedControlSequence_OnlyConsumesOneCharacter() {
- SafeInputStream input = createSafeInputStream("32mdata");
- handler.parse(input);
- assertThat(readRemaining(input), is("2mdata"));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_EOF() {
- SafeInputStream input = createSafeInputStream("");
- assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_EOF_AfterFirstCharacter() {
- SafeInputStream input = createSafeInputStream("[");
- assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_UnterminatedControlSequence() {
- SafeInputStream input = createSafeInputStream("[data");
- assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_MalformedControlSequence() {
- SafeInputStream input = createSafeInputStream("32mdata");
- assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_SGR_Reset() {
- SafeInputStream input = createSafeInputStream("[0m");
- assertThat(handler.parse(input), is(RESET));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_SGR_Red() {
- SafeInputStream input = createSafeInputStream("[31m");
- assertThat(handler.parse(input), is(RED));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_SGR_Green() {
- SafeInputStream input = createSafeInputStream("[32m");
- assertThat(handler.parse(input), is(GREEN));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_SGR_Yellow() {
- SafeInputStream input = createSafeInputStream("[33m");
- assertThat(handler.parse(input), is(YELLOW));
- }
-
- @Test
- public void parsedControlSequenceIsCorrectType_SGR_Purple() {
- SafeInputStream input = createSafeInputStream("[35m");
- assertThat(handler.parse(input), is(PURPLE));
- }
-
- @Test
- public void parseMultipleControlSequences() {
- SafeInputStream input = createSafeInputStream("[35m[32m[0m");
- assertThat(handler.parse(input), is(PURPLE));
- assertThat(handler.parse(input), is(GREEN));
- assertThat(handler.parse(input), is(RESET));
- }
-}
diff --git a/src/test/kotlin/terminal/ControlSequenceHandlerTest.kt b/src/test/kotlin/terminal/ControlSequenceHandlerTest.kt
new file mode 100644
index 0000000..f8b043d
--- /dev/null
+++ b/src/test/kotlin/terminal/ControlSequenceHandlerTest.kt
@@ -0,0 +1,133 @@
+package terminal
+
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import stream.SafeInputStream
+import terminal.ControlSequence.NullControlSequence
+import terminal.ControlSequenceHandler.Companion.isEscape
+import terminal.SelectGraphicRendition.GREEN
+import terminal.SelectGraphicRendition.PURPLE
+import terminal.SelectGraphicRendition.RED
+import terminal.SelectGraphicRendition.RESET
+import terminal.SelectGraphicRendition.YELLOW
+import testutil.TestUtilities
+import util.Characters.EOF
+
+class ControlSequenceHandlerTest {
+
+ private lateinit var handler: ControlSequenceHandler
+
+ private fun readRemaining(input: SafeInputStream): Any {
+ var remaining = ""
+ var c = input.read()
+
+ while (c != EOF) {
+ remaining += c.toChar()
+ c = input.read()
+ }
+
+ return remaining
+ }
+
+ private fun createSafeInputStream(data: String) =
+ SafeInputStream(TestUtilities.createInputStreamFromString(data))
+
+ @BeforeEach
+ fun setUp() {
+ handler = ControlSequenceHandler()
+ }
+
+ @Test
+ fun isEscapeDetectsNonEscapeCharacter() {
+ assertThat(isEscape('x')).isFalse()
+ }
+
+ @Test
+ fun isEscapeDetectsEscapeCharacter() {
+ assertThat(isEscape('\u001b')).isTrue()
+ }
+
+ @Test
+ fun correctlyParsesControlSequence_LeavesRestOfStreamIntact() {
+ val input = createSafeInputStream("[32mdata")
+ handler.parse(input)
+ assertThat(readRemaining(input)).isEqualTo("data")
+ }
+
+ @Test
+ fun unterminatedControlSequence_OnlyConsumesFirstNonSequenceCharacter() {
+ val input = createSafeInputStream("[32data")
+ handler.parse(input)
+ assertThat(readRemaining(input)).isEqualTo("ata")
+ }
+
+ @Test
+ fun malformedControlSequence_OnlyConsumesOneCharacter() {
+ val input = createSafeInputStream("32mdata")
+ handler.parse(input)
+ assertThat(readRemaining(input)).isEqualTo("2mdata")
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_EOF() {
+ val input = createSafeInputStream("")
+ assertThat(handler.parse(input)).isInstanceOf(NullControlSequence::class.java)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_EOF_AfterFirstCharacter() {
+ val input = createSafeInputStream("[")
+ assertThat(handler.parse(input)).isInstanceOf(NullControlSequence::class.java)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_UnterminatedControlSequence() {
+ val input = createSafeInputStream("[data")
+ assertThat(handler.parse(input)).isInstanceOf(NullControlSequence::class.java)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_MalformedControlSequence() {
+ val input = createSafeInputStream("32mdata")
+ assertThat(handler.parse(input)).isInstanceOf(NullControlSequence::class.java)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_SGR_Reset() {
+ val input = createSafeInputStream("[0m")
+ assertThat(handler.parse(input)).isEqualTo(RESET)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_SGR_Red() {
+ val input = createSafeInputStream("[31m")
+ assertThat(handler.parse(input)).isEqualTo(RED)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_SGR_Green() {
+ val input = createSafeInputStream("[32m")
+ assertThat(handler.parse(input)).isEqualTo(GREEN)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_SGR_Yellow() {
+ val input = createSafeInputStream("[33m")
+ assertThat(handler.parse(input)).isEqualTo(YELLOW)
+ }
+
+ @Test
+ fun parsedControlSequenceIsCorrectType_SGR_Purple() {
+ val input = createSafeInputStream("[35m")
+ assertThat(handler.parse(input)).isEqualTo(PURPLE)
+ }
+
+ @Test
+ fun parseMultipleControlSequences() {
+ val input = createSafeInputStream("[35m[32m[0m")
+ assertThat(handler.parse(input)).isEqualTo(PURPLE)
+ assertThat(handler.parse(input)).isEqualTo(GREEN)
+ assertThat(handler.parse(input)).isEqualTo(RESET)
+ }
+}
diff --git a/src/test/kotlin/terminal/ControlSequenceTest.java b/src/test/kotlin/terminal/ControlSequenceTest.java
deleted file mode 100644
index c6580a2..0000000
--- a/src/test/kotlin/terminal/ControlSequenceTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package terminal;
-
-import com.googlecode.lanterna.TextColor;
-import com.googlecode.lanterna.terminal.virtual.DefaultVirtualTerminal;
-import com.googlecode.lanterna.terminal.virtual.VirtualTerminal;
-import org.junit.Before;
-import org.junit.Test;
-import terminal.ControlSequence.NullControlSequence;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.isEmptyString;
-import static org.junit.Assert.assertThat;
-import static terminal.SelectGraphicRendition.GREEN;
-import static terminal.SelectGraphicRendition.PURPLE;
-import static terminal.SelectGraphicRendition.RED;
-import static terminal.SelectGraphicRendition.RESET;
-import static terminal.SelectGraphicRendition.YELLOW;
-
-public class ControlSequenceTest {
-
- private Set indicatorSet;
-
- private VirtualTerminal createTerminalWithIndicators() {
- return new DefaultVirtualTerminal() {
-
- @Override
- public void resetColorAndSGR() {
- indicatorSet.add("RESET");
- }
-
- @Override
- public void setForegroundColor(TextColor color) {
- indicatorSet.add(color.toString());
- }
- };
- }
-
- @Before
- public void setUp() {
- indicatorSet = new HashSet<>();
- }
-
- @Test
- public void nullControlSequenceDoesNothing() {
- ControlSequence nullControlSequence = new NullControlSequence();
- VirtualTerminal terminal = createTerminalWithIndicators();
- nullControlSequence.applyTo(terminal);
- assertThat(indicatorSet, empty());
- }
-
- @Test
- public void controlSequenceUpdatesTerminal_SGR_Reset() {
- VirtualTerminal terminal = createTerminalWithIndicators();
- RESET.applyTo(terminal);
- assertThat(indicatorSet, contains("RESET"));
- }
-
- @Test
- public void controlSequenceUpdatesTerminal_SGR_Red() {
- VirtualTerminal terminal = createTerminalWithIndicators();
- RED.applyTo(terminal);
- assertThat(indicatorSet, contains("RED"));
- }
-
- @Test
- public void controlSequenceUpdatesTerminal_SGR_Green() {
- VirtualTerminal terminal = createTerminalWithIndicators();
- GREEN.applyTo(terminal);
- assertThat(indicatorSet, contains("GREEN"));
- }
-
- @Test
- public void controlSequenceUpdatesTerminal_SGR_Yellow() {
- VirtualTerminal terminal = createTerminalWithIndicators();
- YELLOW.applyTo(terminal);
- assertThat(indicatorSet, contains("YELLOW"));
- }
-
- @Test
- public void controlSequenceUpdatesTerminal_SGR_Purple() {
- VirtualTerminal terminal = createTerminalWithIndicators();
- PURPLE.applyTo(terminal);
- assertThat(indicatorSet, contains("MAGENTA"));
- }
-
- @Test
- public void nullControlSequenceHasCorrectCode() {
- ControlSequence nullControlSequence = new NullControlSequence();
- assertThat(nullControlSequence.getCode(), isEmptyString());
- }
-
- @Test
- public void SelectGraphicRenditionEnumCoverage() {
- for (SelectGraphicRendition sgr : SelectGraphicRendition.values())
- SelectGraphicRendition.valueOf(sgr.toString());
- }
-}
diff --git a/src/test/kotlin/terminal/ControlSequenceTest.kt b/src/test/kotlin/terminal/ControlSequenceTest.kt
new file mode 100644
index 0000000..0b39135
--- /dev/null
+++ b/src/test/kotlin/terminal/ControlSequenceTest.kt
@@ -0,0 +1,87 @@
+package terminal
+
+import com.googlecode.lanterna.TextColor
+import com.googlecode.lanterna.terminal.virtual.DefaultVirtualTerminal
+import com.googlecode.lanterna.terminal.virtual.VirtualTerminal
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import terminal.ControlSequence.NullControlSequence
+import terminal.SelectGraphicRendition.GREEN
+import terminal.SelectGraphicRendition.PURPLE
+import terminal.SelectGraphicRendition.RED
+import terminal.SelectGraphicRendition.RESET
+import terminal.SelectGraphicRendition.YELLOW
+import java.util.HashSet
+
+class ControlSequenceTest {
+
+ private lateinit var indicatorSet: MutableSet
+
+ private fun createTerminalWithIndicators(): VirtualTerminal {
+ return object : DefaultVirtualTerminal() {
+
+ override fun resetColorAndSGR() {
+ indicatorSet.add("RESET")
+ }
+
+ override fun setForegroundColor(color: TextColor) {
+ indicatorSet.add(color.toString())
+ }
+ }
+ }
+
+ @BeforeEach
+ fun setUp() {
+ indicatorSet = HashSet()
+ }
+
+ @Test
+ fun nullControlSequenceDoesNothing() {
+ val nullControlSequence = NullControlSequence()
+ val terminal = createTerminalWithIndicators()
+ nullControlSequence.applyTo(terminal)
+ assertThat(indicatorSet).isEmpty()
+ }
+
+ @Test
+ fun controlSequenceUpdatesTerminal_SGR_Reset() {
+ val terminal = createTerminalWithIndicators()
+ RESET.applyTo(terminal)
+ assertThat(indicatorSet).contains("RESET")
+ }
+
+ @Test
+ fun controlSequenceUpdatesTerminal_SGR_Red() {
+ val terminal = createTerminalWithIndicators()
+ RED.applyTo(terminal)
+ assertThat(indicatorSet).contains("RED")
+ }
+
+ @Test
+ fun controlSequenceUpdatesTerminal_SGR_Green() {
+ val terminal = createTerminalWithIndicators()
+ GREEN.applyTo(terminal)
+ assertThat(indicatorSet).contains("GREEN")
+ }
+
+ @Test
+ fun controlSequenceUpdatesTerminal_SGR_Yellow() {
+ val terminal = createTerminalWithIndicators()
+ YELLOW.applyTo(terminal)
+ assertThat(indicatorSet).contains("YELLOW")
+ }
+
+ @Test
+ fun controlSequenceUpdatesTerminal_SGR_Purple() {
+ val terminal = createTerminalWithIndicators()
+ PURPLE.applyTo(terminal)
+ assertThat(indicatorSet).contains("MAGENTA")
+ }
+
+ @Test
+ fun nullControlSequenceHasCorrectCode() {
+ val nullControlSequence = NullControlSequence()
+ assertThat(nullControlSequence.code).isEmpty()
+ }
+}
diff --git a/src/test/kotlin/terminal/LispTerminalTest.java b/src/test/kotlin/terminal/LispTerminalTest.java
deleted file mode 100644
index 6e1df95..0000000
--- a/src/test/kotlin/terminal/LispTerminalTest.java
+++ /dev/null
@@ -1,494 +0,0 @@
-package terminal;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static com.googlecode.lanterna.input.KeyType.ArrowDown;
-import static com.googlecode.lanterna.input.KeyType.ArrowLeft;
-import static com.googlecode.lanterna.input.KeyType.ArrowRight;
-import static com.googlecode.lanterna.input.KeyType.ArrowUp;
-import static com.googlecode.lanterna.input.KeyType.Backspace;
-import static com.googlecode.lanterna.input.KeyType.Delete;
-import static com.googlecode.lanterna.input.KeyType.Enter;
-import static com.googlecode.lanterna.input.KeyType.Escape;
-import static terminal.LispTerminal.END_OF_SEGMENT;
-
-public class LispTerminalTest {
-
- private VirtualTerminalInteractor terminal;
-
- @Before
- public void setUp() {
- terminal = new VirtualTerminalInteractor();
- terminal.start();
- }
-
- @After
- public void tearDown() {
- terminal.stop();
- }
-
- @Test
- public void leftArrowDoesNotMovePastOrigin() {
- terminal.pressKey(ArrowLeft);
- terminal.assertCursorPosition(0, 0);
- }
-
- @Test
- public void leftArrowWorksAfterEnteringCharacters() {
- 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);
- }
-
- @Test
- public void leftArrowWorksAcrossRows() {
- terminal.setColumns(5);
- terminal.enterCharacters("123451");
- terminal.assertCursorPosition(1, 1);
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.assertCursorPosition(4, 0);
- }
-
- @Test
- public void rightArrowDoesNotMovePastEndOfInput() {
- terminal.pressKey(ArrowRight);
- terminal.assertCursorPosition(0, 0);
- }
-
- @Test
- public void rightArrowWorksAfterMovingLeft() {
- 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);
- }
-
- @Test
- public void rightArrowWorksAcrossRow() {
- 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);
- }
-
- @Test
- public void characterKeyIsEchoed() {
- terminal.enterCharacter('a');
- terminal.assertCursorPosition(1, 0);
- terminal.assertScreenText("a");
- }
-
- @Test
- public void characterIsInserted() {
- terminal.enterCharacters("abcd");
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.enterCharacter('x');
- terminal.assertScreenText("abxcd");
- }
-
- @Test
- public void characterIsInserted_PushesInputToNextRow() {
- terminal.setColumns(4);
- terminal.enterCharacters("abcd");
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.enterCharacter('x');
- terminal.assertScreenText("abxc", "d ");
- }
-
- @Test
- public void backspaceDoesNothingAtOrigin() {
- terminal.pressKey(Backspace);
- terminal.assertCursorPosition(0, 0);
- }
-
- @Test
- public void backspaceWorksAfterInput() {
- terminal.enterCharacters("12345");
- terminal.pressKeyTimes(Backspace, 2);
- terminal.assertCursorPosition(3, 0);
- terminal.assertScreenText("123 ");
- }
-
- @Test
- public void backspaceWorksAcrossRow() {
- terminal.setColumns(4);
- terminal.enterCharacters("1234567");
- terminal.pressKeyTimes(Backspace, 5);
- terminal.assertCursorPosition(2, 0);
- terminal.assertScreenText("12 ", " ");
- }
-
- @Test
- public void backspaceWorksInMiddleOfInput() {
- terminal.enterCharacters("12345");
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.pressKey(Backspace);
- terminal.assertCursorPosition(2, 0);
- terminal.assertScreenText("1245");
- }
-
- @Test
- public void deleteDoesNothingAtOrigin() {
- terminal.pressKey(Delete);
- terminal.assertCursorPosition(0, 0);
- }
-
- @Test
- public void deleteDoesNothingAtEndOfInput() {
- terminal.enterCharacters("del");
- terminal.pressKey(Delete);
- terminal.assertCursorPosition(3, 0);
- terminal.assertScreenText("del");
- }
-
- @Test
- public void deleteWorksAtStartOfInput() {
- terminal.enterCharacters("del");
- terminal.pressKeyTimes(ArrowLeft, 3);
- terminal.pressKeyTimes(Delete, 3);
- terminal.assertCursorPosition(0, 0);
- terminal.assertScreenText(" ");
- }
-
- @Test
- public void deleteWorksAcrossRow() {
- terminal.setColumns(4);
- terminal.enterCharacters("delete");
- terminal.pressKeyTimes(ArrowLeft, 5);
- terminal.pressKey(Delete);
- terminal.assertCursorPosition(1, 0);
- terminal.assertScreenText("dlet", "e ");
- }
-
- @Test
- public void enterMovesToNextLine() {
- terminal.pressKey(Enter);
- terminal.assertCursorPosition(0, 1);
- }
-
- @Test
- public void enterWritesLineToPipedStream() {
- terminal.enterCharacters("enter");
- terminal.pressKey(Enter);
- terminal.assertInputWritten("enter\n");
- }
-
- @Test
- public void enterPressedInMiddleOfInput_WritesEntireLineToPipedStream() {
- terminal.enterCharacters("enter");
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.pressKey(Enter);
- terminal.assertInputWritten("enter\n");
- }
-
- @Test
- public void enterAfterInsertedText_WritesLineToPipedStream() {
- terminal.enterCharacters("enter");
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.enterCharacters("||");
- terminal.pressKey(Enter);
- terminal.assertInputWritten("ent||er\n");
- }
-
- @Test
- public void enterAfterBackspace_WritesLineToPipedStream() {
- terminal.enterCharacters("enter");
- terminal.pressKeyTimes(Backspace, 2);
- terminal.pressKey(Enter);
- terminal.assertInputWritten("ent\n");
- }
-
- @Test
- public void enterAfterDelete_WritesLineToPipedStream() {
- terminal.enterCharacters("enter");
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.pressKeyTimes(Delete, 2);
- terminal.pressKey(Enter);
- terminal.assertInputWritten("ent\n");
- }
-
- @Test
- public void controlDWorks() {
- terminal.enterCharacters("control-d");
- terminal.enterControlCharacter('d');
- terminal.assertInputStreamClosed();
- terminal.assertInputWritten("control-d\n");
- }
-
- @Test
- public void controlDWorksInMiddleOfInput() {
- terminal.enterCharacters("control-d");
- terminal.pressKeyTimes(ArrowLeft, 2);
- terminal.enterControlCharacter('d');
- terminal.assertInputStreamClosed();
- terminal.assertInputWritten("control-d\n");
- }
-
- @Test
- public void escapeDoesNothing() {
- terminal.pressKey(Escape);
- terminal.assertCursorPosition(0, 0);
- terminal.assertInputWritten("");
- }
-
- @Test
- public void controlQDoesNothing() {
- terminal.enterControlCharacter('q');
- terminal.assertCursorPosition(0, 0);
- terminal.assertInputWritten("");
- }
-
- @Test
- public void controlEnterDoesNothing() {
- terminal.pressControlKey(Enter);
- terminal.assertCursorPosition(0, 0);
- terminal.assertInputWritten("");
- }
-
- @Test
- public void outputIsWritten() {
- terminal.produceOutput("output");
- terminal.assertCursorPosition(6, 0);
- terminal.assertScreenText("output");
- }
-
- @Test
- public void endOfSegmentCharacterIsNotPrinted() {
- terminal.produceOutput("> " + END_OF_SEGMENT);
- terminal.assertCursorPosition(2, 0);
- terminal.assertScreenText("> ");
- }
-
- @Test
- public void enterTextPastLastLineOfBuffer() {
- terminal.setColumns(3);
- terminal.setRows(2);
- terminal.enterCharacters("01201201");
- terminal.assertCursorPosition(2, 1);
- terminal.assertScreenText("012", "01 ");
- }
-
- @Test
- public void insertingTextPushesInputPastEndOfBuffer() {
- 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.assertScreenText("000", "1zz", "112", "2 ");
- }
-
- @Test
- public void insertingTextDoesNothingWhenBufferFilled() {
- 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.assertScreenText("000", "111", "22 ");
- }
-
- @Test
- public void appendingTextDoesNothingWhenBufferFilled() {
- terminal.setColumns(3);
- terminal.setRows(3);
- terminal.enterCharacters("000111222333444");
- terminal.assertCursorPosition(2, 2);
- terminal.assertScreenText("000", "111", "22 ");
- }
-
- @Test
- public void printedOutputToEndOfRow_MovesCursorToNextRow() {
- terminal.setColumns(3);
- terminal.produceOutput("out");
- terminal.assertCursorPosition(0, 1);
- }
-
- @Test
- public void printedOutputToEndOfBuffer_MovesCursorToNewRow() {
- terminal.setColumns(3);
- terminal.setRows(2);
- terminal.produceOutput("output");
- terminal.assertCursorPosition(0, 1);
- terminal.assertScreenText("put", " ");
- }
-
- @Test
- public void outputDoesNotOverwriteInput_AndRedisplaysInput() {
- terminal.setColumns(3);
- terminal.enterCharacters("0123");
- terminal.pressKeyTimes(ArrowLeft, 3);
- terminal.produceOutput("out");
- terminal.assertCursorPosition(2, 3);
- terminal.assertScreenText("012", "3ou", "t01", "23 ", " ");
- }
-
- @Test
- public void outputEndsOnSecondToLastColumn_MovesToNewRow() {
- terminal.setColumns(3);
- terminal.enterCharacters("01234");
- terminal.pressKeyTimes(ArrowLeft, 3);
- terminal.produceOutput("out");
- terminal.assertCursorPosition(2, 4);
- terminal.assertScreenText("012", "34o", "ut ", "012", "34 ");
- }
-
- @Test
- public void outputEndsOnLastColumn_MovesToNewRow() {
- terminal.setColumns(3);
- terminal.enterCharacters("012345");
- terminal.pressKeyTimes(ArrowLeft, 3);
- terminal.produceOutput("out");
- terminal.assertCursorPosition(0, 5);
- terminal.assertScreenText("012", "345", "out", "012", "345", " ");
- }
-
- @Test
- public void outputRedisplaysInputAtEndOfBuffer() {
- terminal.setColumns(3);
- terminal.setRows(4);
- terminal.enterCharacters("01234");
- terminal.pressKeyTimes(ArrowLeft, 3);
- terminal.produceOutput("out");
- terminal.assertCursorPosition(2, 3);
- terminal.assertScreenText("34o", "ut ", "012");
- }
-
- @Test
- public void outputDoesNotOverwriteInput_AfterEnter() {
- terminal.setColumns(3);
- terminal.enterCharacters("01201201");
- terminal.pressKeyTimes(ArrowLeft, 5);
- terminal.pressKey(Enter);
- terminal.produceOutput("out");
- terminal.assertCursorPosition(0, 4);
- terminal.assertScreenText("012", "012", "01 ", "out", " ");
- }
-
- @Test
- public void resizeIsHandledGracefully() {
- terminal.enterCharacters("resize");
- terminal.pressKey(Enter);
- terminal.enterCharacters("test");
- terminal.setColumns(3);
- terminal.assertCursorPosition(1, 1);
- terminal.assertScreenText("tes", "t ");
- }
-
- @Test
- public void backspaceWorksAfterResize() {
- terminal.enterCharacters("resize");
- terminal.pressKey(Enter);
- terminal.enterCharacters("test");
- terminal.setColumns(3);
- terminal.pressKeyTimes(Backspace, 20);
- terminal.assertCursorPosition(0, 0);
- terminal.assertScreenText(" ", " ");
- }
-
- @Test
- public void deleteWorksAfterResize() {
- 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.assertScreenText(" ", " ");
- }
-
- @Test
- public void controlSequencesAreNotPrinted() {
- terminal.produceOutput("\u001B[32mcontrol\u001B[0mseq");
- terminal.assertScreenText("controlseq");
- }
-
- @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);
- }
-}
diff --git a/src/test/kotlin/terminal/LispTerminalTest.kt b/src/test/kotlin/terminal/LispTerminalTest.kt
new file mode 100644
index 0000000..d4629ee
--- /dev/null
+++ b/src/test/kotlin/terminal/LispTerminalTest.kt
@@ -0,0 +1,493 @@
+package terminal
+
+import com.googlecode.lanterna.input.KeyType.ArrowDown
+import com.googlecode.lanterna.input.KeyType.ArrowLeft
+import com.googlecode.lanterna.input.KeyType.ArrowRight
+import com.googlecode.lanterna.input.KeyType.ArrowUp
+import com.googlecode.lanterna.input.KeyType.Backspace
+import com.googlecode.lanterna.input.KeyType.Delete
+import com.googlecode.lanterna.input.KeyType.Enter
+import com.googlecode.lanterna.input.KeyType.Escape
+import org.junit.jupiter.api.AfterEach
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import terminal.LispTerminal.END_OF_SEGMENT
+
+class LispTerminalTest {
+
+ private lateinit var terminal: VirtualTerminalInteractor
+
+ @BeforeEach
+ fun setUp() {
+ terminal = VirtualTerminalInteractor()
+ terminal.start()
+ }
+
+ @AfterEach
+ fun tearDown() {
+ terminal.stop()
+ }
+
+ @Test
+ fun leftArrowDoesNotMovePastOrigin() {
+ terminal.pressKey(ArrowLeft)
+ terminal.assertCursorPosition(0, 0)
+ }
+
+ @Test
+ fun leftArrowWorksAfterEnteringCharacters() {
+ 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)
+ }
+
+ @Test
+ fun leftArrowWorksAcrossRows() {
+ terminal.setColumns(5)
+ terminal.enterCharacters("123451")
+ terminal.assertCursorPosition(1, 1)
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.assertCursorPosition(4, 0)
+ }
+
+ @Test
+ fun rightArrowDoesNotMovePastEndOfInput() {
+ terminal.pressKey(ArrowRight)
+ terminal.assertCursorPosition(0, 0)
+ }
+
+ @Test
+ fun rightArrowWorksAfterMovingLeft() {
+ 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)
+ }
+
+ @Test
+ fun rightArrowWorksAcrossRow() {
+ 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)
+ }
+
+ @Test
+ fun characterKeyIsEchoed() {
+ terminal.enterCharacter('a')
+ terminal.assertCursorPosition(1, 0)
+ terminal.assertScreenText("a")
+ }
+
+ @Test
+ fun characterIsInserted() {
+ terminal.enterCharacters("abcd")
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.enterCharacter('x')
+ terminal.assertScreenText("abxcd")
+ }
+
+ @Test
+ fun characterIsInserted_PushesInputToNextRow() {
+ terminal.setColumns(4)
+ terminal.enterCharacters("abcd")
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.enterCharacter('x')
+ terminal.assertScreenText("abxc", "d ")
+ }
+
+ @Test
+ fun backspaceDoesNothingAtOrigin() {
+ terminal.pressKey(Backspace)
+ terminal.assertCursorPosition(0, 0)
+ }
+
+ @Test
+ fun backspaceWorksAfterInput() {
+ terminal.enterCharacters("12345")
+ terminal.pressKeyTimes(Backspace, 2)
+ terminal.assertCursorPosition(3, 0)
+ terminal.assertScreenText("123 ")
+ }
+
+ @Test
+ fun backspaceWorksAcrossRow() {
+ terminal.setColumns(4)
+ terminal.enterCharacters("1234567")
+ terminal.pressKeyTimes(Backspace, 5)
+ terminal.assertCursorPosition(2, 0)
+ terminal.assertScreenText("12 ", " ")
+ }
+
+ @Test
+ fun backspaceWorksInMiddleOfInput() {
+ terminal.enterCharacters("12345")
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.pressKey(Backspace)
+ terminal.assertCursorPosition(2, 0)
+ terminal.assertScreenText("1245")
+ }
+
+ @Test
+ fun deleteDoesNothingAtOrigin() {
+ terminal.pressKey(Delete)
+ terminal.assertCursorPosition(0, 0)
+ }
+
+ @Test
+ fun deleteDoesNothingAtEndOfInput() {
+ terminal.enterCharacters("del")
+ terminal.pressKey(Delete)
+ terminal.assertCursorPosition(3, 0)
+ terminal.assertScreenText("del")
+ }
+
+ @Test
+ fun deleteWorksAtStartOfInput() {
+ terminal.enterCharacters("del")
+ terminal.pressKeyTimes(ArrowLeft, 3)
+ terminal.pressKeyTimes(Delete, 3)
+ terminal.assertCursorPosition(0, 0)
+ terminal.assertScreenText(" ")
+ }
+
+ @Test
+ fun deleteWorksAcrossRow() {
+ terminal.setColumns(4)
+ terminal.enterCharacters("delete")
+ terminal.pressKeyTimes(ArrowLeft, 5)
+ terminal.pressKey(Delete)
+ terminal.assertCursorPosition(1, 0)
+ terminal.assertScreenText("dlet", "e ")
+ }
+
+ @Test
+ fun enterMovesToNextLine() {
+ terminal.pressKey(Enter)
+ terminal.assertCursorPosition(0, 1)
+ }
+
+ @Test
+ fun enterWritesLineToPipedStream() {
+ terminal.enterCharacters("enter")
+ terminal.pressKey(Enter)
+ terminal.assertInputWritten("enter\n")
+ }
+
+ @Test
+ fun enterPressedInMiddleOfInput_WritesEntireLineToPipedStream() {
+ terminal.enterCharacters("enter")
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.pressKey(Enter)
+ terminal.assertInputWritten("enter\n")
+ }
+
+ @Test
+ fun enterAfterInsertedText_WritesLineToPipedStream() {
+ terminal.enterCharacters("enter")
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.enterCharacters("||")
+ terminal.pressKey(Enter)
+ terminal.assertInputWritten("ent||er\n")
+ }
+
+ @Test
+ fun enterAfterBackspace_WritesLineToPipedStream() {
+ terminal.enterCharacters("enter")
+ terminal.pressKeyTimes(Backspace, 2)
+ terminal.pressKey(Enter)
+ terminal.assertInputWritten("ent\n")
+ }
+
+ @Test
+ fun enterAfterDelete_WritesLineToPipedStream() {
+ terminal.enterCharacters("enter")
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.pressKeyTimes(Delete, 2)
+ terminal.pressKey(Enter)
+ terminal.assertInputWritten("ent\n")
+ }
+
+ @Test
+ fun controlDWorks() {
+ terminal.enterCharacters("control-d")
+ terminal.enterControlCharacter('d')
+ terminal.assertInputStreamClosed()
+ terminal.assertInputWritten("control-d\n")
+ }
+
+ @Test
+ fun controlDWorksInMiddleOfInput() {
+ terminal.enterCharacters("control-d")
+ terminal.pressKeyTimes(ArrowLeft, 2)
+ terminal.enterControlCharacter('d')
+ terminal.assertInputStreamClosed()
+ terminal.assertInputWritten("control-d\n")
+ }
+
+ @Test
+ fun escapeDoesNothing() {
+ terminal.pressKey(Escape)
+ terminal.assertCursorPosition(0, 0)
+ terminal.assertInputWritten("")
+ }
+
+ @Test
+ fun controlQDoesNothing() {
+ terminal.enterControlCharacter('q')
+ terminal.assertCursorPosition(0, 0)
+ terminal.assertInputWritten("")
+ }
+
+ @Test
+ fun controlEnterDoesNothing() {
+ terminal.pressControlKey(Enter)
+ terminal.assertCursorPosition(0, 0)
+ terminal.assertInputWritten("")
+ }
+
+ @Test
+ fun outputIsWritten() {
+ terminal.produceOutput("output")
+ terminal.assertCursorPosition(6, 0)
+ terminal.assertScreenText("output")
+ }
+
+ @Test
+ fun endOfSegmentCharacterIsNotPrinted() {
+ terminal.produceOutput("> $END_OF_SEGMENT")
+ terminal.assertCursorPosition(2, 0)
+ terminal.assertScreenText("> ")
+ }
+
+ @Test
+ fun enterTextPastLastLineOfBuffer() {
+ terminal.setColumns(3)
+ terminal.setRows(2)
+ terminal.enterCharacters("01201201")
+ terminal.assertCursorPosition(2, 1)
+ terminal.assertScreenText("012", "01 ")
+ }
+
+ @Test
+ fun insertingTextPushesInputPastEndOfBuffer() {
+ 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.assertScreenText("000", "1zz", "112", "2 ")
+ }
+
+ @Test
+ fun insertingTextDoesNothingWhenBufferFilled() {
+ 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.assertScreenText("000", "111", "22 ")
+ }
+
+ @Test
+ fun appendingTextDoesNothingWhenBufferFilled() {
+ terminal.setColumns(3)
+ terminal.setRows(3)
+ terminal.enterCharacters("000111222333444")
+ terminal.assertCursorPosition(2, 2)
+ terminal.assertScreenText("000", "111", "22 ")
+ }
+
+ @Test
+ fun printedOutputToEndOfRow_MovesCursorToNextRow() {
+ terminal.setColumns(3)
+ terminal.produceOutput("out")
+ terminal.assertCursorPosition(0, 1)
+ }
+
+ @Test
+ fun printedOutputToEndOfBuffer_MovesCursorToNewRow() {
+ terminal.setColumns(3)
+ terminal.setRows(2)
+ terminal.produceOutput("output")
+ terminal.assertCursorPosition(0, 1)
+ terminal.assertScreenText("put", " ")
+ }
+
+ @Test
+ fun outputDoesNotOverwriteInput_AndRedisplaysInput() {
+ terminal.setColumns(3)
+ terminal.enterCharacters("0123")
+ terminal.pressKeyTimes(ArrowLeft, 3)
+ terminal.produceOutput("out")
+ terminal.assertCursorPosition(2, 3)
+ terminal.assertScreenText("012", "3ou", "t01", "23 ", " ")
+ }
+
+ @Test
+ fun outputEndsOnSecondToLastColumn_MovesToNewRow() {
+ terminal.setColumns(3)
+ terminal.enterCharacters("01234")
+ terminal.pressKeyTimes(ArrowLeft, 3)
+ terminal.produceOutput("out")
+ terminal.assertCursorPosition(2, 4)
+ terminal.assertScreenText("012", "34o", "ut ", "012", "34 ")
+ }
+
+ @Test
+ fun outputEndsOnLastColumn_MovesToNewRow() {
+ terminal.setColumns(3)
+ terminal.enterCharacters("012345")
+ terminal.pressKeyTimes(ArrowLeft, 3)
+ terminal.produceOutput("out")
+ terminal.assertCursorPosition(0, 5)
+ terminal.assertScreenText("012", "345", "out", "012", "345", " ")
+ }
+
+ @Test
+ fun outputRedisplaysInputAtEndOfBuffer() {
+ terminal.setColumns(3)
+ terminal.setRows(4)
+ terminal.enterCharacters("01234")
+ terminal.pressKeyTimes(ArrowLeft, 3)
+ terminal.produceOutput("out")
+ terminal.assertCursorPosition(2, 3)
+ terminal.assertScreenText("34o", "ut ", "012")
+ }
+
+ @Test
+ fun outputDoesNotOverwriteInput_AfterEnter() {
+ terminal.setColumns(3)
+ terminal.enterCharacters("01201201")
+ terminal.pressKeyTimes(ArrowLeft, 5)
+ terminal.pressKey(Enter)
+ terminal.produceOutput("out")
+ terminal.assertCursorPosition(0, 4)
+ terminal.assertScreenText("012", "012", "01 ", "out", " ")
+ }
+
+ @Test
+ fun resizeIsHandledGracefully() {
+ terminal.enterCharacters("resize")
+ terminal.pressKey(Enter)
+ terminal.enterCharacters("test")
+ terminal.setColumns(3)
+ terminal.assertCursorPosition(1, 1)
+ terminal.assertScreenText("tes", "t ")
+ }
+
+ @Test
+ fun backspaceWorksAfterResize() {
+ terminal.enterCharacters("resize")
+ terminal.pressKey(Enter)
+ terminal.enterCharacters("test")
+ terminal.setColumns(3)
+ terminal.pressKeyTimes(Backspace, 20)
+ terminal.assertCursorPosition(0, 0)
+ terminal.assertScreenText(" ", " ")
+ }
+
+ @Test
+ fun deleteWorksAfterResize() {
+ 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.assertScreenText(" ", " ")
+ }
+
+ @Test
+ fun controlSequencesAreNotPrinted() {
+ terminal.produceOutput("\u001B[32mcontrol\u001B[0mseq")
+ terminal.assertScreenText("controlseq")
+ }
+
+ @Test
+ fun 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
+ fun 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
+ fun 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
+ fun 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
+ fun 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
+ fun downArrowStopsAtLastLine() {
+ terminal.pressKeyTimes(ArrowDown, 5)
+ terminal.assertScreenText(" ")
+ terminal.assertCursorPosition(0, 0)
+ }
+}
diff --git a/src/test/kotlin/terminal/VirtualTerminalInteractor.java b/src/test/kotlin/terminal/VirtualTerminalInteractor.java
index ef932ad..847f512 100644
--- a/src/test/kotlin/terminal/VirtualTerminalInteractor.java
+++ b/src/test/kotlin/terminal/VirtualTerminalInteractor.java
@@ -12,8 +12,7 @@ import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static terminal.LispTerminal.END_OF_SEGMENT;
@@ -138,8 +137,8 @@ public class VirtualTerminalInteractor {
}
public void assertCursorPosition(int column, int row) {
- assertThat(virtualTerminal.getCursorPosition().getColumn(), is(column));
- assertThat(virtualTerminal.getCursorPosition().getRow(), is(row));
+ assertThat(virtualTerminal.getCursorPosition().getColumn()).isEqualTo(column);
+ assertThat(virtualTerminal.getCursorPosition().getRow()).isEqualTo(row);
}
public void assertScreenText(String... rows) {
@@ -152,7 +151,7 @@ public class VirtualTerminalInteractor {
TerminalPosition position = new TerminalPosition(column, row);
String expected = String.valueOf(character);
String actual = String.valueOf(virtualTerminal.getCharacter(position).getCharacter());
- assertThat(actual, is(expected));
+ assertThat(actual).isEqualTo(expected);
}
public void assertInputWritten(String expected) {
@@ -166,7 +165,7 @@ public class VirtualTerminalInteractor {
} catch (IOException ignored) {
}
- assertThat(actual, is(expected));
+ assertThat(actual).isEqualTo(expected);
}
public void assertInputStreamClosed() {