OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Extract example functions from package ASTs. | 5 // Extract example functions from package ASTs. |
6 | 6 |
7 package doc | 7 package doc |
8 | 8 |
9 import ( | 9 import ( |
10 "go/ast" | 10 "go/ast" |
11 "strings" | 11 "strings" |
12 "unicode" | 12 "unicode" |
13 » "utf8" | 13 » "unicode/utf8" |
14 ) | 14 ) |
15 | 15 |
16 type Example struct { | 16 type Example struct { |
17 Name string // name of the item being demonstrated | 17 Name string // name of the item being demonstrated |
18 Body *ast.BlockStmt // code | 18 Body *ast.BlockStmt // code |
19 Output string // expected output | 19 Output string // expected output |
20 } | 20 } |
21 | 21 |
22 func Examples(pkg *ast.Package) []*Example { | 22 func Examples(pkg *ast.Package) []*Example { |
23 var examples []*Example | 23 var examples []*Example |
(...skipping 23 matching lines...) Expand all Loading... |
47 func isTest(name, prefix string) bool { | 47 func isTest(name, prefix string) bool { |
48 if !strings.HasPrefix(name, prefix) { | 48 if !strings.HasPrefix(name, prefix) { |
49 return false | 49 return false |
50 } | 50 } |
51 if len(name) == len(prefix) { // "Test" is ok | 51 if len(name) == len(prefix) { // "Test" is ok |
52 return true | 52 return true |
53 } | 53 } |
54 rune, _ := utf8.DecodeRuneInString(name[len(prefix):]) | 54 rune, _ := utf8.DecodeRuneInString(name[len(prefix):]) |
55 return !unicode.IsLower(rune) | 55 return !unicode.IsLower(rune) |
56 } | 56 } |
OLD | NEW |