Skip to content

Commit 91a9a55

Browse files
committed
Moved ctags test into ctags package
Signed-off-by: Cristian Maglie <[email protected]>
1 parent f44e835 commit 91a9a55

17 files changed

+29
-77
lines changed

src/arduino.cc/builder/test/ctags_parser_test.go renamed to src/arduino.cc/builder/ctags/ctags_parser_test.go

+25-72
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,28 @@
2727
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
2828
*/
2929

30-
package test
30+
package ctags
3131

3232
import (
3333
"io/ioutil"
3434
"path/filepath"
3535
"testing"
3636

37-
"arduino.cc/builder/ctags"
37+
"arduino.cc/builder/types"
38+
3839
"github.com/stretchr/testify/require"
3940
)
4041

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)
4445

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")
4752

4853
require.Equal(t, 8, len(tags))
4954
idx := 0
@@ -81,11 +86,7 @@ func TestCTagsParserShouldListPrototypes(t *testing.T) {
8186
}
8287

8388
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")
8990

9091
require.Equal(t, 3, len(tags))
9192
idx := 0
@@ -103,11 +104,7 @@ func TestCTagsParserShouldListTemplates(t *testing.T) {
103104
}
104105

105106
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")
111108

112109
require.Equal(t, 4, len(tags))
113110
idx := 0
@@ -127,11 +124,7 @@ func TestCTagsParserShouldListTemplates2(t *testing.T) {
127124
}
128125

129126
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")
135128

136129
require.Equal(t, 2, len(tags))
137130
idx := 0
@@ -143,11 +136,7 @@ func TestCTagsParserShouldDealWithClasses(t *testing.T) {
143136
}
144137

145138
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")
151140

152141
require.Equal(t, 5, len(tags))
153142
idx := 0
@@ -169,11 +158,7 @@ func TestCTagsParserShouldDealWithStructs(t *testing.T) {
169158
}
170159

171160
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")
177162

178163
require.Equal(t, 8, len(tags))
179164
idx := 0
@@ -203,11 +188,7 @@ func TestCTagsParserShouldDealWithMacros(t *testing.T) {
203188
}
204189

205190
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")
211192

212193
require.Equal(t, 3, len(tags))
213194
idx := 0
@@ -222,11 +203,7 @@ func TestCTagsParserShouldDealFunctionWithDifferentSignatures(t *testing.T) {
222203
}
223204

224205
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")
230207

231208
require.Equal(t, 5, len(tags))
232209
idx := 0
@@ -250,11 +227,7 @@ func TestCTagsParserClassMembersAreFilteredOut(t *testing.T) {
250227
}
251228

252229
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")
258231

259232
require.Equal(t, 8, len(tags))
260233
idx := 0
@@ -286,11 +259,7 @@ func TestCTagsParserStructWithFunctions(t *testing.T) {
286259
}
287260

288261
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")
294263

295264
require.Equal(t, 3, len(tags))
296265
idx := 0
@@ -306,11 +275,7 @@ func TestCTagsParserDefaultArguments(t *testing.T) {
306275
}
307276

308277
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")
314279

315280
require.Equal(t, 3, len(tags))
316281
idx := 0
@@ -326,11 +291,7 @@ func TestCTagsParserNamespace(t *testing.T) {
326291
}
327292

328293
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")
334295

335296
require.Equal(t, 3, len(tags))
336297
idx := 0
@@ -345,11 +306,7 @@ func TestCTagsParserStatic(t *testing.T) {
345306
}
346307

347308
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")
353310

354311
require.Equal(t, 4, len(tags))
355312
idx := 0
@@ -367,11 +324,7 @@ func TestCTagsParserFunctionPointer(t *testing.T) {
367324
}
368325

369326
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")
375328

376329
require.Equal(t, 5, len(tags))
377330
idx := 0

src/arduino.cc/builder/test/ctags_to_prototypes_test.go renamed to src/arduino.cc/builder/ctags/ctags_to_prototypes_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,22 @@
2727
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
2828
*/
2929

30-
package test
30+
package ctags
3131

3232
import (
3333
"io/ioutil"
3434
"path/filepath"
3535
"testing"
3636

37-
"arduino.cc/builder/ctags"
3837
"arduino.cc/builder/types"
3938
"github.com/stretchr/testify/require"
4039
)
4140

4241
func producePrototypes(t *testing.T, filename string) ([]*types.Prototype, int) {
43-
bytes, err := ioutil.ReadFile(filepath.Join("ctags_output", filename))
44-
NoError(t, err)
42+
bytes, err := ioutil.ReadFile(filepath.Join("test_data", filename))
43+
require.NoError(t, err)
4544

46-
parser := &ctags.CTagsParser{}
45+
parser := &CTagsParser{}
4746
parser.Parse(string(bytes))
4847
return parser.GeneratePrototypes()
4948
}

0 commit comments

Comments
 (0)