Skip to content

Commit

Permalink
update some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 9, 2021
1 parent ac48b1f commit befe633
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
15 changes: 0 additions & 15 deletions detect_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,6 @@ func detectColorLevelFromEnv(termVal string, isWin bool) terminfo.ColorLevel {
// return terminfo.ColorLevelBasic
}

func fallbackCheckTermValue(termVal string) (terminfo.ColorLevel, error) {
debugf("terminfo.Load error - fallback detect color by check TERM value")
if strings.Contains(termVal, "256color") {
return terminfo.ColorLevelHundreds, nil
}

if strings.Contains(termVal, "xterm") {
return terminfo.ColorLevelHundreds, nil
// return terminfo.ColorLevelBasic, nil
}

// return terminfo.ColorLevelNone, nil
return terminfo.ColorLevelBasic, nil
}

var detectedWSL bool
var wslContents string

Expand Down
21 changes: 20 additions & 1 deletion utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ func TestIsDetectColorLevel_unix(t *testing.T) {
is.True(IsSupportColor())
})

mockOsEnvByText("TERM=not-exist-256color", func() {
is.Equal(Level256, DetectColorLevel())
is.False(IsSupportTrueColor())
is.True(IsSupport256Color())
is.True(IsSupportColor())
})

// TERM_PROGRAM=Terminus
mockOsEnvByText(`
TERMINUS_PLUGINS=
Expand Down Expand Up @@ -187,10 +194,22 @@ func TestIsDetectColorLevel_screen(t *testing.T) {
}
is := assert.New(t)

// COLORTERM=truecolor
mockOsEnvByText(`
TERM=screen
COLORTERM=truecolor
`, func() {
is.Equal(Level256, DetectColorLevel())
is.False(IsSupportRGBColor())
is.False(IsSupportTrueColor())
is.True(IsSupport256Color())
is.True(IsSupportColor())
})

// TERM_PROGRAM=Apple_Terminal use screen
mockOsEnvByText(`
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
TERM=screen
TERM_PROGRAM_VERSION=433
TERM_SESSION_ID=F17907FE-DCA5-488D-829B-7AFA8B323753
ZSH_TMUX_TERM=screen-256color
Expand Down

0 comments on commit befe633

Please sign in to comment.