-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_test.go
89 lines (83 loc) · 1.99 KB
/
path_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
package main
import "testing"
func testSamePath(p1, p2 []string) bool {
if len(p1) != len(p2) {
return false
}
for i, v := range p1 {
if v != p2[i] {
return false
}
}
return true
}
func TestGetDisectPath(t *testing.T) {
var testdata = []struct {
Base string
New string
Outslice []string
Cmds []string
ErrNil bool
}{
{"", "path", []string{"path"}, []string{}, true},
{"path/more", "path/more/not", []string{"not"}, []string{}, true},
{"path/more", "path/more/not/_hooks/0", []string{"not"}, []string{"_hooks", "0"}, true},
{"path/more", "path", []string{}, []string{}, false},
{"/path/more", "more/path", []string{}, []string{}, false},
}
for i, td := range testdata {
comps, cmds, err := disectPath(td.Base, td.New)
if td.ErrNil != (err == nil) {
t.Error("Relative Test failed Error Nr:", i, err)
}
if !td.ErrNil {
continue
}
if !testSamePath(td.Outslice, comps) {
t.Error("Relative Test failed Compare Nr:", i)
}
if !testSamePath(td.Cmds, cmds) {
t.Error("Relative Test failed Cmds Nr:", i)
}
}
}
func TestSplitPath(t *testing.T) {
var splittest = []struct {
Instring string
Outslice []string
}{
{"path", []string{"path"}},
{"path/", []string{"path"}},
{"path/more", []string{"path", "more"}},
{"/path/more", []string{"path", "more"}},
}
for i, st := range splittest {
if !testSamePath(splitPath(st.Instring), st.Outslice) {
t.Error("Split Test failed Nr: ", i)
}
}
}
func TestIsCommand(t *testing.T) {
if !isCommand("_hooks") {
t.Error("isCommand _hooks not recognized")
}
if isCommand("_asdf") {
t.Error("isCommand random accepted")
}
}
func TestContainsCommand(t *testing.T) {
var pathtests = []struct {
Instring string
Contains bool
}{
{"path", false},
{"path/_hooks", true},
{"path/_hooks/something", true},
{"path/_hookssomething/a", false},
}
for i, st := range pathtests {
if containsCommand(splitPath(st.Instring)) != st.Contains {
t.Error("ContainCommand failed Nr: ", i)
}
}
}