1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/wtf/colors_test.go
2019-08-03 18:31:00 -07:00

76 lines
1.3 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package wtf
import (
"testing"
"github.com/gdamore/tcell"
)
func Test_ASCIItoTviewColors(t *testing.T) {
tests := []struct {
name string
text string
expected string
}{
{
name: "with blank text",
text: "",
expected: "",
},
{
name: "with no color",
text: "cat",
expected: "cat",
},
{
name: "with defined color",
text: "[38;5;226mcat/",
expected: "[38;5;226mcat/[-]",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := ASCIItoTviewColors(tt.text)
if tt.expected != actual {
t.Errorf("\nexpected: %q\n got: %q", tt.expected, actual)
}
})
}
}
func Test_ColorFor(t *testing.T) {
tests := []struct {
name string
label string
expected tcell.Color
}{
{
name: "with no label",
label: "",
expected: tcell.ColorGreen,
},
{
name: "with missing label",
label: "cat",
expected: tcell.ColorGreen,
},
{
name: "with defined label",
label: "tomato",
expected: tcell.ColorTomato,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := ColorFor(tt.label)
if tt.expected != actual {
t.Errorf("\nexpected: %q\n got: %q", tt.expected, actual)
}
})
}
}