@@ -24,9 +24,29 @@ func TestNewFromFile(t *testing.T) {
24
24
}
25
25
26
26
// perform the gitignore test
27
- withfile (t , _test )
27
+ withfile (t , _test , _GITIGNORE )
28
28
} // TestNewFromFile()
29
29
30
+ func TestNewFromWhitespaceFile (t * testing.T ) {
31
+ _test := & gitignoretest {}
32
+ _test .instance = func (file string ) (gitignore.GitIgnore , error ) {
33
+ return gitignore .NewFromFile (file )
34
+ }
35
+
36
+ // perform the gitignore test
37
+ withfile (t , _test , _GITIGNORE_WHITESPACE )
38
+ } // TestNewFromWhitespaceFile()
39
+
40
+ func TestNewFromEmptyFile (t * testing.T ) {
41
+ _test := & gitignoretest {}
42
+ _test .instance = func (file string ) (gitignore.GitIgnore , error ) {
43
+ return gitignore .NewFromFile (file )
44
+ }
45
+
46
+ // perform the gitignore test
47
+ withfile (t , _test , "" )
48
+ } // TestNewFromEmptyFile()
49
+
30
50
func TestNewWithErrors (t * testing.T ) {
31
51
_test := & gitignoretest {}
32
52
_test .error = func (e gitignore.Error ) bool {
@@ -57,10 +77,10 @@ func TestNewWithErrors(t *testing.T) {
57
77
}
58
78
59
79
// perform the gitignore test
60
- withfile (t , _test )
80
+ withfile (t , _test , _GITIGNORE )
61
81
62
82
_test .error = nil
63
- withfile (t , _test )
83
+ withfile (t , _test , _GITIGNORE )
64
84
} // TestNewWithErrors()
65
85
66
86
func TestNewWithCache (t * testing.T ) {
@@ -92,14 +112,14 @@ func TestNewWithCache(t *testing.T) {
92
112
}
93
113
94
114
// perform the gitignore test
95
- withfile (t , _test )
115
+ withfile (t , _test , _GITIGNORE )
96
116
97
117
// repeat the tests while accumulating errors
98
118
_test .error = func (e gitignore.Error ) bool {
99
119
_test .errors = append (_test .errors , e )
100
120
return true
101
121
}
102
- withfile (t , _test )
122
+ withfile (t , _test , _GITIGNORE )
103
123
104
124
// create a temporary .gitignore
105
125
_file , _err := file (_GITIGNORE )
@@ -185,9 +205,9 @@ func TestNew(t *testing.T) {
185
205
}
186
206
} // TestNew()
187
207
188
- func withfile (t * testing.T , test * gitignoretest ) {
208
+ func withfile (t * testing.T , test * gitignoretest , content string ) {
189
209
// create a temporary .gitignore
190
- _file , _err := file (_GITIGNORE )
210
+ _file , _err := file (content )
191
211
if _err != nil {
192
212
t .Fatalf ("unable to create temporary .gitignore: %s" , _err .Error ())
193
213
}
@@ -241,7 +261,7 @@ func withfile(t *testing.T, test *gitignoretest) {
241
261
}
242
262
}
243
263
244
- // test NewFromFile() behaves as expected if the .gtignore file does
264
+ // test NewFromFile() behaves as expected if the .gitgnore file does
245
265
// not exist
246
266
_err = os .Remove (_file .Name ())
247
267
if _err != nil {
@@ -275,7 +295,7 @@ func withfile(t *testing.T, test *gitignoretest) {
275
295
276
296
// test NewFromFile() behaves as expected if absolute path of the
277
297
// .gitignore cannot be determined
278
- _map := map [string ]string {gitignore .File : _GITIGNORE }
298
+ _map := map [string ]string {gitignore .File : content }
279
299
_dir , _err = dir (_map )
280
300
if _err != nil {
281
301
t .Fatalf ("unable to create temporary directory: %s" , _err .Error ())
0 commit comments