105 lines
3.2 KiB
Java
105 lines
3.2 KiB
Java
package terminal;
|
|
|
|
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;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import com.googlecode.lanterna.TextColor;
|
|
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);
|
|
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());
|
|
}
|
|
|
|
}
|