mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add specs for /wtf/colors
This commit is contained in:
parent
a1aafbeade
commit
681dd85ce6
@ -3,11 +3,73 @@ package wtf
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/stretchr/testify/assert"
|
"github.com/gdamore/tcell"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_ASCIItoTviewColors(t *testing.T) {
|
func Test_ASCIItoTviewColors(t *testing.T) {
|
||||||
Equal(t, "", ASCIItoTviewColors(""))
|
tests := []struct {
|
||||||
Equal(t, "cat", ASCIItoTviewColors("cat"))
|
name string
|
||||||
Equal(t, "[38;5;226mcat/[-]", ASCIItoTviewColors("[38;5;226mcat/[0m"))
|
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/[0m",
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user