mirror of
https://github.com/walles/moar.git
synced 2024-11-09 17:40:09 +03:00
Add tests for ANSI foreground color support
This commit is contained in:
parent
86007b3293
commit
0336c55a71
@ -18,16 +18,66 @@ func TestUnicodeRendering(t *testing.T) {
|
||||
pager.Quit()
|
||||
pager.StartPaging(screen)
|
||||
|
||||
contents, _, _ := screen.GetContents()
|
||||
s := ""
|
||||
for i := 0; i <= 2; i++ {
|
||||
cell := contents[i]
|
||||
for _, r := range cell.Runes {
|
||||
s += string(r)
|
||||
}
|
||||
var answers = []_ExpectedCell{
|
||||
_CreateExpectedCell('å', tcell.StyleDefault),
|
||||
_CreateExpectedCell('ä', tcell.StyleDefault),
|
||||
_CreateExpectedCell('ö', tcell.StyleDefault),
|
||||
}
|
||||
|
||||
if s != "åäö" {
|
||||
t.Errorf("Expected 'åäö', got: <%s>", s)
|
||||
contents, _, _ := screen.GetContents()
|
||||
for pos, expected := range answers {
|
||||
expected.LogDifference(t, contents[pos])
|
||||
}
|
||||
}
|
||||
|
||||
type _ExpectedCell struct {
|
||||
Rune rune
|
||||
Style tcell.Style
|
||||
}
|
||||
|
||||
func (expected _ExpectedCell) LogDifference(t *testing.T, actual tcell.SimCell) {
|
||||
if actual.Runes[0] == expected.Rune && actual.Style == expected.Style {
|
||||
return
|
||||
}
|
||||
|
||||
t.Errorf("Expected '%s'/0x%x, got '%s'/0x%x",
|
||||
string(expected.Rune), expected.Style,
|
||||
string(actual.Runes[0]), actual.Style)
|
||||
}
|
||||
|
||||
func _CreateExpectedCell(Rune rune, Style tcell.Style) _ExpectedCell {
|
||||
return _ExpectedCell{
|
||||
Rune: Rune,
|
||||
Style: Style,
|
||||
}
|
||||
}
|
||||
|
||||
func TestFgColorRendering(t *testing.T) {
|
||||
reader, err := NewReaderFromStream(strings.NewReader(
|
||||
"\x1b[30ma\x1b[31mb\x1b[32mc\x1b[33md\x1b[34me\x1b[35mf\x1b[36mg\x1b[37mh\x1b[0mi"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
screen := tcell.NewSimulationScreen("UTF-8")
|
||||
pager := NewPager(*reader)
|
||||
pager.Quit()
|
||||
pager.StartPaging(screen)
|
||||
|
||||
var answers = []_ExpectedCell{
|
||||
_CreateExpectedCell('a', tcell.StyleDefault.Foreground(tcell.ColorBlack)),
|
||||
_CreateExpectedCell('b', tcell.StyleDefault.Foreground(tcell.ColorRed)),
|
||||
_CreateExpectedCell('c', tcell.StyleDefault.Foreground(tcell.ColorGreen)),
|
||||
_CreateExpectedCell('d', tcell.StyleDefault.Foreground(tcell.ColorYellow)),
|
||||
_CreateExpectedCell('e', tcell.StyleDefault.Foreground(tcell.ColorBlue)),
|
||||
_CreateExpectedCell('f', tcell.StyleDefault.Foreground(tcell.ColorPurple)),
|
||||
_CreateExpectedCell('g', tcell.StyleDefault.Foreground(tcell.ColorTeal)),
|
||||
_CreateExpectedCell('h', tcell.StyleDefault.Foreground(tcell.ColorWhite)),
|
||||
_CreateExpectedCell('i', tcell.StyleDefault),
|
||||
}
|
||||
|
||||
contents, _, _ := screen.GetContents()
|
||||
for pos, expected := range answers {
|
||||
expected.LogDifference(t, contents[pos])
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user