github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zlog/color_test.go (about)

     1  package zlog
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"testing"
     7  
     8  	zls "github.com/sohaha/zlsgo"
     9  )
    10  
    11  func TestColor(t *testing.T) {
    12  	T := zls.NewTest(t)
    13  	testText := "ok"
    14  	_ = os.Setenv("ConEmuANSI", "ON")
    15  	bl := IsSupportColor()
    16  	OutAllColor()
    17  	if bl {
    18  		T.Equal(fmt.Sprintf("\x1b[%dm%s\x1b[0m", ColorGreen, testText), ColorTextWrap(ColorGreen, testText))
    19  	} else {
    20  		T.Equal(testText, ColorTextWrap(ColorGreen, testText))
    21  	}
    22  
    23  	DisableColor = true
    24  	bl = isSupportColor()
    25  	T.Equal(false, bl)
    26  	OutAllColor()
    27  	T.Equal(testText, ColorTextWrap(ColorGreen, testText))
    28  }
    29  
    30  func TestTrimAnsi(t *testing.T) {
    31  	tt := zls.NewTest(t)
    32  
    33  	testText := "ok\x1b[31m"
    34  	tt.Equal("ok", TrimAnsi(testText))
    35  
    36  	testText = ColorTextWrap(ColorGreen, "ok")
    37  	tt.Equal("ok", TrimAnsi(testText))
    38  }