Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 1, 2021
1 parent 9e0126d commit f7f679a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
20 changes: 20 additions & 0 deletions color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ func TestSet(t *testing.T) {
is.Equal("\x1b[0m", str)
}

func TestSupportColor(t *testing.T) {
is := assert.New(t)

if is.True(SupportTrueColor()) {
is.True(SupportColor())
is.True(Support256Color())
}

if is.True(Support256Color()) {
is.True(SupportColor())
} else {
is.False(SupportTrueColor())
}

if is.False(SupportColor()) {
is.False(Support256Color())
is.False(SupportTrueColor())
}
}

func TestRenderCode(t *testing.T) {
// force open color render for testing
oldVal = ForceColor()
Expand Down
2 changes: 1 addition & 1 deletion detect_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func detectTermColorLevel() (level terminfo.ColorLevel, needVTP bool) {
// - support true-color
// TERMINAL_EMULATOR=JetBrains-JediTerm
if val := os.Getenv("TERMINAL_EMULATOR"); val == "JetBrains-JediTerm" {
debugf("on JetBrains-JediTerm, is win: %v", isWin)
debugf("True Color support on JetBrains-JediTerm, is win: %v", isWin)
return terminfo.ColorLevelMillions, isWin
}

Expand Down
13 changes: 13 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func TestDetectColorLevel(t *testing.T) {
is.True(IsSupportColor())
})

// TERMINAL_EMULATOR=JetBrains-JediTerm
mockEnvValue("TERMINAL_EMULATOR", "JetBrains-JediTerm", func(val string) {
is.Equal(LevelRgb, DetectColorLevel())
is.True(IsSupport16Color())
is.True(IsSupportColor())
})

// "COLORTERM=truecolor"
mockEnvValue("COLORTERM", "truecolor", func(val string) {
is.Equal("truecolor", val)
Expand Down Expand Up @@ -80,9 +87,15 @@ func TestIsDetectColorLevel_win(t *testing.T) {
mockEnvValue("ConEmuANSI", "ON", func(_ string) {
is.Equal(LevelRgb, DetectColorLevel())
is.True(IsSupportColor())
is.True(IsSupport256Color())
is.True(IsSupportTrueColor())
})

// WSL_DISTRO_NAME=Debian
mockEnvValue("WSL_DISTRO_NAME", "Debian", func(_ string) {
is.True(IsSupportColor())
})

// ANSICON
mockEnvValue("ANSICON", "189x2000 (189x43)", func(_ string) {
is.True(IsSupportColor())
Expand Down

0 comments on commit f7f679a

Please sign in to comment.