Skip to content

Commit 24a2f44

Browse files
committed
Add test for go1.4's variable-free range
1 parent 1c39d8a commit 24a2f44

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

parser_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package main
22

33
import (
44
"path/filepath"
5+
"runtime"
56
"strconv"
67
"testing"
78
)
89

910
type F map[TagField]string
1011

1112
var testCases = []struct {
12-
filename string
13-
relative bool
14-
basepath string
15-
tags []Tag
13+
filename string
14+
relative bool
15+
basepath string
16+
minversion string
17+
tags []Tag
1618
}{
1719
{filename: "tests/const.go-src", tags: []Tag{
1820
tag("Test", 1, "p", F{}),
@@ -88,10 +90,20 @@ var testCases = []struct {
8890
{filename: "tests/simple.go-src", relative: true, basepath: "dir", tags: []Tag{
8991
Tag{Name: "main", File: "../tests/simple.go-src", Address: "1", Type: "p", Fields: F{"line": "1"}},
9092
}},
93+
{filename: "tests/range.go-src", minversion: "go1.4", tags: []Tag{
94+
tag("main", 1, "p", F{}),
95+
tag("fmt", 3, "i", F{}),
96+
tag("main", 5, "f", F{"access": "private", "signature": "()"}),
97+
}},
9198
}
9299

93100
func TestParse(t *testing.T) {
94101
for _, testCase := range testCases {
102+
if testCase.minversion != "" && runtime.Version() < testCase.minversion {
103+
t.Skipf("[%s] skipping test. Version is %s, but test requires %s", testCase.filename, runtime.Version(), testCase.minversion)
104+
continue
105+
}
106+
95107
basepath, err := filepath.Abs(testCase.basepath)
96108
if err != nil {
97109
t.Errorf("[%s] could not determine base path: %s\n", testCase.filename, err)

tests/range.go-src

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
for range [3]int{} {
7+
fmt.Println("testing")
8+
}
9+
}

0 commit comments

Comments
 (0)