Skip to content

Commit d3931d3

Browse files
committed
TestErrConst; TestErrNewVar
1 parent 02ce4a6 commit d3931d3

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

error_msg_test.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,31 @@ func newFunc(
117117
return fn
118118
}
119119

120+
func TestErrConst(t *testing.T) {
121+
codeErrorTest(t, "./foo.gop:2:7 a redeclared in this block\n\tprevious declaration at ./foo.gop:1:5",
122+
func(pkg *gox.Package) {
123+
pkg.NewVarStart(position(1, 5), nil, "a").Val(1).EndInit(1)
124+
pkg.NewConstStart(position(2, 7), nil, "a").Val(2).EndInit(1)
125+
})
126+
}
127+
128+
func TestErrNewVar(t *testing.T) {
129+
codeErrorTest(t, "./foo.gop:2:7 a redeclared in this block\n\tprevious declaration at ./foo.gop:1:5",
130+
func(pkg *gox.Package) {
131+
pkg.NewVarStart(position(1, 5), nil, "a").Val(1).EndInit(1)
132+
pkg.NewVarStart(position(2, 7), nil, "a").Val(2).EndInit(1)
133+
})
134+
codeErrorTest(t, "./foo.gop:2:6 foo redeclared in this block\n\tprevious declaration at ./foo.gop:1:5",
135+
func(pkg *gox.Package) {
136+
var x *types.Var
137+
pkg.Fset.AddFile("./foo.gop", 1, 100).AddLine(10)
138+
pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg).
139+
NewAutoVar(position(1, 5), "foo", &x).
140+
NewAutoVar(position(2, 6), "foo", &x).
141+
End()
142+
})
143+
}
144+
120145
func TestErrForRange(t *testing.T) {
121146
codeErrorTest(t, `./foo.gop:1:5 cannot assign type string to a (type int) in range`,
122147
func(pkg *gox.Package) {
@@ -283,18 +308,6 @@ func TestErrLabel(t *testing.T) {
283308
})
284309
}
285310

286-
func TestErrNewVar(t *testing.T) {
287-
codeErrorTest(t, "./foo.gop:2:6 foo redeclared in this block\n\tprevious declaration at ./foo.gop:1:5",
288-
func(pkg *gox.Package) {
289-
var x *types.Var
290-
pkg.Fset.AddFile("./foo.gop", 1, 100).AddLine(10)
291-
pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg).
292-
NewAutoVar(position(1, 5), "foo", &x).
293-
NewAutoVar(position(2, 6), "foo", &x).
294-
End()
295-
})
296-
}
297-
298311
func _TestErrDefineVar(t *testing.T) {
299312
codeErrorTest(t, "foo redeclared in this block\n\tprevious declaration at ./foo.gop:1",
300313
func(pkg *gox.Package) {

0 commit comments

Comments
 (0)