// problem with types.
const (
+ // InvalidSyntaxTree occurs if an invalid syntax tree is provided
+ // to the type checker. It should never happen.
+ InvalidSyntaxTree Code = -1
+
+ // The zero Code value indicates an unset (invalid) error code.
_ Code = iota
// Test is reserved for errors that only apply while in self-test mode.
//
// Per the spec:
// "The PackageName must not be the blank identifier."
+ //
+ // Example:
+ // package _
BlankPkgName
// MismatchedPkgName occurs when a file's package name doesn't match the
doc := spec.Doc.Text()
examples := strings.Split(doc, "Example:")
for i := 1; i < len(examples); i++ {
- example := examples[i]
+ example := strings.TrimSpace(examples[i])
err := checkExample(t, example)
if err == nil {
t.Fatalf("no error in example #%d", i)
func checkExample(t *testing.T, example string) error {
t.Helper()
fset := token.NewFileSet()
- src := fmt.Sprintf("package p\n\n%s", example)
- file, err := parser.ParseFile(fset, "example.go", src, 0)
+ if !strings.HasPrefix(example, "package") {
+ example = "package p\n\n" + example
+ }
+ file, err := parser.ParseFile(fset, "example.go", example, 0)
if err != nil {
t.Fatal(err)
}