-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfind_test.go
93 lines (85 loc) · 1.57 KB
/
find_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package depfile
import (
"path"
"testing"
)
func TestFind(t *testing.T) {
var check = func(query string, want string, got *DepFile) {
if got == nil {
t.Errorf("Expected %s to resolve to %s but got nil", query, want)
} else if got.Name != want {
t.Errorf("Expected %s to resolve to %s but got %v", query, want, got.Name)
}
}
var fnames = []string{
"requirements.txt",
"package.json",
"package-lock.json",
"composer.json",
"composer.lock",
"Gemfile",
"Gemfile.lock",
"bower.json",
"yarn.lock",
"pom.xml",
}
t.Run("Canonical", func(t *testing.T) {
for _, fname := range fnames {
got := Find(fname)
check(fname, fname, got)
}
})
t.Run("Subdir", func(t *testing.T) {
for _, fname := range fnames {
q := path.Join("sub/dir", fname)
got := Find(q)
check(q, fname, got)
}
})
t.Run("Aliases", func(t *testing.T) {
var tcs = []struct {
Queries []string
Result string
}{
{
Queries: []string{
"requirements.pip",
"requires.txt",
"requirements-dev.txt",
},
Result: "requirements.txt",
},
{
Queries: []string{
"xyz.gemspec",
"activerecord.gemspec",
},
Result: "gemspec",
},
{
Queries: []string{
"gems.rb",
},
Result: "Gemfile",
},
{
Queries: []string{
"gems.locked",
},
Result: "Gemfile.lock",
},
{
Queries: []string{
"npm-shrinkwrap.json",
},
Result: "package-lock.json",
},
}
for _, tc := range tcs {
for _, q := range tc.Queries {
got := Find(q)
check(q, tc.Result, got)
}
}
})
}