| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package testfuncs |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"strconv" |
| 10 |
"strings" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
func (b *indexBuilder) uniqueName(parent, subname string) string { |
| 20 |
base := parent + "/" + subname |
| 21 |
|
| 22 |
for { |
| 23 |
n := b.subNames[base] |
| 24 |
if n < 0 { |
| 25 |
panic("subtest count overflow") |
| 26 |
} |
| 27 |
b.subNames[base] = n + 1 |
| 28 |
|
| 29 |
if n == 0 && subname != "" { |
| 30 |
prefix, nn := parseSubtestNumber(base) |
| 31 |
if len(prefix) < len(base) && nn < b.subNames[prefix] { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
continue |
| 36 |
} |
| 37 |
return base |
| 38 |
} |
| 39 |
|
| 40 |
name := fmt.Sprintf("%s#%02d", base, n) |
| 41 |
if b.subNames[name] != 0 { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
continue |
| 46 |
} |
| 47 |
|
| 48 |
return name |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
func parseSubtestNumber(s string) (prefix string, nn int) { |
| 55 |
i := strings.LastIndex(s, "#") |
| 56 |
if i < 0 { |
| 57 |
return s, 0 |
| 58 |
} |
| 59 |
|
| 60 |
prefix, suffix := s[:i], s[i+1:] |
| 61 |
if len(suffix) < 2 || (len(suffix) > 2 && suffix[0] == '0') { |
| 62 |
|
| 63 |
|
| 64 |
return s, 0 |
| 65 |
} |
| 66 |
if suffix == "00" { |
| 67 |
if !strings.HasSuffix(prefix, "/") { |
| 68 |
|
| 69 |
y. |
| 70 |
return s, 0 |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
n, err := strconv.ParseInt(suffix, 10, 32) |
| 75 |
if err != nil || n < 0 { |
| 76 |
return s, 0 |
| 77 |
} |
| 78 |
return prefix, int(n) |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
func rewrite(s string) string { |
| 84 |
b := []byte{} |
| 85 |
for _, r := range s { |
| 86 |
switch { |
| 87 |
case isSpace(r): |
| 88 |
b = append(b, '_') |
| 89 |
case !strconv.IsPrint(r): |
| 90 |
s := strconv.QuoteRune(r) |
| 91 |
b = append(b, s[1:len(s)-1]...) |
| 92 |
default: |
| 93 |
b = append(b, string(r)...) |
| 94 |
} |
| 95 |
} |
| 96 |
return string(b) |
| 97 |
} |
| 98 |
|
| 99 |
func isSpace(r rune) bool { |
| 100 |
if r < 0x2000 { |
| 101 |
switch r { |
| 102 |
|
| 103 |
case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0, 0x1680: |
| 104 |
return true |
| 105 |
} |
| 106 |
} else { |
| 107 |
if r <= 0x200a { |
| 108 |
return true |
| 109 |
} |
| 110 |
switch r { |
| 111 |
case 0x2028, 0x2029, 0x202f, 0x205f, 0x3000: |
| 112 |
return true |
| 113 |
} |
| 114 |
} |
| 115 |
return false |
| 116 |
} |