package iostreams import ( "testing" "github.com/stretchr/testify/assert" ) func TestColorFromRGB(t *testing.T) { tests := []struct { name string hex string text string wants string cs *ColorScheme }{ { name: "truecolor", hex: "fc0303", text: "red", wants: "\033[38;2;252;3;3mred\033[0m", cs: NewColorScheme(true, true, true), }, { name: "no truecolor", hex: "fc0303", text: "red", wants: "red", cs: NewColorScheme(true, true, false), }, { name: "no color", hex: "fc0303", text: "red", wants: "red", cs: NewColorScheme(false, false, false), }, { name: "invalid hex", hex: "fc0", text: "red", wants: "red", cs: NewColorScheme(false, false, false), }, } for _, tt := range tests { fn := tt.cs.ColorFromRGB(tt.hex) assert.Equal(t, tt.wants, fn(tt.text)) } } func TestHexToRGB(t *testing.T) { tests := []struct { name string hex string text string wants string cs *ColorScheme }{ { name: "truecolor", hex: "fc0303", text: "red", wants: "\033[38;2;252;3;3mred\033[0m", cs: NewColorScheme(true, true, true), }, { name: "no truecolor", hex: "fc0303", text: "red", wants: "red", cs: NewColorScheme(true, true, false), }, { name: "no color", hex: "fc0303", text: "red", wants: "red", cs: NewColorScheme(false, false, false), }, { name: "invalid hex", hex: "fc0", text: "red", wants: "red", cs: NewColorScheme(false, false, false), }, } for _, tt := range tests { output := tt.cs.HexToRGB(tt.hex, tt.text) assert.Equal(t, tt.wants, output) } }