From 0ced849c613cfbccb9bfdf4bd88d2551b7bf8f81 Mon Sep 17 00:00:00 2001 From: Ford Hurley Date: Fri, 18 Sep 2015 10:43:42 -0400 Subject: [PATCH] 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 --- cmd/vet/example.go | 7 ++++++- cmd/vet/testdata/examples_test.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/vet/example.go b/cmd/vet/example.go index 29994f1b..585d3884 100644 --- a/cmd/vet/example.go +++ b/cmd/vet/example.go @@ -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 diff --git a/cmd/vet/testdata/examples_test.go b/cmd/vet/testdata/examples_test.go index ca1dab72..9c53672a 100644 --- a/cmd/vet/testdata/examples_test.go +++ b/cmd/vet/testdata/examples_test.go @@ -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"