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