1
1
mirror of https://github.com/cooperspencer/gickup synced 2024-10-18 13:48:07 +02:00
gickup/main_test.go
Colin Dean c05e8c9329
Extracts tilde-in-home check and tests it (#45)
* Extract user home directory detection to a function

* Extracts tilde-in-path substitution and tests it
2021-12-17 06:37:43 +01:00

33 lines
720 B
Go

package main
import (
"strings"
"testing"
)
func TestTildeReplacement_NoAction(t *testing.T) {
path := "/boop"
if SubstituteHomeForTildeInPath(path) != path {
t.Error("Altered path when no alteration was expected")
}
}
func TestTildeReplacement_TildeOnly(t *testing.T) {
path := "~"
if SubstituteHomeForTildeInPath(path) == path {
t.Error("Path unaltered when alteration was expected")
}
}
func TestTildeReplacement_TildeDir(t *testing.T) {
path := "~/boop"
actual := SubstituteHomeForTildeInPath(path)
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")
}
}