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:
parent
8049553ca8
commit
0ced849c61
|
@ -7,6 +7,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"golang.org/x/tools/go/types"
|
"golang.org/x/tools/go/types"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +20,10 @@ func init() {
|
||||||
funcDecl)
|
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
|
// checkExample walks the documentation example functions checking for common
|
||||||
// mistakes of misnamed functions, failure to map functions to existing
|
// mistakes of misnamed functions, failure to map functions to existing
|
||||||
|
|
|
@ -17,7 +17,7 @@ var DefaultBuf Buf
|
||||||
|
|
||||||
func Example() {} // OK because is package-level.
|
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"
|
func Example_BadSuffix() // ERROR "Example_BadSuffix has malformed example suffix: BadSuffix"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue