1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 func TestParsePrintfVerb(t *testing.T) {
10 for _, test := range []struct {
20 {"%3.*[4]d", 8, false},
22 gotSize, gotW := parsePrintfVerb(test.in)
23 if gotSize != test.wantSize || gotW != test.wantW {
24 t.Errorf("parsePrintfVerb(%q) = (%d, %t), want (%d, %t)",
25 test.in, gotSize, gotW, test.wantSize, test.wantW)
30 func TestParsePercentW(t *testing.T) {
31 for _, test := range []struct {
39 {"%w", 0, "%v", true},
40 {"%w%w", 0, "%v%v", false},
41 {"%3.2s %+q %% %w %#v", 2, "%3.2s %+q %% %v %#v", true},
42 {"%3.2s %w %% %w %#v", 1, "%3.2s %v %% %v %#v", false},
44 gotIdx, gotFormat, gotOK := parsePercentW(test.in)
45 if gotIdx != test.wantIdx || gotFormat != test.wantFormat || gotOK != test.wantOK {
46 t.Errorf("parsePercentW(%q) = (%d, %q, %t), want (%d, %q, %t)",
47 test.in, gotIdx, gotFormat, gotOK, test.wantIdx, test.wantFormat, test.wantOK)