transcendental-lisp/test/terminal/TerminalHistoryTest.java

141 lines
3.1 KiB
Java
Raw Normal View History

2017-04-04 07:56:35 -04:00
package terminal;
2017-11-12 09:42:25 -05:00
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
2017-04-04 07:56:35 -04:00
2017-11-12 09:42:25 -05:00
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
2017-04-04 07:56:35 -04:00
public class TerminalHistoryTest {
private TerminalHistory history;
private void assertAtBeginning() {
assertTrue(history.isBeginning());
2017-04-04 07:56:35 -04:00
}
private void assertAtEnd() {
assertTrue(history.isEnd());
2017-04-04 07:56:35 -04:00
}
private void assertPrevious(String expected) {
assertEquals(expected, history.getPreviousLine());
}
private void assertNext(String expected) {
assertEquals(expected, history.getNextLine());
}
@Before
public void setUp() {
history = new TerminalHistory();
}
@After
public void tearDown() {}
@Test
public void historyStartsWithNoLines() {
assertAtBeginning();
assertAtEnd();
}
@Test
public void addOneLineToHistory() {
history.addLine("test line");
assertPrevious("test line");
assertAtBeginning();
}
@Test
public void currentLineIsEmpty() {
history.addLine("one");
history.getPreviousLine();
assertNext("");
2017-04-04 07:56:35 -04:00
}
@Test
public void moveBackwards() {
history.addLine("one");
history.addLine("two");
assertPrevious("two");
assertPrevious("one");
assertAtBeginning();
}
@Test
public void moveForwards() {
history.addLine("one");
history.addLine("two");
history.getPreviousLine();
history.getPreviousLine();
assertNext("two");
assertNext("");
2017-04-04 07:56:35 -04:00
assertAtEnd();
}
@Test
public void addedLineGoesAtEndOfHistory() {
2017-04-04 07:56:35 -04:00
history.addLine("one");
history.addLine("two");
history.getPreviousLine();
history.getPreviousLine();
history.addLine("three");
2017-04-04 07:56:35 -04:00
assertPrevious("three");
2017-04-04 07:56:35 -04:00
assertPrevious("two");
assertPrevious("one");
assertAtBeginning();
}
@Test
public void currentLineIsUpdated() {
history.addLine("one");
history.updateCurrentLine("purple");
history.getPreviousLine();
assertNext("purple");
}
@Test
public void previousLineIsUpdated() {
2017-04-04 07:56:35 -04:00
history.addLine("one");
history.addLine("two");
history.getPreviousLine();
history.updateCurrentLine("purple");
history.getPreviousLine();
assertNext("purple");
}
@Test
public void goingPastFirstLine_KeepsReturningFirstLine() {
history.addLine("one");
history.addLine("two");
history.getPreviousLine();
history.getPreviousLine();
history.getPreviousLine();
history.getPreviousLine();
2017-04-04 07:56:35 -04:00
history.getPreviousLine();
assertPrevious("one");
}
@Test
public void goingPastLastLine_KeepsReturningLastLine() {
history.updateCurrentLine("current");
history.getNextLine();
history.getNextLine();
history.getNextLine();
history.getNextLine();
assertNext("current");
2017-04-04 07:56:35 -04:00
}
}