oh-my-posh/src/segment_os_test.go
2022-02-03 10:44:18 +01:00

82 lines
1.8 KiB
Go

package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestOSInfo(t *testing.T) {
cases := []struct {
Case string
ExpectedString string
GOOS string
IsWSL bool
Platform string
DisplayDistroName bool
}{
{
Case: "WSL debian - icon",
ExpectedString: "WSL at \uf306",
GOOS: "linux",
IsWSL: true,
Platform: "debian",
},
{
Case: "WSL debian - name",
ExpectedString: "WSL at debian",
GOOS: "linux",
IsWSL: true,
Platform: "debian",
DisplayDistroName: true,
},
{
Case: "plain linux - icon",
ExpectedString: "\uf306",
GOOS: "linux",
Platform: "debian",
},
{
Case: "plain linux - name",
ExpectedString: "debian",
GOOS: "linux",
Platform: "debian",
DisplayDistroName: true,
},
{
Case: "windows",
ExpectedString: "windows",
GOOS: "windows",
},
{
Case: "darwin",
ExpectedString: "darwin",
GOOS: "darwin",
},
{
Case: "unknown",
ExpectedString: "unknown",
GOOS: "unknown",
},
}
for _, tc := range cases {
env := new(MockedEnvironment)
env.On("getRuntimeGOOS").Return(tc.GOOS)
env.On("getPlatform").Return(tc.Platform)
env.On("templateCache").Return(&templateCache{
Env: make(map[string]string),
WSL: tc.IsWSL,
})
osInfo := &osInfo{
env: env,
props: properties{
DisplayDistroName: tc.DisplayDistroName,
Windows: "windows",
MacOS: "darwin",
},
}
_ = osInfo.enabled()
assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case)
}
}