-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
pathutil_unix_test.go
52 lines (41 loc) · 1.36 KB
/
pathutil_unix_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || nacl || linux || netbsd || openbsd || solaris
package pathutil_test
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/adrg/xdg/internal/pathutil"
)
func TestExpandHome(t *testing.T) {
home := "/home/test"
require.Equal(t, home, pathutil.ExpandHome("~", home))
require.Equal(t, home, pathutil.ExpandHome("$HOME", home))
require.Equal(t, filepath.Join(home, "appname"), pathutil.ExpandHome("~/appname", home))
require.Equal(t, filepath.Join(home, "appname"), pathutil.ExpandHome("$HOME/appname", home))
require.Equal(t, "", pathutil.ExpandHome("", home))
require.Equal(t, home, pathutil.ExpandHome(home, ""))
require.Equal(t, "", pathutil.ExpandHome("", ""))
require.Equal(t, home, pathutil.ExpandHome(home, home))
require.Equal(t, "/", pathutil.ExpandHome("~", "/"))
require.Equal(t, "/", pathutil.ExpandHome("$HOME", "/"))
require.Equal(t, "/usr/bin", pathutil.ExpandHome("~/bin", "/usr"))
require.Equal(t, "/usr/bin", pathutil.ExpandHome("$HOME/bin", "/usr"))
}
func TestUnique(t *testing.T) {
input := []string{
"",
"/home",
"/home/test",
"a",
"~/appname",
"$HOME/appname",
"a",
"/home",
}
expected := []string{
"/home",
"/home/test",
"/home/test/appname",
}
require.EqualValues(t, expected, pathutil.Unique(input, "/home/test"))
}