-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank_test.go
71 lines (62 loc) · 1.52 KB
/
rank_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetRankForPath(t *testing.T) {
var pathRankTests = []struct {
inputPath string
expectedRank int
}{
{"/home/char8/bin", -1},
{"/home/char8/foo/bar/baz", -1},
{"/homer/foo/baz", 0},
{"/Users/charith/bin", -2},
{"/Users/someone/bin/", -2},
{"/usr/bin/", 2},
{"/bin/", 3},
}
for _, test := range pathRankTests {
rank := getRankForPath(test.inputPath)
assert.Equal(t, test.expectedRank, rank)
}
}
func TestGetOrderedPathsEmpty(t *testing.T) {
result, err := GetOrderedPaths([]string{})
assert.Nil(t, err)
assert.Len(t, result, 0)
}
func TestGetOrderedPathsSimpleDeduplicates(t *testing.T) {
paths := []string{"/usr/bin/test", "/home/char8/bin/test", "/usr/bin/test"}
expected := []string{"/home/char8/bin/test", "/usr/bin/test"}
ranked, err := GetOrderedPaths(paths)
assert.Nil(t, err)
assert.ElementsMatch(t, expected, ranked)
}
func TestGetOrderedPaths(t *testing.T) {
paths := []string{
"/usr/bin/site_perl",
"/home/char8/bin/",
"/usr/local/sbin",
"/home/char8/.local/bin",
"/usr/bin/core_perl",
"/home/char8/bin/",
"/usr/local/bin",
"/home/char8/.local/bin",
"/usr/bin/vendor_perl",
"/usr/bin",
}
ranked, err := GetOrderedPaths(paths)
assert.Nil(t, err)
expected := []string{
"/home/char8/.local/bin",
"/home/char8/bin",
"/usr/local/bin",
"/usr/local/sbin",
"/usr/bin",
"/usr/bin/core_perl",
"/usr/bin/site_perl",
"/usr/bin/vendor_perl",
}
assert.ElementsMatch(t, expected, ranked)
}