@@ -12,124 +12,31 @@ func TestPatternMatches(t *testing.T) {
1212 wd , err := os .Getwd ()
1313 require .NoError (t , err )
1414
15- wdParts := SplitPath (wd )
16- wdLen := len (wdParts )
17-
1815 testCases := []struct {
1916 path string
20- prefix int
2117 expected []string
2218 }{
23- {"cmd" , wdLen + 1 , []string {
19+ {"cmd" , []string {
2420 filepath .Join (wd , "cmd" ),
2521 }},
26- {"cmd/*" , wdLen + 1 , []string {
22+ {"cmd/*" , []string {
2723 filepath .Join (wd , "cmd/gitbase" ),
2824 }},
29- {"cmd/gitbase/*" , wdLen + 2 , []string {
25+ {"cmd/gitbase/*" , []string {
3026 filepath .Join (wd , "cmd/gitbase/command" ),
3127 filepath .Join (wd , "cmd/gitbase/main.go" ),
3228 }},
33- {"cmd/../cmd/gitbase/*" , wdLen + 2 , []string {
29+ {"cmd/../cmd/gitbase/*" , []string {
3430 filepath .Join (wd , "cmd/gitbase/command" ),
3531 filepath .Join (wd , "cmd/gitbase/main.go" ),
3632 }},
3733 }
3834
3935 for _ , test := range testCases {
4036 t .Run (test .path , func (t * testing.T ) {
41- prefix , files , err := PatternMatches (test .path )
37+ files , err := PatternMatches (test .path )
4238 require .NoError (t , err )
43- require .Equal (t , test .prefix , prefix )
4439 require .Exactly (t , test .expected , files )
4540 })
4641 }
4742}
48-
49- func TestPatternPrefixDepth (t * testing.T ) {
50- testCases := []struct {
51- path string
52- expected int
53- }{
54- {"" , 0 },
55- {"root" , 1 },
56-
57- {"/root" , 1 },
58- {"/root/*" , 1 },
59- {"/root/*/tmp" , 1 },
60- {"/root/*/tmp/borges" , 1 },
61- {"/var/lib/gitbase" , 3 },
62- {"/var/lib/gitbase/*" , 3 },
63- {"/var/lib/gitbase/*/repos/a" , 3 },
64- {"/var/lib/gitbase/[aeiou]/repos/a" , 3 },
65- {"/var/lib/gitbase/??/repos/a" , 3 },
66- {"/var/lib/gitbase/??/repos/a" , 3 },
67-
68- // escaped globs
69- {"/var/lib/gitbase/\\ */repos/a" , 6 },
70- {"/var/lib/gitbase/\\ [/repos/a" , 6 },
71- {"/var/lib/gitbase/\\ ?/repos/a" , 6 },
72-
73- // relative
74- {"var/lib/gitbase/*/repos/a" , 3 },
75- {"var/lib/gitbase/[aeiou]/repos/a" , 3 },
76- {"var/lib/gitbase/??/repos/a" , 3 },
77- {"var/lib/gitbase/??/repos/a" , 3 },
78- }
79-
80- for _ , test := range testCases {
81- t .Run (test .path , func (t * testing.T ) {
82- num := PatternPrefixDepth (test .path )
83- require .Equal (t , test .expected , num )
84- })
85- }
86- }
87-
88- func TestIDFromPath (t * testing.T ) {
89- testCases := []struct {
90- prefix int
91- path string
92- expected string
93- }{
94- {0 , "/path" , "path" },
95- {0 , "/path/" , "path" },
96- {0 , "/path/one.git" , "path/one.git" },
97- {1 , "/path/one.git" , "one.git" },
98- {1 , "/path/00/one.git" , "00/one.git" },
99- {2 , "/path/00/one.git" , "one.git" },
100- {2 , "/path/00/two.git" , "two.git" },
101- {2 , "/path/00/three.git" , "three.git" },
102- {2 , "path/00/three.git" , "three.git" },
103- }
104-
105- for _ , test := range testCases {
106- t .Run (test .path , func (t * testing.T ) {
107- id := IDFromPath (test .prefix , test .path )
108- require .Exactly (t , test .expected , id )
109- })
110- }
111- }
112-
113- func TestSplitPath (t * testing.T ) {
114- testCases := []struct {
115- path string
116- expected []string
117- }{
118- {"" , []string {}},
119- {"root" , []string {"root" }},
120- {"/root" , []string {"root" }},
121- {"/root/" , []string {"root" }},
122- {"root/" , []string {"root" }},
123- {"root/other" , []string {"root" , "other" }},
124- {"root//other" , []string {"root" , "other" }},
125- {"/root//other" , []string {"root" , "other" }},
126- {"/root//other/" , []string {"root" , "other" }},
127- }
128-
129- for _ , test := range testCases {
130- t .Run (test .path , func (t * testing.T ) {
131- path := SplitPath (test .path )
132- require .Exactly (t , test .expected , path )
133- })
134- }
135- }
0 commit comments