{"%3.[2]d", SE{7}, "%!d(BADINDEX)"},
{"%.[2]d", SE{7}, "%!d(BADINDEX)"},
{"%d %d %d %#[1]o %#o %#o %#o", SE{11, 12, 13}, "11 12 13 013 014 015 %!o(MISSING)"},
+ {"%[5]d %[2]d %d", SE{1, 2, 3}, "%!d(BADINDEX) 2 3"},
+ {"%d %[3]d %d", SE{1, 2}, "1 %!d(BADINDEX) 2"}, // Erroneous index does not affect sequence.
}
func TestReorder(t *testing.T) {
value reflect.Value
// reordered records whether the format string used argument reordering.
reordered bool
- // goodArgNum records whether all reordering directives were valid.
+ // goodArgNum records whether the most recent reordering directive was valid.
goodArgNum bool
runeBuf [utf8.UTFMax]byte
fmt fmt
// up to the closing paren, if present, and whether the number parsed
// ok. The bytes to consume will be 1 if no closing paren is present.
func parseArgNumber(format string) (index int, wid int, ok bool) {
- // Find closing parenthesis
+ // Find closing bracket.
for i := 1; i < len(format); i++ {
if format[i] == ']' {
width, ok, newi := parsenum(format, 1, i)
argNum := 0 // we process one argument per non-trivial format
afterIndex := false // previous item in format was an index like [3].
p.reordered = false
- p.goodArgNum = true
for i := 0; i < end; {
+ p.goodArgNum = true
lasti := i
for i < end && format[i] != '%' {
i++