"strings"
"text/template"
"time"
+ "unicode"
+ "unicode/utf8"
)
// ----------------------------------------------------------------------------
return buf.String()
}
+func startsWithUppercase(s string) bool {
+ r, _ := utf8.DecodeRuneInString(s)
+ return unicode.IsUpper(r)
+}
+
func example_htmlFunc(funcName string, examples []*doc.Example, fset *token.FileSet) string {
var buf bytes.Buffer
for _, eg := range examples {
- // accept Foo or Foo_.* for funcName == Foo
name := eg.Name
- if i := strings.Index(name, "_"); i >= 0 {
- name = name[:i]
+
+ // strip lowercase braz in Foo_braz or Foo_Bar_braz from name
+ // while keeping uppercase Braz in Foo_Braz
+ if i := strings.LastIndex(name, "_"); i != -1 {
+ if i < len(name)-1 && !startsWithUppercase(name[i+1:]) {
+ name = name[:i]
+ }
}
+
if name != funcName {
continue
}
fmt.Println("The output of this example function.")
}
-Multiple example functions may be provided for a given name XXX if they are
-discriminated by a distinct suffix starting with "_", such as ExampleXXX_2.
+The following naming conventions are used to declare examples for a function F,
+a type T and method M on type T:
+ func ExampleF() { ... } and func ExampleF_suffix() { ... }
+ func ExampleT() { ... } and func ExampleT_suffix() { ... }
+ func ExampleT_M() { ... } and func ExampleT_M_suffix() { ... }
+
+Multiple example functions may be provided by appending a distinct suffix
+to the name. The suffix must start with a lowercase letter.
+
Example functions without doc comments are compiled but not executed.
See the documentation of the testing package for more information.