github.com/coveo/gotemplate@v2.7.7+incompatible/utils/color_test.go (about) 1 package utils 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 8 "github.com/fatih/color" 9 ) 10 11 func TestColor(t *testing.T) { 12 t.Parallel() 13 tests := []struct { 14 args []string 15 want *color.Color 16 wantErr bool 17 }{ 18 {[]string{"red ;green"}, color.New(color.FgRed, color.FgGreen), false}, 19 } 20 for _, tt := range tests { 21 t.Run(fmt.Sprint(tt.args), func(t *testing.T) { 22 got, err := Color(tt.args...) 23 if (err != nil) != tt.wantErr { 24 t.Errorf("Color() error = %v, wantErr %v", err, tt.wantErr) 25 return 26 } 27 if !reflect.DeepEqual(got, tt.want) { 28 t.Errorf("Color() = %v, want %v", got, tt.want) 29 } 30 }) 31 } 32 } 33 34 func TestFormatMessage(t *testing.T) { 35 tests := []struct { 36 name string 37 args []interface{} 38 want string 39 }{ 40 {"No argument", nil, ""}, 41 {"Empty arguments", []interface{}{}, ""}, 42 {"Single argument", []interface{}{"Hello"}, "Hello"}, 43 {"Two arguments", []interface{}{"Hello", "World"}, "Hello World"}, 44 {"Two arguments with format", []interface{}{"Hello %s! %d", "World", 100}, "Hello World! 100"}, 45 {"Bad format", []interface{}{"Hello %s! %d", "World"}, "Hello %s! %d World"}, 46 {"Escaped %", []interface{}{"You got %d%% off", 60}, "You got 60% off"}, 47 } 48 for _, tt := range tests { 49 t.Run(tt.name, func(t *testing.T) { 50 if got := FormatMessage(tt.args...); got != tt.want { 51 t.Errorf("FormatMessage() = %v, want %v", got, tt.want) 52 } 53 }) 54 } 55 }