2021-12-17 06:37:43 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTildeReplacement_NoAction(t *testing.T) {
|
2022-03-20 11:25:11 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
if path := "/boop"; substituteHomeForTildeInPath(path) != path {
|
2021-12-17 06:37:43 +01:00
|
|
|
t.Error("Altered path when no alteration was expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTildeReplacement_TildeOnly(t *testing.T) {
|
2022-03-20 11:25:11 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
if path := "~"; substituteHomeForTildeInPath(path) == path {
|
2021-12-17 06:37:43 +01:00
|
|
|
t.Error("Path unaltered when alteration was expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTildeReplacement_TildeDir(t *testing.T) {
|
2022-03-20 11:25:11 +01:00
|
|
|
t.Parallel()
|
|
|
|
|
2021-12-17 06:37:43 +01:00
|
|
|
path := "~/boop"
|
2022-03-20 11:25:11 +01:00
|
|
|
actual := substituteHomeForTildeInPath(path)
|
2021-12-17 06:37:43 +01:00
|
|
|
if strings.HasPrefix(actual, "~") {
|
|
|
|
t.Error("Altered path still contains ~")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.HasSuffix(actual, "boop") {
|
|
|
|
t.Error("Altered path does not end with directory to be retained")
|
|
|
|
}
|
|
|
|
}
|