diff --git a/src/environment/shell.go b/src/environment/shell.go index ac7d43bb..d6f51f9e 100644 --- a/src/environment/shell.go +++ b/src/environment/shell.go @@ -344,17 +344,15 @@ func (env *ShellEnvironment) Pwd() string { return env.cwd } correctPath := func(pwd string) string { - // on Windows, and being case sensitive and not consistent and all, this gives silly issues - if env.GOOS() == WINDOWS { - driveLetter := regex.GetCompiledRegex(`^[a-z]:`) - return driveLetter.ReplaceAllStringFunc(pwd, strings.ToUpper) + if env.GOOS() != WINDOWS { + return pwd } - return pwd + // on Windows, and being case sensitive and not consistent and all, this gives silly issues + driveLetter := regex.GetCompiledRegex(`^[a-z]:`) + return driveLetter.ReplaceAllStringFunc(pwd, strings.ToUpper) } if env.CmdFlags != nil && env.CmdFlags.PWD != "" { - // ensure a clean path - root, path := ParsePath(env, correctPath(env.CmdFlags.PWD)) - env.cwd = root + path + env.cwd = correctPath(env.CmdFlags.PWD) return env.cwd } dir, err := os.Getwd() @@ -846,47 +844,6 @@ func Base(env Environment, path string) string { return path } -// ParsePath parses an input path and returns a clean root and a clean path. -func ParsePath(env Environment, inputPath string) (root, path string) { - if len(inputPath) == 0 { - return - } - separator := env.PathSeparator() - clean := func(path string) string { - matches := regex.FindAllNamedRegexMatch(fmt.Sprintf(`(?P[^\%s]+)`, separator), path) - n := len(matches) - 1 - s := new(strings.Builder) - for i, m := range matches { - s.WriteString(m["element"]) - if i != n { - s.WriteString(separator) - } - } - return s.String() - } - - if env.GOOS() == WINDOWS { - inputPath = strings.ReplaceAll(inputPath, "/", `\`) - // for a UNC path, extract \\hostname\sharename as the root - matches := regex.FindNamedRegexMatch(`^\\\\(?P[^\\]+)\\+(?P[^\\]+)\\*(?P[\s\S]*)$`, inputPath) - if len(matches) > 0 { - root = `\\` + matches["hostname"] + `\` + matches["sharename"] + `\` - path = clean(matches["path"]) - return - } - } - s := strings.SplitAfterN(inputPath, separator, 2) - root = s[0] - if !strings.HasSuffix(root, separator) { - // a root should end with a separator - root += separator - } - if len(s) == 2 { - path = clean(s[1]) - } - return root, path -} - func ReplaceHomeDirPrefixWithTilde(env Environment, path string) string { home := env.Home() // match Home directory exactly diff --git a/src/segments/path.go b/src/segments/path.go index 120e1fc6..d506cdf1 100644 --- a/src/segments/path.go +++ b/src/segments/path.go @@ -15,7 +15,10 @@ type Path struct { props properties.Properties env environment.Environment - pwd string + root string + relative string + pwd string + Path string StackCount int Location string @@ -70,7 +73,11 @@ func (pt *Path) Template() string { } func (pt *Path) Enabled() bool { - pt.setPath() + pt.setPaths() + if len(pt.pwd) == 0 { + return false + } + pt.setStyle() if pt.env.IsWsl() { pt.Location, _ = pt.env.RunCommand("wslpath", "-m", pt.pwd) } else { @@ -81,22 +88,35 @@ func (pt *Path) Enabled() bool { return true } +func (pt *Path) setPaths() { + pt.pwd = pt.env.Pwd() + if (pt.env.Shell() == shell.PWSH || pt.env.Shell() == shell.PWSH5) && len(pt.env.Flags().PSWD) != 0 { + pt.pwd = pt.env.Flags().PSWD + } + if len(pt.pwd) == 0 { + return + } + // ensure a clean path + pt.root, pt.relative = pt.replaceMappedLocations() + pathSeparator := pt.env.PathSeparator() + if !strings.HasSuffix(pt.root, pathSeparator) && len(pt.relative) > 0 { + pt.pwd = pt.root + pathSeparator + pt.relative + return + } + pt.pwd = pt.root + pt.relative +} + func (pt *Path) Parent() string { - pwd := pt.getPwd() - if len(pwd) == 0 { + if len(pt.pwd) == 0 { return "" } - root, path := environment.ParsePath(pt.env, pwd) - if len(path) == 0 { + if len(pt.relative) == 0 { // a root path has no parent return "" } - base := environment.Base(pt.env, path) - path = pt.replaceFolderSeparators(path[:len(path)-len(base)]) - if root != pt.env.PathSeparator() { - root = root[:len(root)-1] + pt.getFolderSeparator() - } - return root + path + base := environment.Base(pt.env, pt.pwd) + path := pt.replaceFolderSeparators(pt.pwd[:len(pt.pwd)-len(base)]) + return path } func (pt *Path) Init(props properties.Properties, env environment.Environment) { @@ -104,38 +124,33 @@ func (pt *Path) Init(props properties.Properties, env environment.Environment) { pt.env = env } -func (pt *Path) setPath() { - pwd := pt.getPwd() - if len(pwd) == 0 { - return - } - root, path := environment.ParsePath(pt.env, pwd) - if len(path) == 0 { - pt.Path = pt.formatRoot(root) +func (pt *Path) setStyle() { + if len(pt.relative) == 0 { + pt.Path = pt.root return } switch style := pt.props.GetString(properties.Style, Agnoster); style { case Agnoster: - pt.Path = pt.getAgnosterPath(root, path) + pt.Path = pt.getAgnosterPath() case AgnosterFull: - pt.Path = pt.getAgnosterFullPath(root, path) + pt.Path = pt.getAgnosterFullPath() case AgnosterShort: - pt.Path = pt.getAgnosterShortPath(root, path) + pt.Path = pt.getAgnosterShortPath() case Mixed: - pt.Path = pt.getMixedPath(root, path) + pt.Path = pt.getMixedPath() case Letter: - pt.Path = pt.getLetterPath(root, path) + pt.Path = pt.getLetterPath() case Unique: - pt.Path = pt.getUniqueLettersPath(root, path) + pt.Path = pt.getUniqueLettersPath() case AgnosterLeft: - pt.Path = pt.getAgnosterLeftPath(root, path) + pt.Path = pt.getAgnosterLeftPath() case Short: // "short" is a duplicate of "full", just here for backwards compatibility fallthrough case Full: - pt.Path = pt.getFullPath(root, path) + pt.Path = pt.getFullPath() case Folder: - pt.Path = pt.getFolderPath(path) + pt.Path = pt.getFolderPath() default: pt.Path = fmt.Sprintf("Path style: %s is not available", style) } @@ -166,14 +181,14 @@ func (pt *Path) getFolderSeparator() string { return text } -func (pt *Path) getMixedPath(root, path string) string { +func (pt *Path) getMixedPath() string { var buffer strings.Builder threshold := int(pt.props.GetFloat64(MixedThreshold, 4)) folderIcon := pt.props.GetString(FolderIcon, "..") separator := pt.getFolderSeparator() - elements := strings.Split(path, pt.env.PathSeparator()) - if root != pt.env.PathSeparator() { - elements = append([]string{root[:len(root)-1]}, elements...) + elements := strings.Split(pt.relative, pt.env.PathSeparator()) + if pt.root != pt.env.PathSeparator() { + elements = append([]string{pt.root}, elements...) } n := len(elements) buffer.WriteString(elements[0]) @@ -187,13 +202,24 @@ func (pt *Path) getMixedPath(root, path string) string { return buffer.String() } -func (pt *Path) getAgnosterPath(root, path string) string { +func (pt *Path) pathDepth(pwd string) int { + splitted := strings.Split(pwd, pt.env.PathSeparator()) + depth := 0 + for _, part := range splitted { + if part != "" { + depth++ + } + } + return depth +} + +func (pt *Path) getAgnosterPath() string { var buffer strings.Builder folderIcon := pt.props.GetString(FolderIcon, "..") separator := pt.getFolderSeparator() - elements := strings.Split(path, pt.env.PathSeparator()) - if root != pt.env.PathSeparator() { - elements = append([]string{root[:len(root)-1]}, elements...) + elements := strings.Split(pt.relative, pt.env.PathSeparator()) + if pt.root != pt.env.PathSeparator() { + elements = append([]string{pt.root}, elements...) } n := len(elements) buffer.WriteString(elements[0]) @@ -206,13 +232,13 @@ func (pt *Path) getAgnosterPath(root, path string) string { return buffer.String() } -func (pt *Path) getAgnosterLeftPath(root, path string) string { +func (pt *Path) getAgnosterLeftPath() string { var buffer strings.Builder folderIcon := pt.props.GetString(FolderIcon, "..") separator := pt.getFolderSeparator() - elements := strings.Split(path, pt.env.PathSeparator()) - if root != pt.env.PathSeparator() { - elements = append([]string{root[:len(root)-1]}, elements...) + elements := strings.Split(pt.relative, pt.env.PathSeparator()) + if pt.root != pt.env.PathSeparator() { + elements = append([]string{pt.root}, elements...) } n := len(elements) buffer.WriteString(elements[0]) @@ -238,12 +264,12 @@ func (pt *Path) getRelevantLetter(folder string) string { return letter } -func (pt *Path) getLetterPath(root, path string) string { +func (pt *Path) getLetterPath() string { var buffer strings.Builder separator := pt.getFolderSeparator() - elements := strings.Split(path, pt.env.PathSeparator()) - if root != pt.env.PathSeparator() { - elements = append([]string{root[:len(root)-1]}, elements...) + elements := strings.Split(pt.relative, pt.env.PathSeparator()) + if pt.root != pt.env.PathSeparator() { + elements = append([]string{pt.root}, elements...) } n := len(elements) for i := 0; i < n-1; i++ { @@ -257,12 +283,12 @@ func (pt *Path) getLetterPath(root, path string) string { return buffer.String() } -func (pt *Path) getUniqueLettersPath(root, path string) string { +func (pt *Path) getUniqueLettersPath() string { var buffer strings.Builder separator := pt.getFolderSeparator() - elements := strings.Split(path, pt.env.PathSeparator()) - if root != pt.env.PathSeparator() { - elements = append([]string{root[:len(root)-1]}, elements...) + elements := strings.Split(pt.relative, pt.env.PathSeparator()) + if pt.root != pt.env.PathSeparator() { + elements = append([]string{pt.root}, elements...) } n := len(elements) letters := make(map[string]bool) @@ -285,112 +311,72 @@ func (pt *Path) getUniqueLettersPath(root, path string) string { return buffer.String() } -func (pt *Path) getAgnosterFullPath(root, path string) string { +func (pt *Path) getAgnosterFullPath() string { + path := strings.Trim(pt.relative, pt.env.PathSeparator()) path = pt.replaceFolderSeparators(path) - if root == pt.env.PathSeparator() { + if pt.root == pt.env.PathSeparator() { return path } - root = root[:len(root)-1] + pt.getFolderSeparator() - return root + path + return pt.root + pt.getFolderSeparator() + path } -func (pt *Path) getAgnosterShortPath(root, path string) string { - elements := strings.Split(path, pt.env.PathSeparator()) - if root != pt.env.PathSeparator() { - elements = append([]string{root[:len(root)-1]}, elements...) - } - depth := len(elements) +func (pt *Path) getAgnosterShortPath() string { + pathDepth := pt.pathDepth(pt.relative) maxDepth := pt.props.GetInt(MaxDepth, 1) if maxDepth < 1 { maxDepth = 1 } - hideRootLocation := pt.props.GetBool(HideRootLocation, false) - if !hideRootLocation { - maxDepth++ - } - if depth <= maxDepth { - return pt.getAgnosterFullPath(root, path) - } - separator := pt.getFolderSeparator() folderIcon := pt.props.GetString(FolderIcon, "..") - var buffer strings.Builder - if !hideRootLocation { - buffer.WriteString(fmt.Sprintf("%s%s", elements[0], separator)) - maxDepth-- - } - splitPos := depth - maxDepth - if splitPos != 1 { - buffer.WriteString(fmt.Sprintf("%s%s", folderIcon, separator)) - } - for i := splitPos; i < depth; i++ { - buffer.WriteString(elements[i]) - if i != depth-1 { - buffer.WriteString(separator) + hideRootLocation := pt.props.GetBool(HideRootLocation, false) + if pathDepth <= maxDepth { + if hideRootLocation { + pt.root = folderIcon } + return pt.getAgnosterFullPath() + } + pathSeparator := pt.env.PathSeparator() + folderSeparator := pt.getFolderSeparator() + rel := strings.TrimPrefix(pt.relative, pathSeparator) + splitted := strings.Split(rel, pathSeparator) + splitPos := pathDepth - maxDepth + var buffer strings.Builder + // unix root, needs to be replaced with the folder we're in at root level + root := pt.root + room := pathDepth - maxDepth + if root == pathSeparator { + root = splitted[0] + room-- + } + if hideRootLocation { + buffer.WriteString(folderIcon) + } else { + buffer.WriteString(root) + if room > 0 { + buffer.WriteString(folderSeparator) + buffer.WriteString(folderIcon) + } + } + for i := splitPos; i < pathDepth; i++ { + buffer.WriteString(fmt.Sprintf("%s%s", folderSeparator, splitted[i])) } return buffer.String() } -func (pt *Path) getFullPath(root, path string) string { - if root != pt.env.PathSeparator() { - root = root[:len(root)-1] + pt.getFolderSeparator() +func (pt *Path) getFullPath() string { + rel := pt.relative + if pt.root != pt.env.PathSeparator() { + rel = pt.env.PathSeparator() + rel } - path = pt.replaceFolderSeparators(path) - return root + path + path := pt.replaceFolderSeparators(rel) + return pt.root + path } -func (pt *Path) getFolderPath(path string) string { - return environment.Base(pt.env, path) +func (pt *Path) getFolderPath() string { + pwd := environment.Base(pt.env, pt.pwd) + return pt.replaceFolderSeparators(pwd) } -func (pt *Path) setPwd() { - if len(pt.pwd) > 0 { - return - } - if pt.env.Shell() == shell.PWSH || pt.env.Shell() == shell.PWSH5 { - pt.pwd = pt.env.Flags().PSWD - } - if len(pt.pwd) == 0 { - pt.pwd = pt.env.Pwd() - return - } - // ensure a clean path - root, path := environment.ParsePath(pt.env, pt.pwd) - pt.pwd = root + path -} - -func (pt *Path) getPwd() string { - pt.setPwd() - return pt.replaceMappedLocations(pt.pwd) -} - -func (pt *Path) formatRoot(root string) string { - n := len(root) - // trim the trailing separator first - root = root[:n-1] - // only preserve the trailing separator for a Unix/Windows/PSDrive root - if len(root) == 0 || (strings.HasPrefix(pt.pwd, root) && strings.HasSuffix(root, ":")) { - return root + pt.env.PathSeparator() - } - return root -} - -func (pt *Path) normalize(inputPath string) string { - normalized := inputPath - if strings.HasPrefix(normalized, "~") && (len(normalized) == 1 || environment.IsPathSeparator(pt.env, normalized[1])) { - normalized = pt.env.Home() + normalized[1:] - } - switch pt.env.GOOS() { - case environment.WINDOWS: - normalized = strings.ReplaceAll(normalized, "/", `\`) - fallthrough - case environment.DARWIN: - normalized = strings.ToLower(normalized) - } - return normalized -} - -func (pt *Path) replaceMappedLocations(pwd string) string { +func (pt *Path) replaceMappedLocations() (string, string) { mappedLocations := map[string]string{} // predefined mapped locations, can be disabled if pt.props.GetBool(MappedLocationsEnabled, true) { @@ -417,30 +403,117 @@ func (pt *Path) replaceMappedLocations(pwd string) string { } sort.Sort(sort.Reverse(sort.StringSlice(keys))) - cleanPwdRoot, cleanPwdPath := environment.ParsePath(pt.env, pwd) - pwdRoot := pt.normalize(cleanPwdRoot) - pwdPath := pt.normalize(cleanPwdPath) + root, relative := pt.parsePath(pt.pwd) + rootN := pt.normalize(root) + relativeN := pt.normalize(relative) + pathSeparator := pt.env.PathSeparator() + + formatRoot := func(root string) string { + // trim the trailing separator first + root = strings.TrimSuffix(root, pathSeparator) + // only preserve the trailing separator for a Unix/Windows/PSDrive root + if len(root) == 0 || strings.HasSuffix(root, ":") { + return root + pathSeparator + } + return root + } + for _, key := range keys { - keyRoot, keyPath := environment.ParsePath(pt.env, key) - if keyRoot != pwdRoot || !strings.HasPrefix(pwdPath, keyPath) { + keyRoot, keyRelative := pt.parsePath(key) + if keyRoot != rootN || !strings.HasPrefix(relativeN, keyRelative) { continue } value := mappedLocations[key] - rem := cleanPwdPath[len(keyPath):] - if len(rem) == 0 { + overflow := relative[len(keyRelative):] + if len(overflow) == 0 { // exactly match the full path - return value + return formatRoot(value), "" } - if len(keyPath) == 0 { + if len(keyRelative) == 0 { // only match the root - return value + pt.env.PathSeparator() + cleanPwdPath + return formatRoot(value), strings.Trim(relative, pathSeparator) } // match several prefix elements - if rem[0:1] == pt.env.PathSeparator() { - return value + rem + if overflow[0:1] == pt.env.PathSeparator() { + return formatRoot(value), strings.Trim(overflow, pathSeparator) } } - return cleanPwdRoot + cleanPwdPath + return formatRoot(root), strings.Trim(relative, pathSeparator) +} + +func (pt *Path) normalizePath(path string) string { + if pt.env.GOOS() != environment.WINDOWS { + return path + } + var clean []rune + for _, char := range path { + var lastChar rune + if len(clean) > 0 { + lastChar = clean[len(clean)-1:][0] + } + if char == '/' && lastChar != 60 { // 60 == <, this is done to ovoid replacing color codes + clean = append(clean, 92) // 92 == \ + continue + } + clean = append(clean, char) + } + return string(clean) +} + +// ParsePath parses an input path and returns a clean root and a clean path. +func (pt *Path) parsePath(inputPath string) (root, path string) { + if len(inputPath) == 0 { + return + } + separator := pt.env.PathSeparator() + clean := func(path string) string { + matches := regex.FindAllNamedRegexMatch(fmt.Sprintf(`(?P[^\%s]+)`, separator), path) + n := len(matches) - 1 + s := new(strings.Builder) + for i, m := range matches { + s.WriteString(m["element"]) + if i != n { + s.WriteString(separator) + } + } + return s.String() + } + + if pt.env.GOOS() == environment.WINDOWS { + inputPath = pt.normalizePath(inputPath) + // for a UNC path, extract \\hostname\sharename as the root + matches := regex.FindNamedRegexMatch(`^\\\\(?P[^\\]+)\\+(?P[^\\]+)\\*(?P[\s\S]*)$`, inputPath) + if len(matches) > 0 { + root = `\\` + matches["hostname"] + `\` + matches["sharename"] + `\` + path = clean(matches["path"]) + return + } + } + s := strings.SplitAfterN(inputPath, separator, 2) + root = s[0] + if !strings.HasSuffix(root, separator) { + // a root should end with a separator + root += separator + } + if len(s) == 2 { + path = clean(s[1]) + } + return root, path +} + +func (pt *Path) normalize(inputPath string) string { + normalized := inputPath + if strings.HasPrefix(normalized, "~") && (len(normalized) == 1 || environment.IsPathSeparator(pt.env, normalized[1])) { + normalized = pt.env.Home() + normalized[1:] + } + switch pt.env.GOOS() { + case environment.WINDOWS: + normalized = pt.normalizePath(normalized) + fallthrough + case environment.DARWIN: + normalized = strings.ToLower(normalized) + } + return normalized } func (pt *Path) replaceFolderSeparators(pwd string) string { diff --git a/src/segments/path_test.go b/src/segments/path_test.go index 89a060eb..370cd2d2 100644 --- a/src/segments/path_test.go +++ b/src/segments/path_test.go @@ -54,6 +54,14 @@ func TestParent(t *testing.T) { PathSeparator string FolderSeparatorIcon string }{ + { + Case: "Inside Home folder", + Expected: "~/", + HomePath: homeDir, + Pwd: homeDir + "/test", + GOOS: environment.DARWIN, + PathSeparator: "/", + }, { Case: "Home folder", HomePath: homeDir, @@ -68,14 +76,6 @@ func TestParent(t *testing.T) { GOOS: environment.DARWIN, PathSeparator: "/", }, - { - Case: "Inside Home folder", - Expected: "~/", - HomePath: homeDir, - Pwd: homeDir + "/test", - GOOS: environment.DARWIN, - PathSeparator: "/", - }, { Case: "Root", HomePath: homeDir, @@ -142,7 +142,7 @@ func TestParent(t *testing.T) { FolderSeparatorIcon: tc.FolderSeparatorIcon, }, } - path.pwd = tc.Pwd + path.setPaths() got := path.Parent() assert.EqualValues(t, tc.Expected, got, tc.Case) } @@ -163,354 +163,34 @@ func TestAgnosterPathStyles(t *testing.T) { HideRootLocation bool }{ { - Style: AgnosterFull, - Expected: "usr > location > whatever", + Style: Unique, + Expected: "~ > a > ab > abcd", HomePath: homeDir, - Pwd: "/usr/location/whatever", + Pwd: homeDir + "/ab/abc/abcd", PathSeparator: "/", FolderSeparatorIcon: " > ", }, { - Style: AgnosterFull, - Expected: "PSDRIVE: | src", + Style: Unique, + Expected: "~ > a > .a > abcd", HomePath: homeDir, - Pwd: "/foo", - Pswd: "PSDRIVE:/src", - PathSeparator: "/", - FolderSeparatorIcon: " | ", - }, - - { - Style: AgnosterShort, - Expected: "usr > .. > man", - HomePath: homeDir, - Pwd: "/usr/location/whatever/man", + Pwd: homeDir + "/ab/.abc/abcd", PathSeparator: "/", FolderSeparatorIcon: " > ", }, { - Style: AgnosterShort, - Expected: "~ > .. > man", + Style: Unique, + Expected: "~ > a > ab > abcd", HomePath: homeDir, - Pwd: homeDir + "/whatever/man", + Pwd: homeDir + "/ab/ab/abcd", PathSeparator: "/", FolderSeparatorIcon: " > ", }, { - Style: AgnosterShort, - Expected: "~ > projects", - HomePath: homeDir, - Pwd: homeDir + "/projects", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - }, - { - Style: AgnosterShort, - Expected: "usr > .. > bar > man", - HomePath: homeDir, - Pwd: "/usr/foo/bar/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - }, - { - Style: AgnosterShort, - Expected: "usr > foo > bar > man", - HomePath: homeDir, - Pwd: "/usr/foo/bar/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 3, - }, - { - Style: AgnosterShort, - Expected: "~ > .. > bar > man", - HomePath: homeDir, - Pwd: homeDir + "/foo/bar/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - }, - { - Style: AgnosterShort, - Expected: "~ > foo > bar > man", - HomePath: homeDir, - Pwd: homeDir + "/foo/bar/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 3, - }, - { - Style: AgnosterShort, - Expected: "PSDRIVE: | .. | init", - HomePath: homeDir, - Pwd: "/foo", - Pswd: "PSDRIVE:/src/init", - PathSeparator: "/", - FolderSeparatorIcon: " | ", - }, - { - Style: AgnosterShort, - Expected: "src | init", - HomePath: homeDir, - Pwd: "/foo", - Pswd: "PSDRIVE:/src/init", - PathSeparator: "/", - FolderSeparatorIcon: " | ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "PSDRIVE: | src", - HomePath: homeDir, - Pwd: "/foo", - Pswd: "PSDRIVE:/src", - PathSeparator: "/", - FolderSeparatorIcon: " | ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "~", - HomePath: homeDir, - Pwd: homeDir, - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 1, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "foo", - HomePath: homeDir, - Pwd: homeDir + "/foo", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 1, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "bar > man", - HomePath: homeDir, - Pwd: homeDir + "/bar/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "foo > bar > man", - HomePath: homeDir, - Pwd: "/usr/foo/bar/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 3, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "~ > foo", - HomePath: homeDir, - Pwd: homeDir + "/foo", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "~ > foo > bar", - HomePath: homeDir, - Pwd: homeDir + "/foo/bar", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - MaxDepth: 3, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "C:/", - HomePath: homeDir, - Pwd: "/mnt/c", - Pswd: "C:", - PathSeparator: "/", - FolderSeparatorIcon: " | ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "~ | space foo", - HomePath: homeDir, - Pwd: homeDir + "/space foo", - PathSeparator: "/", - FolderSeparatorIcon: " | ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "space foo", - HomePath: homeDir, - Pwd: homeDir + "/space foo", - PathSeparator: "/", - FolderSeparatorIcon: " | ", - MaxDepth: 1, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "C:\\", + Style: Unique, + Expected: "C > a > ab > abcd", HomePath: homeDirWindows, - Pwd: "C:", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - }, - { - Style: AgnosterShort, - Expected: "C: > .. > bar > man", - HomePath: homeDirWindows, - Pwd: "C:\\usr\\foo\\bar\\man", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - }, - { - Style: AgnosterShort, - Expected: "C: > .. > foo > bar > man", - HomePath: homeDirWindows, - Pwd: "C:\\usr\\foo\\bar\\man", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 3, - }, - { - Style: AgnosterShort, - Expected: "~ > .. > bar > man", - HomePath: homeDirWindows, - Pwd: homeDirWindows + "\\foo\\bar\\man", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - }, - { - Style: AgnosterShort, - Expected: "~ > foo > bar > man", - HomePath: homeDirWindows, - Pwd: homeDirWindows + "\\foo\\bar\\man", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 3, - }, - { - Style: AgnosterShort, - Expected: "~", - HomePath: homeDirWindows, - Pwd: homeDirWindows, - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 1, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "foo", - HomePath: homeDirWindows, - Pwd: homeDirWindows + "\\foo", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 1, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "~ > foo", - HomePath: homeDirWindows, - Pwd: homeDirWindows + "\\foo", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: ".. > bar > man", - HomePath: homeDirWindows, - Pwd: homeDirWindows + "\\foo\\bar\\man", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - MaxDepth: 2, - HideRootLocation: true, - }, - { - Style: AgnosterShort, - Expected: "\\\\localhost\\c$", - HomePath: homeDirWindows, - Pwd: "\\\\localhost\\c$", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - }, - { - Style: AgnosterShort, - Expected: "\\\\localhost\\c$ > some", - HomePath: homeDirWindows, - Pwd: "\\\\localhost\\c$\\some", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - FolderSeparatorIcon: " > ", - }, - - { - Style: Mixed, - Expected: "~ > .. > man", - HomePath: homeDir, - Pwd: homeDir + "/whatever/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - }, - { - Style: Mixed, - Expected: "~ > ab > .. > man", - HomePath: homeDir, - Pwd: homeDir + "/ab/whatever/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - }, - { - Style: Mixed, - Expected: "usr > foo > bar > .. > man", - HomePath: homeDir, - Pwd: "/usr/foo/bar/foobar/man", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - }, - { - Style: Mixed, - Expected: "whatever > .. > foo > bar", - HomePath: homeDir, - Pwd: "/whatever/foobar/foo/bar", - PathSeparator: "/", - FolderSeparatorIcon: " > ", - }, - { - Style: Mixed, - Expected: "C: > .. > foo > .. > man", - HomePath: homeDirWindows, - Pwd: "C:\\Users\\foo\\foobar\\man", + Pwd: "C:\\ab\\ab\\abcd", GOOS: environment.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", @@ -641,38 +321,359 @@ func TestAgnosterPathStyles(t *testing.T) { }, { - Style: Unique, - Expected: "~ > a > ab > abcd", + Style: Mixed, + Expected: "~ > .. > man", HomePath: homeDir, - Pwd: homeDir + "/ab/abc/abcd", + Pwd: homeDir + "/whatever/man", PathSeparator: "/", FolderSeparatorIcon: " > ", }, { - Style: Unique, - Expected: "~ > a > .a > abcd", + Style: Mixed, + Expected: "~ > ab > .. > man", HomePath: homeDir, - Pwd: homeDir + "/ab/.abc/abcd", + Pwd: homeDir + "/ab/whatever/man", PathSeparator: "/", FolderSeparatorIcon: " > ", }, { - Style: Unique, - Expected: "~ > a > ab > abcd", + Style: Mixed, + Expected: "usr > foo > bar > .. > man", HomePath: homeDir, - Pwd: homeDir + "/ab/ab/abcd", + Pwd: "/usr/foo/bar/foobar/man", PathSeparator: "/", FolderSeparatorIcon: " > ", }, { - Style: Unique, - Expected: "C > a > ab > abcd", + Style: Mixed, + Expected: "whatever > .. > foo > bar", + HomePath: homeDir, + Pwd: "/whatever/foobar/foo/bar", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + }, + { + Style: Mixed, + Expected: "C:\\ > .. > foo > .. > man", HomePath: homeDirWindows, - Pwd: "C:\\ab\\ab\\abcd", + Pwd: "C:\\Users\\foo\\foobar\\man", GOOS: environment.WINDOWS, PathSeparator: "\\", FolderSeparatorIcon: " > ", }, + + { + Style: AgnosterFull, + Expected: "usr > location > whatever", + HomePath: homeDir, + Pwd: "/usr/location/whatever", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + }, + { + Style: AgnosterFull, + Expected: "PSDRIVE:/ | src", + HomePath: homeDir, + Pwd: "/foo", + Pswd: "PSDRIVE:/src", + PathSeparator: "/", + FolderSeparatorIcon: " | ", + }, + + { + Style: AgnosterShort, + Expected: ".. | src | init", + HomePath: homeDir, + Pwd: "/foo", + Pswd: "PSDRIVE:/src/init", + PathSeparator: "/", + FolderSeparatorIcon: " | ", + MaxDepth: 2, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: "usr > foo > bar > man", + HomePath: homeDir, + Pwd: "/usr/foo/bar/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 3, + }, + { + Style: AgnosterShort, + Expected: ".. | src", + HomePath: homeDir, + Pwd: "/foo", + Pswd: "PSDRIVE:/src", + PathSeparator: "/", + FolderSeparatorIcon: " | ", + MaxDepth: 2, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: "~ > projects", + HomePath: homeDir, + Pwd: homeDir + "/projects", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + }, + { + Style: AgnosterShort, + Expected: "\\\\localhost\\c$ > some", + HomePath: homeDirWindows, + Pwd: "\\\\localhost\\c$\\some", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + }, + + { + Style: AgnosterShort, + Expected: "~", + HomePath: homeDir, + Pwd: homeDir, + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 1, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: "\\\\localhost\\c$", + HomePath: homeDirWindows, + Pwd: "\\\\localhost\\c$", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + }, + { + Style: AgnosterShort, + Expected: "usr > .. > bar > man", + HomePath: homeDir, + Pwd: "/usr/foo/bar/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + }, + { + Style: AgnosterShort, + Expected: "~ > .. > man", + HomePath: homeDir, + Pwd: homeDir + "/whatever/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + }, + { + Style: AgnosterShort, + Expected: "usr > .. > man", + HomePath: homeDir, + Pwd: "/usr/location/whatever/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + }, + { + Style: AgnosterShort, + Expected: ".. > bar > man", + HomePath: homeDirWindows, + Pwd: homeDirWindows + "\\foo\\bar\\man", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: "~ > .. > bar > man", + HomePath: homeDir, + Pwd: homeDir + "/foo/bar/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + }, + { + Style: AgnosterShort, + Expected: "~ > foo > bar > man", + HomePath: homeDir, + Pwd: homeDir + "/foo/bar/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 3, + }, + { + Style: AgnosterShort, + Expected: "PSDRIVE:/ | .. | init", + HomePath: homeDir, + Pwd: "/foo", + Pswd: "PSDRIVE:/src/init", + PathSeparator: "/", + FolderSeparatorIcon: " | ", + }, + { + Style: AgnosterShort, + Expected: ".. > foo", + HomePath: homeDir, + Pwd: homeDir + "/foo", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 1, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. > bar > man", + HomePath: homeDir, + Pwd: homeDir + "/bar/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. > foo > bar > man", + HomePath: homeDir, + Pwd: "/usr/foo/bar/man", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 3, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. > foo", + HomePath: homeDir, + Pwd: homeDir + "/foo", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. > foo > bar", + HomePath: homeDir, + Pwd: homeDir + "/foo/bar", + PathSeparator: "/", + FolderSeparatorIcon: " > ", + MaxDepth: 3, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: "C:/", + HomePath: homeDir, + Pwd: "/mnt/c", + Pswd: "C:", + PathSeparator: "/", + FolderSeparatorIcon: " | ", + MaxDepth: 2, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. | space foo", + HomePath: homeDir, + Pwd: homeDir + "/space foo", + PathSeparator: "/", + FolderSeparatorIcon: " | ", + MaxDepth: 2, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. | space foo", + HomePath: homeDir, + Pwd: homeDir + "/space foo", + PathSeparator: "/", + FolderSeparatorIcon: " | ", + MaxDepth: 1, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: "C:\\", + HomePath: homeDirWindows, + Pwd: "C:", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + }, + { + Style: AgnosterShort, + Expected: "C:\\ > .. > bar > man", + HomePath: homeDirWindows, + Pwd: "C:\\usr\\foo\\bar\\man", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + }, + { + Style: AgnosterShort, + Expected: "C:\\ > .. > foo > bar > man", + HomePath: homeDirWindows, + Pwd: "C:\\usr\\foo\\bar\\man", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 3, + }, + { + Style: AgnosterShort, + Expected: "~ > .. > bar > man", + HomePath: homeDirWindows, + Pwd: homeDirWindows + "\\foo\\bar\\man", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + }, + { + Style: AgnosterShort, + Expected: "~ > foo > bar > man", + HomePath: homeDirWindows, + Pwd: homeDirWindows + "\\foo\\bar\\man", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 3, + }, + { + Style: AgnosterShort, + Expected: "~", + HomePath: homeDirWindows, + Pwd: homeDirWindows, + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 1, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. > foo", + HomePath: homeDirWindows, + Pwd: homeDirWindows + "\\foo", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 1, + HideRootLocation: true, + }, + { + Style: AgnosterShort, + Expected: ".. > foo", + HomePath: homeDirWindows, + Pwd: homeDirWindows + "\\foo", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + FolderSeparatorIcon: " > ", + MaxDepth: 2, + HideRootLocation: true, + }, } for _, tc := range cases { env := new(mock.MockedEnvironment) @@ -696,7 +697,8 @@ func TestAgnosterPathStyles(t *testing.T) { HideRootLocation: tc.HideRootLocation, }, } - path.setPath() + path.setPaths() + path.setStyle() got := renderTemplate(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got) } @@ -824,7 +826,8 @@ func TestFullAndFolderPath(t *testing.T) { props: props, StackCount: env.StackCount(), } - path.setPath() + path.setPaths() + path.setStyle() got := renderTemplate(env, tc.Template, path) assert.Equal(t, tc.Expected, got) } @@ -872,7 +875,8 @@ func TestFullPathCustomMappedLocations(t *testing.T) { MappedLocations: tc.MappedLocations, }, } - path.setPath() + path.setPaths() + path.setStyle() got := renderTemplate(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got) } @@ -899,12 +903,13 @@ func TestFolderPathCustomMappedLocations(t *testing.T) { }, }, } - path.setPath() + path.setPaths() + path.setStyle() got := renderTemplate(env, "{{ .Path }}", path) assert.Equal(t, "#", got) } -func TestAgnosterPath(t *testing.T) { //nolint:dupl +func TestAgnosterPath(t *testing.T) { cases := []struct { Case string Expected string @@ -915,7 +920,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }{ { Case: "Windows outside home", - Expected: "C: > f > f > location", + Expected: "C:\\ > f > f > location", Home: homeDirWindows, PWD: "C:\\Program Files\\Go\\location", GOOS: environment.WINDOWS, @@ -931,7 +936,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, { Case: "Windows inside home zero levels", - Expected: "C: > location", + Expected: "C:\\ > location", Home: homeDirWindows, PWD: "C:\\location", GOOS: environment.WINDOWS, @@ -939,7 +944,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, { Case: "Windows inside home one level", - Expected: "C: > f > location", + Expected: "C:\\ > f > location", Home: homeDirWindows, PWD: "C:\\Program Files\\location", GOOS: environment.WINDOWS, @@ -947,7 +952,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower case drive letter", - Expected: "C: > Windows", + Expected: "C:\\ > Windows", Home: homeDirWindows, PWD: "C:\\Windows\\", GOOS: environment.WINDOWS, @@ -955,7 +960,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower case drive letter (other)", - Expected: "P: > Other", + Expected: "P:\\ > Other", Home: homeDirWindows, PWD: "P:\\Other\\", GOOS: environment.WINDOWS, @@ -963,7 +968,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower word drive", - Expected: "some: > some", + Expected: "some:\\ > some", Home: homeDirWindows, PWD: "some:\\some\\", GOOS: environment.WINDOWS, @@ -971,7 +976,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower word drive (ending with c)", - Expected: "src: > source", + Expected: "src:\\ > source", Home: homeDirWindows, PWD: "src:\\source\\", GOOS: environment.WINDOWS, @@ -979,7 +984,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower word drive (arbitrary cases)", - Expected: "sRc: > source", + Expected: "sRc:\\ > source", Home: homeDirWindows, PWD: "sRc:\\source\\", GOOS: environment.WINDOWS, @@ -1031,7 +1036,7 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl }, } - for _, tc := range cases { + for _, tc := range cases { //nolint:dupl env := new(mock.MockedEnvironment) env.On("Home").Return(tc.Home) env.On("PathSeparator").Return(tc.PathSeparator) @@ -1051,13 +1056,14 @@ func TestAgnosterPath(t *testing.T) { //nolint:dupl HomeIcon: "~", }, } - path.setPath() + path.setPaths() + path.setStyle() got := renderTemplate(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got, tc.Case) } } -func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl +func TestAgnosterLeftPath(t *testing.T) { cases := []struct { Case string Expected string @@ -1066,14 +1072,6 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl GOOS string PathSeparator string }{ - { - Case: "Windows outside home", - Expected: "C: > Program Files > f > f", - Home: homeDirWindows, - PWD: "C:\\Program Files\\Go\\location", - GOOS: environment.WINDOWS, - PathSeparator: "\\", - }, { Case: "Windows inside home", Expected: "~ > Documents > f > f", @@ -1082,9 +1080,17 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl GOOS: environment.WINDOWS, PathSeparator: "\\", }, + { + Case: "Windows outside home", + Expected: "C:\\ > Program Files > f > f", + Home: homeDirWindows, + PWD: "C:\\Program Files\\Go\\location", + GOOS: environment.WINDOWS, + PathSeparator: "\\", + }, { Case: "Windows inside home zero levels", - Expected: "C: > location", + Expected: "C:\\ > location", Home: homeDirWindows, PWD: "C:\\location", GOOS: environment.WINDOWS, @@ -1092,7 +1098,7 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl }, { Case: "Windows inside home one level", - Expected: "C: > Program Files > f", + Expected: "C:\\ > Program Files > f", Home: homeDirWindows, PWD: "C:\\Program Files\\location", GOOS: environment.WINDOWS, @@ -1100,7 +1106,7 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower case drive letter", - Expected: "C: > Windows", + Expected: "C:\\ > Windows", Home: homeDirWindows, PWD: "C:\\Windows\\", GOOS: environment.WINDOWS, @@ -1108,7 +1114,7 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower case drive letter (other)", - Expected: "P: > Other", + Expected: "P:\\ > Other", Home: homeDirWindows, PWD: "P:\\Other\\", GOOS: environment.WINDOWS, @@ -1116,7 +1122,7 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower word drive", - Expected: "some: > some", + Expected: "some:\\ > some", Home: homeDirWindows, PWD: "some:\\some\\", GOOS: environment.WINDOWS, @@ -1124,7 +1130,7 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower word drive (ending with c)", - Expected: "src: > source", + Expected: "src:\\ > source", Home: homeDirWindows, PWD: "src:\\source\\", GOOS: environment.WINDOWS, @@ -1132,7 +1138,7 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl }, { Case: "Windows lower word drive (arbitrary cases)", - Expected: "sRc: > source", + Expected: "sRc:\\ > source", Home: homeDirWindows, PWD: "sRc:\\source\\", GOOS: environment.WINDOWS, @@ -1184,7 +1190,7 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl }, } - for _, tc := range cases { + for _, tc := range cases { //nolint:dupl env := new(mock.MockedEnvironment) env.On("Home").Return(tc.Home) env.On("PathSeparator").Return(tc.PathSeparator) @@ -1204,7 +1210,8 @@ func TestAgnosterLeftPath(t *testing.T) { //nolint:dupl HomeIcon: "~", }, } - path.setPath() + path.setPaths() + path.setStyle() got := renderTemplate(env, "{{ .Path }}", path) assert.Equal(t, tc.Expected, got, tc.Case) } @@ -1256,8 +1263,8 @@ func TestGetPwd(t *testing.T) { }, }, } - got := path.getPwd() - assert.Equal(t, tc.Expected, got) + path.setPaths() + assert.Equal(t, tc.Expected, path.pwd) } } @@ -1306,12 +1313,12 @@ func TestNormalizePath(t *testing.T) { GOOS string Expected string }{ + {Input: "/foo/~/bar", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "\\foo\\~\\bar"}, {Input: homeDirWindows + "\\Foo", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "c:\\users\\someone\\foo"}, {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: environment.LINUX, Expected: homeDir + "/Bob\\Foo"}, {Input: "~/Bob\\Foo", HomeDir: homeDir, GOOS: environment.DARWIN, Expected: homeDir + "/bob\\foo"}, {Input: "~\\Bob\\Foo", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "c:\\users\\someone\\bob\\foo"}, {Input: "/foo/~/bar", HomeDir: homeDir, GOOS: environment.LINUX, Expected: "/foo/~/bar"}, - {Input: "/foo/~/bar", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "\\foo\\~\\bar"}, {Input: "~/baz", HomeDir: homeDir, GOOS: environment.LINUX, Expected: homeDir + "/baz"}, {Input: "~/baz", HomeDir: homeDirWindows, GOOS: environment.WINDOWS, Expected: "c:\\users\\someone\\baz"}, }