...

Source file src/github.com/muesli/termenv/color_test.go

Documentation: github.com/muesli/termenv

     1  package termenv
     2  
     3  import "testing"
     4  
     5  func TestXTermColor(t *testing.T) {
     6  	var tests = []struct {
     7  		input string
     8  		color RGBColor
     9  		valid bool
    10  	}{
    11  		{
    12  			"\033]11;rgb:fafa/fafa/fafa\033",
    13  			RGBColor("#fafafa"),
    14  			true,
    15  		},
    16  		{
    17  			"\033]11;rgb:fafa/fafa/fafa\033\\",
    18  			RGBColor("#fafafa"),
    19  			true,
    20  		},
    21  		{
    22  			"\033]11;rgb:1212/3434/5656\a",
    23  			RGBColor("#123456"),
    24  			true,
    25  		},
    26  		{
    27  			"\033]11;foo:fafa/fafa/fafaZZ",
    28  			"",
    29  			false,
    30  		},
    31  		{
    32  			"\033]11;rgb:fafa/fafa",
    33  			"",
    34  			false,
    35  		},
    36  		{
    37  			"\033]11;rgb:fafa/fafa/fafaY",
    38  			"",
    39  			false,
    40  		},
    41  		{
    42  			"\033]11;rgb:fafa/fafa/fafaZZ",
    43  			"",
    44  			false,
    45  		},
    46  	}
    47  
    48  	for _, test := range tests {
    49  		t.Run("", func(t *testing.T) {
    50  			color, err := xTermColor(test.input)
    51  			if err != nil && test.valid {
    52  				t.Fatalf("unexpected error for input %q: %v", test.input, err)
    53  			}
    54  
    55  			if err == nil && !test.valid {
    56  				t.Fatalf("expected error for input %v not found", test.input)
    57  			}
    58  
    59  			if color != test.color {
    60  				t.Fatalf("wrong color returned, want %v, got %v", test.color, color)
    61  			}
    62  		})
    63  	}
    64  }
    65  

View as plain text