2017-03-22 11:26:53 -04:00
|
|
|
package terminal;
|
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
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-03-22 11:26:53 -04:00
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2017-03-22 11:26:53 -04:00
|
|
|
|
2017-11-12 09:42:25 -05:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2017-03-22 11:26:53 -04:00
|
|
|
|
|
|
|
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;
|
2017-03-22 11:26:53 -04:00
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2017-03-23 12:14:44 -04:00
|
|
|
@Test
|
|
|
|
public void nullControlSequenceHasCorrectCode() {
|
|
|
|
ControlSequence nullControlSequence = new NullControlSequence();
|
|
|
|
assertEquals("", nullControlSequence.getCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void SelectGraphicRenditionEnumCoverage() {
|
|
|
|
for (SelectGraphicRendition sgr : SelectGraphicRendition.values())
|
|
|
|
SelectGraphicRendition.valueOf(sgr.toString());
|
|
|
|
}
|
|
|
|
|
2017-03-22 11:26:53 -04:00
|
|
|
}
|