diff --git a/color_test.go b/color_test.go index b5fa65c..d790589 100644 --- a/color_test.go +++ b/color_test.go @@ -168,6 +168,8 @@ func TestRenderCode(t *testing.T) { str = RenderString("36;1", "Text") is.Equal("Text", str) Enable = true + + is.Empty(GetErrors()) } func TestClearCode(t *testing.T) { diff --git a/tag_test.go b/tag_test.go index 5be19ae..19bf3c3 100644 --- a/tag_test.go +++ b/tag_test.go @@ -81,17 +81,21 @@ func TestParseCodeFromAttr(t *testing.T) { } func TestPrint(t *testing.T) { + is := assert.New(t) + + s := Sprint() + is.Equal("", s) + // force open color render for testing buf := forceOpenColorRender() defer resetColorRender() - is := assert.New(t) is.True(len(GetColorTags()) > 0) is.True(IsDefinedTag("info")) is.Equal("0;32", GetTagCode("info")) is.Equal("", GetTagCode("not-exist")) - s := Sprint("MSG") + s = Sprint("MSG") is.Equal("\x1b[0;31mMSG\x1b[0m", s) s = Sprint("HI") diff --git a/utils_test.go b/utils_test.go index 0fcc74d..ca322d4 100644 --- a/utils_test.go +++ b/utils_test.go @@ -28,9 +28,13 @@ func TestUtilFuncs(t *testing.T) { is.NoError(os.Unsetenv("MSYSTEM")) is.False(IsMSys()) _ = os.Setenv("MSYSTEM", oldVal) +} + +func TestIsSupportColor(t *testing.T) { + is := assert.New(t) // IsSupport256Color - oldVal = os.Getenv("TERM") + oldVal := os.Getenv("TERM") _ = os.Unsetenv("TERM") is.False(IsSupportColor()) is.False(IsSupport256Color()) @@ -59,6 +63,7 @@ func TestUtilFuncs(t *testing.T) { // TERM mockEnvValue("TERM", "tmux-256color", func(_ string) { is.True(IsSupportColor()) + is.Equal("TERM=tmux-256color", SupColorMark()) }) // TERM @@ -66,6 +71,11 @@ func TestUtilFuncs(t *testing.T) { is.True(IsSupportColor()) }) + // TERM + mockEnvValue("TERM", "alacritty", func(_ string) { + is.True(IsSupportColor()) + }) + is.NoError(os.Setenv("TERM", "xterm-vt220")) is.True(IsSupportColor()) // revert