27
27
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28
28
*/
29
29
30
- package test
30
+ package ctags
31
31
32
32
import (
33
33
"io/ioutil"
34
34
"path/filepath"
35
35
"testing"
36
36
37
- "arduino.cc/builder/ctags"
37
+ "arduino.cc/builder/types"
38
+
38
39
"github.com/stretchr/testify/require"
39
40
)
40
41
41
- func TestCTagsParserShouldListPrototypes (t * testing.T ) {
42
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output " , "TestCTagsParserShouldListPrototypes.txt" ))
43
- NoError (t , err )
42
+ func produceTags (t * testing.T , filename string ) [] * types. CTag {
43
+ bytes , err := ioutil .ReadFile (filepath .Join ("test_data " , filename ))
44
+ require . NoError (t , err )
44
45
45
- ctagsParser := ctags.CTagsParser {}
46
- tags := ctagsParser .Parse (string (bytes ))
46
+ parser := CTagsParser {}
47
+ return parser .Parse (string (bytes ))
48
+ }
49
+
50
+ func TestCTagsParserShouldListPrototypes (t * testing.T ) {
51
+ tags := produceTags (t , "TestCTagsParserShouldListPrototypes.txt" )
47
52
48
53
require .Equal (t , 8 , len (tags ))
49
54
idx := 0
@@ -81,11 +86,7 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) {
81
86
}
82
87
83
88
func TestCTagsParserShouldListTemplates (t * testing.T ) {
84
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserShouldListTemplates.txt" ))
85
- NoError (t , err )
86
-
87
- ctagsParser := ctags.CTagsParser {}
88
- tags := ctagsParser .Parse (string (bytes ))
89
+ tags := produceTags (t , "TestCTagsParserShouldListTemplates.txt" )
89
90
90
91
require .Equal (t , 3 , len (tags ))
91
92
idx := 0
@@ -103,11 +104,7 @@ func TestCTagsParserShouldListTemplates(t *testing.T) {
103
104
}
104
105
105
106
func TestCTagsParserShouldListTemplates2 (t * testing.T ) {
106
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserShouldListTemplates2.txt" ))
107
- NoError (t , err )
108
-
109
- ctagsParser := ctags.CTagsParser {}
110
- tags := ctagsParser .Parse (string (bytes ))
107
+ tags := produceTags (t , "TestCTagsParserShouldListTemplates2.txt" )
111
108
112
109
require .Equal (t , 4 , len (tags ))
113
110
idx := 0
@@ -127,11 +124,7 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) {
127
124
}
128
125
129
126
func TestCTagsParserShouldDealWithClasses (t * testing.T ) {
130
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserShouldDealWithClasses.txt" ))
131
- NoError (t , err )
132
-
133
- ctagsParser := ctags.CTagsParser {}
134
- tags := ctagsParser .Parse (string (bytes ))
127
+ tags := produceTags (t , "TestCTagsParserShouldDealWithClasses.txt" )
135
128
136
129
require .Equal (t , 2 , len (tags ))
137
130
idx := 0
@@ -143,11 +136,7 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) {
143
136
}
144
137
145
138
func TestCTagsParserShouldDealWithStructs (t * testing.T ) {
146
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserShouldDealWithStructs.txt" ))
147
- NoError (t , err )
148
-
149
- ctagsParser := ctags.CTagsParser {}
150
- tags := ctagsParser .Parse (string (bytes ))
139
+ tags := produceTags (t , "TestCTagsParserShouldDealWithStructs.txt" )
151
140
152
141
require .Equal (t , 5 , len (tags ))
153
142
idx := 0
@@ -169,11 +158,7 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) {
169
158
}
170
159
171
160
func TestCTagsParserShouldDealWithMacros (t * testing.T ) {
172
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserShouldDealWithMacros.txt" ))
173
- NoError (t , err )
174
-
175
- ctagsParser := ctags.CTagsParser {}
176
- tags := ctagsParser .Parse (string (bytes ))
161
+ tags := produceTags (t , "TestCTagsParserShouldDealWithMacros.txt" )
177
162
178
163
require .Equal (t , 8 , len (tags ))
179
164
idx := 0
@@ -203,11 +188,7 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) {
203
188
}
204
189
205
190
func TestCTagsParserShouldDealFunctionWithDifferentSignatures (t * testing.T ) {
206
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt" ))
207
- NoError (t , err )
208
-
209
- ctagsParser := ctags.CTagsParser {}
210
- tags := ctagsParser .Parse (string (bytes ))
191
+ tags := produceTags (t , "TestCTagsParserShouldDealFunctionWithDifferentSignatures.txt" )
211
192
212
193
require .Equal (t , 3 , len (tags ))
213
194
idx := 0
@@ -222,11 +203,7 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) {
222
203
}
223
204
224
205
func TestCTagsParserClassMembersAreFilteredOut (t * testing.T ) {
225
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserClassMembersAreFilteredOut.txt" ))
226
- NoError (t , err )
227
-
228
- ctagsParser := ctags.CTagsParser {}
229
- tags := ctagsParser .Parse (string (bytes ))
206
+ tags := produceTags (t , "TestCTagsParserClassMembersAreFilteredOut.txt" )
230
207
231
208
require .Equal (t , 5 , len (tags ))
232
209
idx := 0
@@ -250,11 +227,7 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) {
250
227
}
251
228
252
229
func TestCTagsParserStructWithFunctions (t * testing.T ) {
253
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserStructWithFunctions.txt" ))
254
- NoError (t , err )
255
-
256
- ctagsParser := ctags.CTagsParser {}
257
- tags := ctagsParser .Parse (string (bytes ))
230
+ tags := produceTags (t , "TestCTagsParserStructWithFunctions.txt" )
258
231
259
232
require .Equal (t , 8 , len (tags ))
260
233
idx := 0
@@ -286,11 +259,7 @@ func TestCTagsParserStructWithFunctions(t *testing.T) {
286
259
}
287
260
288
261
func TestCTagsParserDefaultArguments (t * testing.T ) {
289
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserDefaultArguments.txt" ))
290
- NoError (t , err )
291
-
292
- ctagsParser := ctags.CTagsParser {}
293
- tags := ctagsParser .Parse (string (bytes ))
262
+ tags := produceTags (t , "TestCTagsParserDefaultArguments.txt" )
294
263
295
264
require .Equal (t , 3 , len (tags ))
296
265
idx := 0
@@ -306,11 +275,7 @@ func TestCTagsParserDefaultArguments(t *testing.T) {
306
275
}
307
276
308
277
func TestCTagsParserNamespace (t * testing.T ) {
309
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserNamespace.txt" ))
310
- NoError (t , err )
311
-
312
- ctagsParser := ctags.CTagsParser {}
313
- tags := ctagsParser .Parse (string (bytes ))
278
+ tags := produceTags (t , "TestCTagsParserNamespace.txt" )
314
279
315
280
require .Equal (t , 3 , len (tags ))
316
281
idx := 0
@@ -326,11 +291,7 @@ func TestCTagsParserNamespace(t *testing.T) {
326
291
}
327
292
328
293
func TestCTagsParserStatic (t * testing.T ) {
329
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserStatic.txt" ))
330
- NoError (t , err )
331
-
332
- ctagsParser := ctags.CTagsParser {}
333
- tags := ctagsParser .Parse (string (bytes ))
294
+ tags := produceTags (t , "TestCTagsParserStatic.txt" )
334
295
335
296
require .Equal (t , 3 , len (tags ))
336
297
idx := 0
@@ -345,11 +306,7 @@ func TestCTagsParserStatic(t *testing.T) {
345
306
}
346
307
347
308
func TestCTagsParserFunctionPointer (t * testing.T ) {
348
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserFunctionPointer.txt" ))
349
- NoError (t , err )
350
-
351
- ctagsParser := ctags.CTagsParser {}
352
- tags := ctagsParser .Parse (string (bytes ))
309
+ tags := produceTags (t , "TestCTagsParserFunctionPointer.txt" )
353
310
354
311
require .Equal (t , 4 , len (tags ))
355
312
idx := 0
@@ -367,11 +324,7 @@ func TestCTagsParserFunctionPointer(t *testing.T) {
367
324
}
368
325
369
326
func TestCTagsParserFunctionPointers (t * testing.T ) {
370
- bytes , err := ioutil .ReadFile (filepath .Join ("ctags_output" , "TestCTagsParserFunctionPointers.txt" ))
371
- NoError (t , err )
372
-
373
- ctagsParser := ctags.CTagsParser {}
374
- tags := ctagsParser .Parse (string (bytes ))
327
+ tags := produceTags (t , "TestCTagsParserFunctionPointers.txt" )
375
328
376
329
require .Equal (t , 5 , len (tags ))
377
330
idx := 0
0 commit comments