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

     1  package utils
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_ColorizePercent(t *testing.T) {
    10  	tests := []struct {
    11  		name     string
    12  		percent  float64
    13  		expected string
    14  	}{
    15  		{
    16  			name:     "with high percent",
    17  			percent:  70,
    18  			expected: "[green]70[white]",
    19  		},
    20  		{
    21  			name:     "with medium percent",
    22  			percent:  35,
    23  			expected: "[yellow]35[white]",
    24  		},
    25  		{
    26  			name:     "with low percent",
    27  			percent:  1,
    28  			expected: "[red]1[white]",
    29  		},
    30  		{
    31  			name:     "with negative percent",
    32  			percent:  -5,
    33  			expected: "[grey]-5[white]",
    34  		},
    35  	}
    36  
    37  	for _, tt := range tests {
    38  		t.Run(tt.name, func(t *testing.T) {
    39  			actual := ColorizePercent(tt.percent)
    40  			assert.Equal(t, tt.expected, actual)
    41  		})
    42  	}
    43  }