/
pathutil_plan9_test.go
52 lines (42 loc) · 1.28 KB
/
pathutil_plan9_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 plan9
// +build plan9
package pathutil_test
import (
"path/filepath"
"testing"
"github.com/adrg/xdg/internal/pathutil"
"github.com/stretchr/testify/require"
)
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"))
}