Home | History | Annotate | Download | only in testdata

Lines Matching defs:printf

5 // This file contains tests for the printf checker.
21 // For testing printf-like functions from external package.
27 fmt.Printf("%p, %x %X", up, up, up)
70 fmt.Printf("")
71 fmt.Printf("%b %b %b", 3, i, x)
72 fmt.Printf("%c %c %c %c", 3, i, 'x', r)
73 fmt.Printf("%d %d %d", 3, i, imap)
74 fmt.Printf("%e %e %e %e", 3e9, x, fslice, c)
75 fmt.Printf("%E %E %E %E", 3e9, x, fslice, c)
76 fmt.Printf("%f %f %f %f", 3e9, x, fslice, c)
77 fmt.Printf("%F %F %F %F", 3e9, x, fslice, c)
78 fmt.Printf("%g %g %g %g", 3e9, x, fslice, c)
79 fmt.Printf("%G %G %G %G", 3e9, x, fslice, c)
80 fmt.Printf("%b %b %b %b", 3e9, x, fslice, c)
81 fmt.Printf("%o %o", 3, i)
82 fmt.Printf("%p %p", p, nil)
83 fmt.Printf("%q %q %q %q", 3, i, 'x', r)
84 fmt.Printf("%s %s %s", "hi", s, []byte{65})
85 fmt.Printf("%t %t", true, b)
86 fmt.Printf("%T %T", 3, i)
87 fmt.Printf("%U %U", 3, i)
88 fmt.Printf("%v %v", 3, i)
89 fmt.Printf("%x %x %x %x", 3, i, "hi", s)
90 fmt.Printf("%X %X %X %X", 3, i, "hi", s)
91 fmt.Printf("%.*s %d %g", 3, "hi", 23, 2.3)
92 fmt.Printf("%s", &stringerv)
93 fmt.Printf("%v", &stringerv)
94 fmt.Printf("%T", &stringerv)
95 fmt.Printf("%s", &embeddedStringerv)
96 fmt.Printf("%v", &embeddedStringerv)
97 fmt.Printf("%T", &embeddedStringerv)
98 fmt.Printf("%v", notstringerv)
99 fmt.Printf("%T", notstringerv)
100 fmt.Printf("%q", stringerarrayv)
101 fmt.Printf("%v", stringerarrayv)
102 fmt.Printf("%s", stringerarrayv)
103 fmt.Printf("%v", notstringerarrayv)
104 fmt.Printf("%T", notstringerarrayv)
105 fmt.Printf("%d", new(Formatter))
106 fmt.Printf("%*%", 2) // Ridiculous but allowed.
107 fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say.
109 fmt.Printf("%g", 1+2i)
110 fmt.Printf("%#e %#E %#f %#F %#g %#G", 1.2, 1.2, 1.2, 1.2, 1.2, 1.2) // OK since Go 1.9
112 fmt.Printf("%b", "hi") // ERROR "Printf format %b has arg \x22hi\x22 of wrong type string"
113 fmt.Printf("%t", c) // ERROR "Printf format %t has arg c of wrong type complex64"
114 fmt.Printf("%t", 1+2i) // ERROR "Printf format %t has arg 1 \+ 2i of wrong type complex128"
115 fmt.Printf("%c", 2.3) // ERROR "Printf format %c has arg 2.3 of wrong type float64"
116 fmt.Printf("%d", 2.3) // ERROR "Printf format %d has arg 2.3 of wrong type float64"
117 fmt.Printf("%e", "hi") // ERROR "Printf format %e has arg \x22hi\x22 of wrong type string"
118 fmt.Printf("%E", true) // ERROR "Printf format %E has arg true of wrong type bool"
119 fmt.Printf("%f", "hi") // ERROR "Printf format %f has arg \x22hi\x22 of wrong type string"
120 fmt.Printf("%F", 'x') // ERROR "Printf format %F has arg 'x' of wrong type rune"
121 fmt.Printf("%g", "hi") // ERROR "Printf format %g has arg \x22hi\x22 of wrong type string"
122 fmt.Printf("%g", imap) // ERROR "Printf format %g has arg imap of wrong type map\[int\]int"
123 fmt.Printf("%G", i) // ERROR "Printf format %G has arg i of wrong type int"
124 fmt.Printf("%o", x) // ERROR "Printf format %o has arg x of wrong type float64"
125 fmt.Printf("%p", 23) // ERROR "Printf format %p has arg 23 of wrong type int"
126 fmt.Printf("%q", x) // ERROR "Printf format %q has arg x of wrong type float64"
127 fmt.Printf("%s", b) // ERROR "Printf format %s has arg b of wrong type bool"
128 fmt.Printf("%s", byte(65)) // ERROR "Printf format %s has arg byte\(65\) of wrong type byte"
129 fmt.Printf("%t", 23) // ERROR "Printf format %t has arg 23 of wrong type int"
130 fmt.Printf("%U", x) // ERROR "Printf format %U has arg x of wrong type float64"
131 fmt.Printf("%x", nil) // ERROR "Printf format %x has arg nil of wrong type untyped nil"
132 fmt.Printf("%X", 2.3) // ERROR "Printf format %X has arg 2.3 of wrong type float64"
133 fmt.Printf("%s", stringerv) // ERROR "Printf format %s has arg stringerv of wrong type testdata.ptrStringer"
134 fmt.Printf("%t", stringerv) // ERROR "Printf format %t has arg stringerv of wrong type testdata.ptrStringer"
135 fmt.Printf("%s", embeddedStringerv) // ERROR "Printf format %s has arg embeddedStringerv of wrong type testdata.embeddedStringer"
136 fmt.Printf("%t", embeddedStringerv) // ERROR "Printf format %t has arg embeddedStringerv of wrong type testdata.embeddedStringer"
137 fmt.Printf("%q", notstringerv) // ERROR "Printf format %q has arg notstringerv of wrong type testdata.notstringer"
138 fmt.Printf("%t", notstringerv) // ERROR "Printf format %t has arg notstringerv of wrong type testdata.notstringer"
139 fmt.Printf("%t", stringerarrayv) // ERROR "Printf format %t has arg stringerarrayv of wrong type testdata.stringerarray"
140 fmt.Printf("%t", notstringerarrayv) // ERROR "Printf format %t has arg notstringerarrayv of wrong type testdata.notstringerarray"
141 fmt.Printf("%q", notstringerarrayv) // ERROR "Printf format %q has arg notstringerarrayv of wrong type testdata.notstringerarray"
142 fmt.Printf("%d", BoolFormatter(true)) // ERROR "Printf format %d has arg BoolFormatter\(true\) of wrong type testdata.BoolFormatter"
143 fmt.Printf("%z", FormatterVal(true)) // correct (the type is responsible for formatting)
144 fmt.Printf("%d", FormatterVal(true)) // correct (the type is responsible for formatting)
145 fmt.Printf("%s", nonemptyinterface) // correct (the type is responsible for formatting)
146 fmt.Printf("%.*s %d %6g", 3, "hi", 23, 'x') // ERROR "Printf format %6g has arg 'x' of wrong type rune"
151 fmt.Printf("%s", "hi", 3) // ERROR "Printf call needs 1 arg but has 2 args"
153 fmt.Printf("%s%%%d", "hi", 3) // correct
154 fmt.Printf("%08s", "woo") // correct
155 fmt.Printf("% 8s", "woo") // correct
156 fmt.Printf("%.*d", 3, 3) // correct
157 fmt.Printf("%.*d x", 3, 3, 3, 3) // ERROR "Printf call needs 2 args but has 4 args"
158 fmt.Printf("%.*d x", "hi", 3) // ERROR "Printf format %.*d uses non-int \x22hi\x22 as argument of \*"
159 fmt.Printf("%.*d x", i, 3) // correct
160 fmt.Printf("%.*d x", s, 3) // ERROR "Printf format %.\*d uses non-int s as argument of \*"
161 fmt.Printf("%*% x", 0.22) // ERROR "Printf format %\*% uses non-int 0.22 as argument of \*"
162 fmt.Printf("%q %q", multi()...) // ok
163 fmt.Printf("%#q", `blah`) // ok
164 // printf("now is the time", "buddy") // no error "printf call has arguments but no formatting directives"
165 Printf("now is the time", "buddy") // ERROR "Printf call has arguments but no formatting directives"
166 Printf("hi") // ok
168 Printf(format, "hi", "there")
169 Printf(format, "hi") // ERROR "Printf format %s reads arg #2, but call has only 1 arg$"
170 Printf("%s %d %.3v %q", "str", 4) // ERROR "Printf format %.3v reads arg #3, but call has only 2 args"
176 fmt.Printf("%#s", FormatterVal(true)) // correct (the type is responsible for formatting)
177 Printf("d%", 2) // ERROR "Printf format % is missing verb at end of string"
178 Printf("%d", percentDV)
179 Printf("%d", &percentDV)
180 Printf("%d", notPercentDV) // ERROR "Printf format %d has arg notPercentDV of wrong type testdata.notPercentDStruct"
181 Printf("%d", &notPercentDV) // ERROR "Printf format %d has arg &notPercentDV of wrong type \*testdata.notPercentDStruct"
182 Printf("%p", &notPercentDV) // Works regardless: we print it as a pointer.
183 Printf("%s", percentSV)
184 Printf("%s", &percentSV)
186 Printf("%[1]d", 3)
187 Printf("%[1]*d", 3, 1)
188 Printf("%[2]*[1]d", 1, 3)
189 Printf("%[2]*.[1]*[3]d", 2, 3, 4)
192 Printf("%[xd", 3) // ERROR "Printf format %\[xd is missing closing \]"
193 Printf("%[x]d x", 3) // ERROR "Printf format has invalid argument index \[x\]"
194 Printf("%[3]*s x", "hi", 2) // ERROR "Printf format has invalid argument index \[3\]"
196 Printf("%[2]*.[1]*[3]d x", 2, "hi", 4) // ERROR "Printf format %\[2]\*\.\[1\]\*\[3\]d uses non-int \x22hi\x22 as argument of \*"
197 Printf("%[0]s x", "arg1") // ERROR "Printf format has invalid argument index \[0\]"
198 Printf("%[0]d x", 1) // ERROR "Printf format has invalid argument index \[0\]"
218 fmt.Printf("%f", iface) // ok: fmt treats interfaces as transparent and iface may well have a float concrete type
220 Printf("%d", someFunction) // ERROR "Printf format %d arg someFunction is a func value, not called"
221 Printf("%v", someFunction) // ERROR "Printf format %v arg someFunction is a func value, not called"
223 Printf("%p", someFunction) // ok: maybe someone wants to see the pointer
224 Printf("%T", someFunction) // ok: maybe someone wants to see the type
226 Printf("%p %x", recursiveStructV, recursiveStructV.next)
227 Printf("%p %x", recursiveStruct1V, recursiveStruct1V.next)
228 Printf("%p %x", recursiveSliceV, recursiveSliceV)
229 Printf("%p %x", recursiveMapV, recursiveMapV)
245 // Printf from external package
246 // externalprintf.Printf("%d", 42) // OK
247 // externalprintf.Printf("foobar") // OK
268 Printf("%d %[3]d %d %[2]d x", 1, 2, 3, 4) // OK
269 Printf("%d %[0]d %d %[2]d x", 1, 2, 3, 4) // ERROR "Printf format has invalid argument index \[0\]"
270 Printf("%d %[3]d %d %[-2]d x", 1, 2, 3, 4) // ERROR "Printf format has invalid argument index \[-2\]"
271 Printf("%d %[3]d %d %[2234234234234]d x", 1, 2, 3, 4) // ERROR "Printf format has invalid argument index \[2234234234234\]"
272 Printf("%d %[3]d %-10d %[2]d x", 1, 2, 3) // ERROR "Printf format %-10d reads arg #4, but call has only 3 args"
273 Printf("%[1][3]d x", 1, 2) // ERROR "Printf format %\[1\]\[ has unknown verb \["
274 Printf("%[1]d x", 1, 2) // OK
275 Printf("%d %[3]d %d %[2]d x", 1, 2, 3, 4, 5) // OK
278 Printf("%p\n", os.Stdout) // OK
281 Printf(someString(), "hello") // OK
311 // Printf is used by the test so we must declare it.
312 func Printf(format string, args ...interface{}) {
332 // printf is used by the test so we must declare it.
333 func printf(format string, args ...interface{}) {
529 fmt.Printf("%s", unexportedInterface{"foo"}) // ok; prints {foo}
530 fmt.Printf("%s", unexportedInterface{3}) // ok; we can't see the problem
533 fmt.Printf("%s", us) // ERROR "Printf format %s has arg us of wrong type testdata.unexportedStringer"
534 fmt.Printf("%s", &us) // ERROR "Printf format %s has arg &us of wrong type [*]testdata.unexportedStringer"
540 fmt.Printf("%s", usf) // ERROR "Printf format %s has arg usf of wrong type testdata.unexportedStringerOtherFields"
541 fmt.Printf("%s", &usf) // ERROR "Printf format %s has arg &usf of wrong type [*]testdata.unexportedStringerOtherFields"
546 fmt.Printf("%s", ue) // ERROR "Printf format %s has arg ue of wrong type testdata.unexportedError"
547 fmt.Printf("%s", &ue) // ERROR "Printf format %s has arg &ue of wrong type [*]testdata.unexportedError"
554 fmt.Printf("%s", uef) // ERROR "Printf format %s has arg uef of wrong type testdata.unexportedErrorOtherFields"
555 fmt.Printf("%s", &uef) // ERROR "Printf format %s has arg &uef of wrong type [*]testdata.unexportedErrorOtherFields"
560 fmt.Printf("%s", uce) // ERROR "Printf format %s has arg uce of wrong type testdata.unexportedCustomError"
563 fmt.Printf("%s", uei) // ERROR "Printf format %s has arg uei of wrong type testdata.unexportedErrorInterface"
571 fmt.Printf("%s", intSlice) // ERROR "Printf format %s has arg intSlice of wrong type \[\]int"
573 fmt.Printf("%s", nonStringerArray) // ERROR "Printf format %s has arg nonStringerArray of wrong type \[1\]testdata.unexportedStringer"
574 fmt.Printf("%s", []stringer{3, 4}) // not an error
575 fmt.Printf("%s", [2]stringer{3, 4}) // not an error
581 fmt.Printf("%0t", true)