github.com/wtfutil/wtf@v0.43.0/wtf/colors_test.go (about)

     1  package wtf
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gdamore/tcell/v2"
     7  )
     8  
     9  func Test_ASCIItoTviewColors(t *testing.T) {
    10  	tests := []struct {
    11  		name     string
    12  		text     string
    13  		expected string
    14  	}{
    15  		{
    16  			name:     "with blank text",
    17  			text:     "",
    18  			expected: "",
    19  		},
    20  		{
    21  			name:     "with no color",
    22  			text:     "cat",
    23  			expected: "cat",
    24  		},
    25  		{
    26  			name:     "with defined color",
    27  			text:     "[38;5;226mcat/\x1b[0m",
    28  			expected: "[38;5;226mcat/[-]",
    29  		},
    30  	}
    31  
    32  	for _, tt := range tests {
    33  		t.Run(tt.name, func(t *testing.T) {
    34  			actual := ASCIItoTviewColors(tt.text)
    35  
    36  			if tt.expected != actual {
    37  				t.Errorf("\nexpected: %q\n     got: %q", tt.expected, actual)
    38  			}
    39  		})
    40  	}
    41  }
    42  
    43  func Test_ColorFor(t *testing.T) {
    44  	tests := []struct {
    45  		name     string
    46  		label    string
    47  		expected tcell.Color
    48  	}{
    49  		{
    50  			name:     "with no label",
    51  			label:    "",
    52  			expected: tcell.ColorDefault,
    53  		},
    54  		{
    55  			name:     "with missing label",
    56  			label:    "cat",
    57  			expected: tcell.ColorDefault,
    58  		},
    59  		{
    60  			name:     "with defined label",
    61  			label:    "tomato",
    62  			expected: tcell.ColorTomato,
    63  		},
    64  	}
    65  
    66  	for _, tt := range tests {
    67  		t.Run(tt.name, func(t *testing.T) {
    68  			actual := ColorFor(tt.label)
    69  
    70  			if tt.expected != actual {
    71  				t.Errorf("\nexpected: %q\n     got: %q", tt.expected, actual)
    72  			}
    73  		})
    74  	}
    75  }