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-23 11:35:28 -05:00
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
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() {
2017-11-23 11:35:28 -05:00
assertThat(history.isBeginning(), is(true));
2017-04-04 07:56:35 -04:00
}
private void assertAtEnd() {
2017-11-23 11:35:28 -05:00
assertThat(history.isEnd(), is(true));
2017-04-04 07:56:35 -04:00
}
private void assertPrevious(String expected) {
2017-11-23 11:35:28 -05:00
assertThat(history.getPreviousLine(), is(expected));
2017-04-04 07:56:35 -04:00
}
private void assertNext(String expected) {
2017-11-23 11:35:28 -05:00
assertThat(history.getNextLine(), is(expected));
2017-04-04 07:56:35 -04:00
}
@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
}
}