1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:54:40 -07:00

tools/cmd/vet: check only first rune of example suffix

The documentation for the testing package states only that "The suffix
must start with a lower-case letter."

Fixes golang/go#12663

Change-Id: I9b079b105a7c9680325fed442c42adcf3b75055e
Reviewed-on: https://go-review.googlesource.com/14760
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Ford Hurley 2015-09-18 10:43:42 -04:00 committed by Andrew Gerrand
parent 8049553ca8
commit 0ced849c61
2 changed files with 7 additions and 2 deletions

View File

@ -7,6 +7,8 @@ package main
import (
"go/ast"
"strings"
"unicode"
"unicode/utf8"
"golang.org/x/tools/go/types"
)
@ -18,7 +20,10 @@ func init() {
funcDecl)
}
func isExampleSuffix(s string) bool { return strings.ToLower(s) == s }
func isExampleSuffix(s string) bool {
r, size := utf8.DecodeRuneInString(s)
return size > 0 && unicode.IsLower(r)
}
// checkExample walks the documentation example functions checking for common
// mistakes of misnamed functions, failure to map functions to existing

View File

@ -17,7 +17,7 @@ var DefaultBuf Buf
func Example() {} // OK because is package-level.
func Example_suffix() // OK because refers to suffix annotation.
func Example_goodSuffix() // OK because refers to suffix annotation.
func Example_BadSuffix() // ERROR "Example_BadSuffix has malformed example suffix: BadSuffix"