transcendental-lisp/test/terminal/ControlSequenceTest.java

105 lines
3.2 KiB
Java
Raw Normal View History

package terminal;
2017-11-23 11:35:28 -05:00
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.isEmptyString;
import static org.junit.Assert.assertThat;
2017-11-12 09:42:25 -05:00
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;
2017-11-12 09:42:25 -05:00
import java.util.HashSet;
import java.util.Set;
2017-11-12 09:42:25 -05:00
import org.junit.Before;
import org.junit.Test;
import com.googlecode.lanterna.TextColor;
2017-11-12 09:42:25 -05:00
import com.googlecode.lanterna.terminal.virtual.DefaultVirtualTerminal;
import com.googlecode.lanterna.terminal.virtual.VirtualTerminal;
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);
2017-11-23 11:35:28 -05:00
assertThat(indicatorSet, empty());
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Reset() {
VirtualTerminal terminal = createTerminalWithIndicators();
RESET.applyTo(terminal);
2017-11-23 11:35:28 -05:00
assertThat(indicatorSet, contains("RESET"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Red() {
VirtualTerminal terminal = createTerminalWithIndicators();
RED.applyTo(terminal);
2017-11-23 11:35:28 -05:00
assertThat(indicatorSet, contains("RED"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Green() {
VirtualTerminal terminal = createTerminalWithIndicators();
GREEN.applyTo(terminal);
2017-11-23 11:35:28 -05:00
assertThat(indicatorSet, contains("GREEN"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Yellow() {
VirtualTerminal terminal = createTerminalWithIndicators();
YELLOW.applyTo(terminal);
2017-11-23 11:35:28 -05:00
assertThat(indicatorSet, contains("YELLOW"));
}
@Test
public void controlSequenceUpdatesTerminal_SGR_Purple() {
VirtualTerminal terminal = createTerminalWithIndicators();
PURPLE.applyTo(terminal);
2017-11-23 11:35:28 -05:00
assertThat(indicatorSet, contains("MAGENTA"));
}
@Test
public void nullControlSequenceHasCorrectCode() {
ControlSequence nullControlSequence = new NullControlSequence();
2017-11-23 11:35:28 -05:00
assertThat(nullControlSequence.getCode(), isEmptyString());
}
@Test
public void SelectGraphicRenditionEnumCoverage() {
for (SelectGraphicRendition sgr : SelectGraphicRendition.values())
SelectGraphicRendition.valueOf(sgr.toString());
}
}