2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2020-09-15 04:44:53 -07:00
|
|
|
|
|
|
|
import (
|
2022-01-26 01:23:18 -08:00
|
|
|
"oh-my-posh/mock"
|
2022-11-09 11:27:54 -08:00
|
|
|
"oh-my-posh/platform"
|
2022-01-26 04:53:35 -08:00
|
|
|
"oh-my-posh/properties"
|
2020-09-15 04:44:53 -07:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWriteCurrentShell(t *testing.T) {
|
|
|
|
expected := "zsh"
|
2022-01-26 01:23:18 -08:00
|
|
|
env := new(mock.MockedEnvironment)
|
2022-01-23 12:37:51 -08:00
|
|
|
env.On("Shell").Return(expected, nil)
|
2022-11-09 11:27:54 -08:00
|
|
|
env.On("Flags").Return(&platform.Flags{ShellVersion: "1.2.3"})
|
2022-01-26 05:10:18 -08:00
|
|
|
s := &Shell{
|
2022-01-01 11:08:08 -08:00
|
|
|
env: env,
|
2022-01-26 04:53:35 -08:00
|
|
|
props: properties.Map{},
|
2020-09-15 04:44:53 -07:00
|
|
|
}
|
2022-01-26 05:26:56 -08:00
|
|
|
_ = s.Enabled()
|
|
|
|
assert.Equal(t, expected, renderTemplate(env, s.Template(), s))
|
2020-09-20 10:13:37 -07:00
|
|
|
}
|
2021-09-17 12:48:00 -07:00
|
|
|
|
|
|
|
func TestUseMappedShellNames(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Shell string
|
|
|
|
Expected string
|
|
|
|
}{
|
|
|
|
{Shell: "zsh", Expected: "zsh"},
|
|
|
|
{Shell: "pwsh", Expected: "PS"},
|
|
|
|
{Shell: "PWSH", Expected: "PS"},
|
|
|
|
}
|
|
|
|
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("Shell").Return(tc.Expected, nil)
|
2022-11-09 11:27:54 -08:00
|
|
|
env.On("Flags").Return(&platform.Flags{ShellVersion: "1.2.3"})
|
2022-01-26 05:10:18 -08:00
|
|
|
s := &Shell{
|
2021-09-17 12:48:00 -07:00
|
|
|
env: env,
|
2022-01-26 04:53:35 -08:00
|
|
|
props: properties.Map{
|
2021-11-26 01:37:33 -08:00
|
|
|
MappedShellNames: map[string]string{"pwsh": "PS"},
|
2021-09-17 12:48:00 -07:00
|
|
|
},
|
|
|
|
}
|
2022-01-26 05:26:56 -08:00
|
|
|
_ = s.Enabled()
|
|
|
|
got := renderTemplate(env, s.Template(), s)
|
2021-09-17 12:48:00 -07:00
|
|
|
assert.Equal(t, tc.Expected, got)
|
|
|
|
}
|
|
|
|
}
|