oh-my-posh/src/segments/os_test.go

85 lines
1.9 KiB
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
2020-10-07 12:01:03 -07:00
import (
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/properties"
2020-10-07 12:01:03 -07:00
"testing"
"github.com/stretchr/testify/assert"
)
func TestOSInfo(t *testing.T) {
cases := []struct {
Case string
ExpectedString string
GOOS string
2022-01-18 00:48:47 -08:00
IsWSL bool
Platform string
DisplayDistroName bool
}{
{
Case: "WSL debian - icon",
ExpectedString: "WSL at \uf306",
GOOS: "linux",
2022-01-18 00:48:47 -08:00
IsWSL: true,
Platform: "debian",
},
{
Case: "WSL debian - name",
2022-01-18 00:48:47 -08:00
ExpectedString: "WSL at debian",
GOOS: "linux",
2022-01-18 00:48:47 -08:00
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",
2020-10-21 19:49:14 -07:00
},
}
for _, tc := range cases {
env := new(mock.MockedEnvironment)
env.On("GOOS").Return(tc.GOOS)
env.On("Platform").Return(tc.Platform)
env.On("TemplateCache").Return(&environment.TemplateCache{
2022-01-22 10:46:56 -08:00
Env: make(map[string]string),
WSL: tc.IsWSL,
})
2022-01-26 05:10:18 -08:00
osInfo := &Os{
2021-11-26 01:37:33 -08:00
env: env,
props: properties.Map{
DisplayDistroName: tc.DisplayDistroName,
Windows: "windows",
MacOS: "darwin",
},
}
_ = osInfo.Enabled()
assert.Equal(t, tc.ExpectedString, renderTemplate(env, osInfo.Template(), osInfo), tc.Case)
2020-10-21 19:49:14 -07:00
}
}