{"%-+1.2a", "[%+-1.2a]"},
{"%-+1.2abc", "[%+-1.2a]bc"},
{"%-1.2abc", "[%-1.2a]bc"},
+ {"%-0abc", "[%-0a]bc"},
}
func TestFlagParser(t *testing.T) {
{"%-+1.2a", flagPrinter{}, "[%+-1.2a]"},
{"%-+1.2abc", flagPrinter{}, "[%+-1.2a]bc"},
{"%-1.2abc", flagPrinter{}, "[%-1.2a]bc"},
+ {"%-0abc", flagPrinter{}, "[%-0a]bc"},
// composite values with the 'a' verb
{"%a", [1]flagPrinter{}, "[[%a]]"},
{"%-+1.2a", [1]flagPrinter{}, "[[%+-1.2a]]"},
{"%-+1.2abc", [1]flagPrinter{}, "[[%+-1.2a]]bc"},
{"%-1.2abc", [1]flagPrinter{}, "[[%-1.2a]]bc"},
+ {"%-0abc", [1]flagPrinter{}, "[[%-0a]]bc"},
// simple values with the 'v' verb
{"%v", flagPrinter{}, "[%v]"},
{"%-+1.2v", flagPrinter{}, "[%+-1.2v]"},
{"%-+1.2vbc", flagPrinter{}, "[%+-1.2v]bc"},
{"%-1.2vbc", flagPrinter{}, "[%-1.2v]bc"},
+ {"%-0vbc", flagPrinter{}, "[%-0v]bc"},
// composite values with the 'v' verb.
{"%v", [1]flagPrinter{}, "[[%v]]"},
{"%-+1.2v", [1]flagPrinter{}, "[[%+-1.2v]]"},
{"%-+1.2vbc", [1]flagPrinter{}, "[[%+-1.2v]]bc"},
{"%-1.2vbc", [1]flagPrinter{}, "[[%-1.2v]]bc"},
+ {"%-0vbc", [1]flagPrinter{}, "[[%-0v]]bc"},
}
func TestFormatterFlags(t *testing.T) {
}
// Decide which byte the padding should be filled with.
padByte := byte(' ')
- if f.zero {
+ // Zero padding is allowed only to the left.
+ if f.zero && !f.minus {
padByte = byte('0')
}
// Fill padding with padByte.
f.zero = oldZero
return
}
- } else if f.zero && f.widPresent {
+ } else if f.zero && !f.minus && f.widPresent { // Zero padding is allowed only to the left.
prec = f.wid
if negative || f.plus || f.space {
prec-- // leave room for sign
if f.plus || num[0] != '+' {
// If we're zero padding to the left we want the sign before the leading zeros.
// Achieve this by writing the sign out and then padding the unsigned number.
- if f.zero && f.widPresent && f.wid > len(num) {
+ // Zero padding is allowed only to the left.
+ if f.zero && !f.minus && f.widPresent && f.wid > len(num) {
f.buf.writeByte(num[0])
f.writePadding(f.wid - len(num))
f.buf.write(num[1:])