@@ -23,6 +23,7 @@ import (
23
23
"runtime"
24
24
"testing"
25
25
26
+ "github.com/goplus/gop/ast"
26
27
"github.com/goplus/gop/cl"
27
28
"github.com/goplus/gop/parser"
28
29
"github.com/goplus/gop/parser/fsx/memfs"
@@ -53,6 +54,24 @@ func codeErrorTestEx(t *testing.T, pkgname, filename, msg, src string) {
53
54
}
54
55
}
55
56
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
+
56
75
func TestErrLambdaExpr(t *testing.T) {
57
76
codeErrorTest(t,
58
77
"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) {
969
988
printf("%+v\n", int32)
970
989
`)
971
990
}
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