github.com/blend/go-sdk@v1.20220411.3/ansi/color_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package ansi
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func TestColorApply(t *testing.T) {
    17  	assert := assert.New(t)
    18  
    19  	escapedBlack := ColorBlack.Normal()
    20  	assert.Equal("\033[0;"+string(ColorBlack), escapedBlack)
    21  
    22  	appliedBlack := ColorBlack.Apply("test")
    23  	assert.Equal(ColorBlack.Normal()+"test"+ColorReset, appliedBlack)
    24  }
    25  
    26  func TestColors(t *testing.T) {
    27  	assert := assert.New(t)
    28  
    29  	assert.Equal(ColorBlack.Apply("foo"), Black("foo"))
    30  	assert.Equal(ColorRed.Apply("foo"), Red("foo"))
    31  	assert.Equal(ColorGreen.Apply("foo"), Green("foo"))
    32  	assert.Equal(ColorYellow.Apply("foo"), Yellow("foo"))
    33  	assert.Equal(ColorBlue.Apply("foo"), Blue("foo"))
    34  	assert.Equal(ColorPurple.Apply("foo"), Purple("foo"))
    35  	assert.Equal(ColorCyan.Apply("foo"), Cyan("foo"))
    36  	assert.Equal(ColorWhite.Apply("foo"), White("foo"))
    37  	assert.Equal(ColorLightBlack.Apply("foo"), LightBlack("foo"))
    38  	assert.Equal(ColorLightRed.Apply("foo"), LightRed("foo"))
    39  	assert.Equal(ColorLightGreen.Apply("foo"), LightGreen("foo"))
    40  	assert.Equal(ColorLightYellow.Apply("foo"), LightYellow("foo"))
    41  	assert.Equal(ColorLightBlue.Apply("foo"), LightBlue("foo"))
    42  	assert.Equal(ColorLightPurple.Apply("foo"), LightPurple("foo"))
    43  	assert.Equal(ColorLightCyan.Apply("foo"), LightCyan("foo"))
    44  	assert.Equal(ColorLightWhite.Apply("foo"), LightWhite("foo"))
    45  
    46  	assert.Equal(ColorRed.Bold()+"foo"+ColorReset, Bold(ColorRed, "foo"))
    47  	assert.Equal(ColorRed.Underline()+"foo"+ColorReset, Underline(ColorRed, "foo"))
    48  }