Skip to content

Commit 60c65ed

Browse files
committed
cl: TestToTypeError
1 parent 3e58499 commit 60c65ed

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cl/error_msg_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"runtime"
2424
"testing"
2525

26+
"github.com/goplus/gop/ast"
2627
"github.com/goplus/gop/cl"
2728
"github.com/goplus/gop/parser"
2829
"github.com/goplus/gop/parser/fsx/memfs"
@@ -53,6 +54,24 @@ func codeErrorTestEx(t *testing.T, pkgname, filename, msg, src string) {
5354
}
5455
}
5556

57+
func codeErrorTestAst(t *testing.T, pkgname, filename, msg, src string) {
58+
f, _ := parser.ParseFile(gblFset, filename, src, parser.AllErrors)
59+
pkg := &ast.Package{
60+
Name: pkgname,
61+
Files: map[string]*ast.File{filename: f},
62+
}
63+
conf := *gblConf
64+
conf.NoFileLine = false
65+
conf.RelativeBase = "/foo"
66+
_, err := cl.NewPackage("", pkg, &conf)
67+
if err == nil {
68+
t.Fatal("no error?")
69+
}
70+
if ret := err.Error(); ret != msg {
71+
t.Fatalf("\nError: \"%s\"\nExpected: \"%s\"\n", ret, msg)
72+
}
73+
}
74+
5675
func TestErrLambdaExpr(t *testing.T) {
5776
codeErrorTest(t,
5877
"bar.gop:7:6: too few arguments in lambda expression\n\thave ()\n\twant (int, int)", `
@@ -969,3 +988,10 @@ func TestErrCompileFunc(t *testing.T) {
969988
printf("%+v\n", int32)
970989
`)
971990
}
991+
992+
func TestToTypeError(t *testing.T) {
993+
codeErrorTestAst(t, "main", "bar.gop", `bar.gop:3:3: toType unexpected: *ast.BadExpr`, `
994+
type
995+
a := 1
996+
`)
997+
}

0 commit comments

Comments
 (0)