transcendental-lisp/test/terminal/ControlSequenceTest.java

95 lines
2.7 KiB
Java

package terminal;
import static org.junit.Assert.*;
import static terminal.SelectGraphicRendition.*;
import java.util.*;
import org.junit.*;
import com.googlecode.lanterna.TextColor;
import com.googlecode.lanterna.terminal.virtual.*;
import terminal.ControlSequence.NullControlSequence;
public class ControlSequenceTest {
private Set<String> 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);
assertTrue(indicatorSet.isEmpty());
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Reset() {
VirtualTerminal terminal = createTerminalWithIndicators();
RESET.applyTo(terminal);
assertTrue(indicatorSet.contains("RESET"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Red() {
VirtualTerminal terminal = createTerminalWithIndicators();
RED.applyTo(terminal);
assertTrue(indicatorSet.contains("RED"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Green() {
VirtualTerminal terminal = createTerminalWithIndicators();
GREEN.applyTo(terminal);
assertTrue(indicatorSet.contains("GREEN"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Yellow() {
VirtualTerminal terminal = createTerminalWithIndicators();
YELLOW.applyTo(terminal);
assertTrue(indicatorSet.contains("YELLOW"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Purple() {
VirtualTerminal terminal = createTerminalWithIndicators();
PURPLE.applyTo(terminal);
assertTrue(indicatorSet.contains("MAGENTA"));
}
@Test
public void nullControlSequenceHasCorrectCode() {
ControlSequence nullControlSequence = new NullControlSequence();
assertEquals("", nullControlSequence.getCode());
}
@Test
public void SelectGraphicRenditionEnumCoverage() {
for (SelectGraphicRendition sgr : SelectGraphicRendition.values())
SelectGraphicRendition.valueOf(sgr.toString());
}
}