1 // Copyright 2020 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.
12 func TestFormatOperandKind(t *testing.T) {
22 {"%[?%s", 2, kindAny},
23 {"%[abc]v", 1, kindAny},
33 {"%e", 1, kindFloat | kindComplex},
34 {"%E", 1, kindFloat | kindComplex},
35 {"%f", 1, kindFloat | kindComplex},
36 {"%F", 1, kindFloat | kindComplex},
37 {"%g", 1, kindFloat | kindComplex},
38 {"%G", 1, kindFloat | kindComplex},
39 {"%b", 1, kindInt | kindFloat | kindComplex | kindBytes},
40 {"%q", 1, kindString | kindBytes | kindStringer | kindError},
41 {"%s", 1, kindString | kindBytes | kindStringer | kindError},
42 {"%x", 1, kindString | kindBytes | kindInt | kindFloat | kindComplex},
43 {"%X", 1, kindString | kindBytes | kindInt | kindFloat | kindComplex},
44 {"%p", 1, kindPtr | kindSlice},
47 {"%1.2f", 1, kindFloat | kindComplex},
49 {"%*f", 2, kindFloat | kindComplex},
50 {"%*.*f", 1, kindInt},
51 {"%*.*f", 2, kindInt},
52 {"%*.*f", 3, kindFloat | kindComplex},
53 {"%[3]*.[2]*[1]f", 1, kindFloat | kindComplex},
54 {"%[3]*.[2]*[1]f", 2, kindInt},
55 {"%[3]*.[2]*[1]f", 3, kindInt},
57 {"foo %% %d", 1, kindInt},
58 {"%#-12.34f", 1, kindFloat | kindComplex},
61 {"%s %[1]X %d", 1, kindString | kindBytes},
62 {"%s %[1]X %d", 2, kindInt},
65 for _, c := range cases {
66 t.Run(fmt.Sprintf("%q#%d", c.f, c.idx), func(t *testing.T) {
67 if got := formatOperandKind(c.f, c.idx); got != c.kind {
68 t.Errorf("expected %d (%[1]b), got %d (%[2]b)", c.kind, got)