oh-my-posh/src/console_title_test.go

62 lines
1.7 KiB
Go
Raw Normal View History

2020-12-26 10:21:26 -08:00
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetConsoleTitle(t *testing.T) {
cases := []struct {
Style ConsoleTitleStyle
2020-12-27 02:56:33 -08:00
Template string
Root bool
2020-12-26 10:21:26 -08:00
Cwd string
PathSeperator string
ShellName string
Expected string
}{
{Style: FolderName, Cwd: "/usr/home", PathSeperator: "/", ShellName: "default", Expected: "\x1b]0;home\a"},
{Style: FullPath, Cwd: "/usr/home/jan", PathSeperator: "/", ShellName: "default", Expected: "\x1b]0;/usr/home/jan\a"},
2020-12-27 02:56:33 -08:00
{
Style: Template,
Template: "{{.Path}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}",
Cwd: "C:\\vagrant",
PathSeperator: "\\",
ShellName: "PowerShell",
Root: true,
Expected: "\x1b]0;C:\\vagrant :: Admin :: PowerShell\a",
},
{
Style: Template,
Template: "{{.Folder}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}",
Cwd: "C:\\vagrant",
PathSeperator: "\\",
ShellName: "PowerShell",
Expected: "\x1b]0;vagrant :: PowerShell\a",
},
2020-12-26 10:21:26 -08:00
}
for _, tc := range cases {
settings := &Settings{
2020-12-27 02:56:33 -08:00
ConsoleTitleStyle: tc.Style,
ConsoleTitleTemplate: tc.Template,
2020-12-26 10:21:26 -08:00
}
env := new(MockedEnvironment)
env.On("getcwd", nil).Return(tc.Cwd)
env.On("homeDir", nil).Return("/usr/home")
env.On("getPathSeperator", nil).Return(tc.PathSeperator)
2020-12-27 02:56:33 -08:00
env.On("isRunningAsRoot", nil).Return(tc.Root)
env.On("getShellName", nil).Return(tc.ShellName)
2020-12-26 10:51:21 -08:00
formats := &ansiFormats{}
formats.init(tc.ShellName)
2020-12-26 10:21:26 -08:00
ct := &consoleTitle{
env: env,
settings: settings,
2020-12-26 10:51:21 -08:00
formats: formats,
2020-12-26 10:21:26 -08:00
}
got := ct.getConsoleTitle()
assert.Equal(t, tc.Expected, got)
}
}