Skip to content

Commit

Permalink
update some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 28, 2021
1 parent bb87a35 commit d701117
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions color_test.go
Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions tag_test.go
Expand Up @@ -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("<red>MSG</>")
s = Sprint("<red>MSG</>")
is.Equal("\x1b[0;31mMSG\x1b[0m", s)

s = Sprint("<red>H</><green>I</>")
Expand Down
12 changes: 11 additions & 1 deletion utils_test.go
Expand Up @@ -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())
Expand Down Expand Up @@ -59,13 +63,19 @@ func TestUtilFuncs(t *testing.T) {
// TERM
mockEnvValue("TERM", "tmux-256color", func(_ string) {
is.True(IsSupportColor())
is.Equal("TERM=tmux-256color", SupColorMark())
})

// TERM
mockEnvValue("TERM", "rxvt-unicode-256color", func(_ string) {
is.True(IsSupportColor())
})

// TERM
mockEnvValue("TERM", "alacritty", func(_ string) {
is.True(IsSupportColor())
})

is.NoError(os.Setenv("TERM", "xterm-vt220"))
is.True(IsSupportColor())
// revert
Expand Down

0 comments on commit d701117

Please sign in to comment.