lf/colors_test.go
Provessor 24f01f4988
Replace termbox-go with tcell (#439)
Fix colour construction issue

This also has a test to mitigate it in the future

Remove `colormode` option

The original issue it was trying to solve is no longer present with
tcell (it being a holdover from `color256` on termbox) so it is not
needed.

retire gitter channel in favor of irc/matrix

Export options as environment variables (#448)

* Export options as environment variables

Any options from gOpts are available via lf_OPTION environment
variables. For now it works only on booleans, integers and strings (no
array support)

* Do not export some of the options

* Add support for arrays and fix numbers

* Fix comments

* Replace 1 and 0 with true and false

* Export hidden,reverse,dirfirst and sortby options

* Fix comments

* Little fix

* Simplify boolean conversion

log readlink errors instead of fail

Related #447 and #374
2020-09-01 15:42:44 +03:00

82 lines
3.2 KiB
Go

package main
import (
"testing"
"github.com/gdamore/tcell"
)
func TestApplyAnsiCodes(t *testing.T) {
none := tcell.StyleDefault
tests := []struct {
s string
st tcell.Style
stExp tcell.Style
}{
{"", none, none},
{"", none.Foreground(tcell.ColorMaroon).Background(tcell.ColorMaroon), none},
{"", none.Bold(true), none},
{"", none.Foreground(tcell.ColorMaroon).Bold(true), none},
{"0", none, none},
{"0", none.Foreground(tcell.ColorMaroon).Background(tcell.ColorMaroon), none},
{"0", none.Bold(true), none},
{"0", none.Foreground(tcell.ColorMaroon).Bold(true), none},
{"1", none, none.Bold(true)},
{"4", none, none.Underline(true)},
{"7", none, none.Reverse(true)},
{"1", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"4", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Underline(true)},
{"7", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Reverse(true)},
{"4", none.Bold(true), none.Bold(true).Underline(true)},
{"4", none.Foreground(tcell.ColorMaroon).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true).Underline(true)},
{"31", none, none.Foreground(tcell.ColorMaroon)},
{"31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
{"31", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"41", none, none.Background(tcell.ColorMaroon)},
{"41", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
{"1;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"1;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
{"38;5;8", none, none.Foreground(tcell.Color(8))},
{"38;5;16", none, none.Foreground(tcell.Color(16))},
{"38;5;232", none, none.Foreground(tcell.Color(232))},
{"38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
{"38;5;1", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"48;5;0", none, none.Background(tcell.ColorBlack)},
{"48;5;1", none, none.Background(tcell.ColorMaroon)},
{"48;5;8", none, none.Background(tcell.Color(8))},
{"48;5;16", none, none.Background(tcell.Color(16))},
{"48;5;232", none, none.Background(tcell.Color(232))},
{"48;5;1", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
{"1;38;5;1", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
{"1;38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
{"38;2;5;102;8", none, none.Foreground(tcell.NewRGBColor(5, 102, 8))},
{"48;2;0;48;143", none, none.Background(tcell.NewRGBColor(0, 48, 143))},
// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446
{"38;5;34;1", none, none.Foreground(tcell.Color(34)).Bold(true)},
}
for _, test := range tests {
if stGot := applyAnsiCodes(test.s, test.st); stGot != test.stExp {
t.Errorf("at input '%s' with '%d' expected '%d' but got '%d'",
test.s, test.st, test.stExp, stGot)
}
}
}