mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
dabc9d4f20
only display UserInfoSeparator if both username and hostname are dislayed cleanHostName only if it ends with garbage instead of contains. fixes .localdomain having just .local stripped add .localdomain to garbage
64 lines
1.7 KiB
Go
Executable file
64 lines
1.7 KiB
Go
Executable file
package main
|
|
|
|
import (
|
|
"os/user"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func setupSession(userInfoSeparator string, username string, hostname string, goos string) session {
|
|
env := new(MockedEnvironment)
|
|
user := user.User{
|
|
Username: username,
|
|
}
|
|
env.On("getCurrentUser", nil).Return(&user, nil)
|
|
env.On("getHostName", nil).Return(hostname, nil)
|
|
env.On("getRuntimeGOOS", nil).Return(goos)
|
|
props := &properties{
|
|
values: map[Property]interface{}{UserInfoSeparator: userInfoSeparator},
|
|
foreground: "#fff",
|
|
background: "#000",
|
|
}
|
|
s := session{
|
|
env: env,
|
|
props: props,
|
|
}
|
|
return s
|
|
}
|
|
|
|
func testUserInfoWriter(userInfoSeparator string, username string, hostname string, goos string) string {
|
|
s := setupSession(userInfoSeparator, username, hostname, goos)
|
|
return s.getFormattedText()
|
|
}
|
|
|
|
func TestWriteUserInfo(t *testing.T) {
|
|
want := "<#fff>bill</>@<#fff>surface</>"
|
|
got := testUserInfoWriter("@", "bill", "surface", "windows")
|
|
assert.EqualValues(t, want, got)
|
|
}
|
|
|
|
func TestWriteUserInfoWindowsIncludingHostname(t *testing.T) {
|
|
want := "<#fff>bill</>@<#fff>surface</>"
|
|
got := testUserInfoWriter("@", "surface\\bill", "surface", "windows")
|
|
assert.EqualValues(t, want, got)
|
|
}
|
|
|
|
func TestWriteOnlyUsername(t *testing.T) {
|
|
s := setupSession("@", "surface\\bill", "surface", "windows")
|
|
s.props.values[DisplayHost] = false
|
|
|
|
want := "<#fff>bill</><#fff></>"
|
|
got := s.getFormattedText()
|
|
assert.EqualValues(t, want, got)
|
|
}
|
|
|
|
func TestWriteOnlyHostname(t *testing.T) {
|
|
s := setupSession("@", "surface\\bill", "surface", "windows")
|
|
s.props.values[DisplayUser] = false
|
|
|
|
want := "<#fff></><#fff>surface</>"
|
|
got := s.getFormattedText()
|
|
assert.EqualValues(t, want, got)
|
|
}
|