Best Gauge code snippet using formatter.Test
format_test.go
Source:format_test.go
...13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.15 */16/*17Test Summary:18NOTE: For each test, a nil pointer, a single pointer and double pointer to the19base test element are also tested to ensure proper indirection across all types.20- Max int8, int16, int32, int64, int21- Max uint8, uint16, uint32, uint64, uint22- Boolean true and false23- Standard complex64 and complex12824- Array containing standard ints25- Array containing type with custom formatter on pointer receiver only26- Array containing interfaces27- Slice containing standard float32 values28- Slice containing type with custom formatter on pointer receiver only29- Slice containing interfaces30- Nil slice31- Standard string32- Nil interface33- Sub-interface34- Map with string keys and int vals35- Map with custom formatter type on pointer receiver only keys and vals36- Map with interface keys and values37- Map with nil interface value38- Struct with primitives39- Struct that contains another struct40- Struct that contains custom type with Stringer pointer interface via both41 exported and unexported fields42- Struct that contains embedded struct and field to same struct43- Uintptr to 0 (null pointer)44- Uintptr address of real variable45- Unsafe.Pointer to 0 (null pointer)46- Unsafe.Pointer to address of real variable47- Nil channel48- Standard int channel49- Function with no params and no returns50- Function with param and no returns51- Function with multiple params and multiple returns52- Struct that is circular through self referencing53- Structs that are circular through cross referencing54- Structs that are indirectly circular55- Type that panics in its Stringer interface56- Type that has a custom Error interface57- %x passthrough with uint58- %#x passthrough with uint59- %f passthrough with precision60- %f passthrough with width and precision61- %d passthrough with width62- %q passthrough with string63*/64package spew_test65import (66 "bytes"67 "fmt"68 "testing"69 "unsafe"70 "github.com/davecgh/go-spew/spew"71)72// formatterTest is used to describe a test to be performed against NewFormatter.73type formatterTest struct {74 format string75 in interface{}76 wants []string77}78// formatterTests houses all of the tests to be performed against NewFormatter.79var formatterTests = make([]formatterTest, 0)80// addFormatterTest is a helper method to append the passed input and desired81// result to formatterTests.82func addFormatterTest(format string, in interface{}, wants ...string) {83 test := formatterTest{format, in, wants}84 formatterTests = append(formatterTests, test)85}86func addIntFormatterTests() {87 // Max int8.88 v := int8(127)89 nv := (*int8)(nil)90 pv := &v91 vAddr := fmt.Sprintf("%p", pv)92 pvAddr := fmt.Sprintf("%p", &pv)93 vt := "int8"94 vs := "127"95 addFormatterTest("%v", v, vs)96 addFormatterTest("%v", pv, "<*>"+vs)97 addFormatterTest("%v", &pv, "<**>"+vs)98 addFormatterTest("%v", nv, "<nil>")99 addFormatterTest("%+v", v, vs)100 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)101 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)102 addFormatterTest("%+v", nv, "<nil>")103 addFormatterTest("%#v", v, "("+vt+")"+vs)104 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)105 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)106 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")107 addFormatterTest("%#+v", v, "("+vt+")"+vs)108 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)109 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)110 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")111 // Max int16.112 v2 := int16(32767)113 nv2 := (*int16)(nil)114 pv2 := &v2115 v2Addr := fmt.Sprintf("%p", pv2)116 pv2Addr := fmt.Sprintf("%p", &pv2)117 v2t := "int16"118 v2s := "32767"119 addFormatterTest("%v", v2, v2s)120 addFormatterTest("%v", pv2, "<*>"+v2s)121 addFormatterTest("%v", &pv2, "<**>"+v2s)122 addFormatterTest("%v", nv2, "<nil>")123 addFormatterTest("%+v", v2, v2s)124 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)125 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)126 addFormatterTest("%+v", nv2, "<nil>")127 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)128 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)129 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)130 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")131 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)132 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)133 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)134 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")135 // Max int32.136 v3 := int32(2147483647)137 nv3 := (*int32)(nil)138 pv3 := &v3139 v3Addr := fmt.Sprintf("%p", pv3)140 pv3Addr := fmt.Sprintf("%p", &pv3)141 v3t := "int32"142 v3s := "2147483647"143 addFormatterTest("%v", v3, v3s)144 addFormatterTest("%v", pv3, "<*>"+v3s)145 addFormatterTest("%v", &pv3, "<**>"+v3s)146 addFormatterTest("%v", nv3, "<nil>")147 addFormatterTest("%+v", v3, v3s)148 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s)149 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s)150 addFormatterTest("%+v", nv3, "<nil>")151 addFormatterTest("%#v", v3, "("+v3t+")"+v3s)152 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s)153 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s)154 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")155 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s)156 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s)157 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s)158 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")159 // Max int64.160 v4 := int64(9223372036854775807)161 nv4 := (*int64)(nil)162 pv4 := &v4163 v4Addr := fmt.Sprintf("%p", pv4)164 pv4Addr := fmt.Sprintf("%p", &pv4)165 v4t := "int64"166 v4s := "9223372036854775807"167 addFormatterTest("%v", v4, v4s)168 addFormatterTest("%v", pv4, "<*>"+v4s)169 addFormatterTest("%v", &pv4, "<**>"+v4s)170 addFormatterTest("%v", nv4, "<nil>")171 addFormatterTest("%+v", v4, v4s)172 addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s)173 addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s)174 addFormatterTest("%+v", nv4, "<nil>")175 addFormatterTest("%#v", v4, "("+v4t+")"+v4s)176 addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s)177 addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s)178 addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")179 addFormatterTest("%#+v", v4, "("+v4t+")"+v4s)180 addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s)181 addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s)182 addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")183 // Max int.184 v5 := int(2147483647)185 nv5 := (*int)(nil)186 pv5 := &v5187 v5Addr := fmt.Sprintf("%p", pv5)188 pv5Addr := fmt.Sprintf("%p", &pv5)189 v5t := "int"190 v5s := "2147483647"191 addFormatterTest("%v", v5, v5s)192 addFormatterTest("%v", pv5, "<*>"+v5s)193 addFormatterTest("%v", &pv5, "<**>"+v5s)194 addFormatterTest("%v", nv5, "<nil>")195 addFormatterTest("%+v", v5, v5s)196 addFormatterTest("%+v", pv5, "<*>("+v5Addr+")"+v5s)197 addFormatterTest("%+v", &pv5, "<**>("+pv5Addr+"->"+v5Addr+")"+v5s)198 addFormatterTest("%+v", nv5, "<nil>")199 addFormatterTest("%#v", v5, "("+v5t+")"+v5s)200 addFormatterTest("%#v", pv5, "(*"+v5t+")"+v5s)201 addFormatterTest("%#v", &pv5, "(**"+v5t+")"+v5s)202 addFormatterTest("%#v", nv5, "(*"+v5t+")"+"<nil>")203 addFormatterTest("%#+v", v5, "("+v5t+")"+v5s)204 addFormatterTest("%#+v", pv5, "(*"+v5t+")("+v5Addr+")"+v5s)205 addFormatterTest("%#+v", &pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")"+v5s)206 addFormatterTest("%#+v", nv5, "(*"+v5t+")"+"<nil>")207}208func addUintFormatterTests() {209 // Max uint8.210 v := uint8(255)211 nv := (*uint8)(nil)212 pv := &v213 vAddr := fmt.Sprintf("%p", pv)214 pvAddr := fmt.Sprintf("%p", &pv)215 vt := "uint8"216 vs := "255"217 addFormatterTest("%v", v, vs)218 addFormatterTest("%v", pv, "<*>"+vs)219 addFormatterTest("%v", &pv, "<**>"+vs)220 addFormatterTest("%v", nv, "<nil>")221 addFormatterTest("%+v", v, vs)222 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)223 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)224 addFormatterTest("%+v", nv, "<nil>")225 addFormatterTest("%#v", v, "("+vt+")"+vs)226 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)227 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)228 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")229 addFormatterTest("%#+v", v, "("+vt+")"+vs)230 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)231 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)232 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")233 // Max uint16.234 v2 := uint16(65535)235 nv2 := (*uint16)(nil)236 pv2 := &v2237 v2Addr := fmt.Sprintf("%p", pv2)238 pv2Addr := fmt.Sprintf("%p", &pv2)239 v2t := "uint16"240 v2s := "65535"241 addFormatterTest("%v", v2, v2s)242 addFormatterTest("%v", pv2, "<*>"+v2s)243 addFormatterTest("%v", &pv2, "<**>"+v2s)244 addFormatterTest("%v", nv2, "<nil>")245 addFormatterTest("%+v", v2, v2s)246 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)247 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)248 addFormatterTest("%+v", nv2, "<nil>")249 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)250 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)251 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)252 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")253 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)254 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)255 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)256 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")257 // Max uint32.258 v3 := uint32(4294967295)259 nv3 := (*uint32)(nil)260 pv3 := &v3261 v3Addr := fmt.Sprintf("%p", pv3)262 pv3Addr := fmt.Sprintf("%p", &pv3)263 v3t := "uint32"264 v3s := "4294967295"265 addFormatterTest("%v", v3, v3s)266 addFormatterTest("%v", pv3, "<*>"+v3s)267 addFormatterTest("%v", &pv3, "<**>"+v3s)268 addFormatterTest("%v", nv3, "<nil>")269 addFormatterTest("%+v", v3, v3s)270 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s)271 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s)272 addFormatterTest("%+v", nv3, "<nil>")273 addFormatterTest("%#v", v3, "("+v3t+")"+v3s)274 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s)275 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s)276 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")277 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s)278 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s)279 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s)280 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")281 // Max uint64.282 v4 := uint64(18446744073709551615)283 nv4 := (*uint64)(nil)284 pv4 := &v4285 v4Addr := fmt.Sprintf("%p", pv4)286 pv4Addr := fmt.Sprintf("%p", &pv4)287 v4t := "uint64"288 v4s := "18446744073709551615"289 addFormatterTest("%v", v4, v4s)290 addFormatterTest("%v", pv4, "<*>"+v4s)291 addFormatterTest("%v", &pv4, "<**>"+v4s)292 addFormatterTest("%v", nv4, "<nil>")293 addFormatterTest("%+v", v4, v4s)294 addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s)295 addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s)296 addFormatterTest("%+v", nv4, "<nil>")297 addFormatterTest("%#v", v4, "("+v4t+")"+v4s)298 addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s)299 addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s)300 addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")301 addFormatterTest("%#+v", v4, "("+v4t+")"+v4s)302 addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s)303 addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s)304 addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")305 // Max uint.306 v5 := uint(4294967295)307 nv5 := (*uint)(nil)308 pv5 := &v5309 v5Addr := fmt.Sprintf("%p", pv5)310 pv5Addr := fmt.Sprintf("%p", &pv5)311 v5t := "uint"312 v5s := "4294967295"313 addFormatterTest("%v", v5, v5s)314 addFormatterTest("%v", pv5, "<*>"+v5s)315 addFormatterTest("%v", &pv5, "<**>"+v5s)316 addFormatterTest("%v", nv5, "<nil>")317 addFormatterTest("%+v", v5, v5s)318 addFormatterTest("%+v", pv5, "<*>("+v5Addr+")"+v5s)319 addFormatterTest("%+v", &pv5, "<**>("+pv5Addr+"->"+v5Addr+")"+v5s)320 addFormatterTest("%+v", nv5, "<nil>")321 addFormatterTest("%#v", v5, "("+v5t+")"+v5s)322 addFormatterTest("%#v", pv5, "(*"+v5t+")"+v5s)323 addFormatterTest("%#v", &pv5, "(**"+v5t+")"+v5s)324 addFormatterTest("%#v", nv5, "(*"+v5t+")"+"<nil>")325 addFormatterTest("%#+v", v5, "("+v5t+")"+v5s)326 addFormatterTest("%#+v", pv5, "(*"+v5t+")("+v5Addr+")"+v5s)327 addFormatterTest("%#+v", &pv5, "(**"+v5t+")("+pv5Addr+"->"+v5Addr+")"+v5s)328 addFormatterTest("%#v", nv5, "(*"+v5t+")"+"<nil>")329}330func addBoolFormatterTests() {331 // Boolean true.332 v := bool(true)333 nv := (*bool)(nil)334 pv := &v335 vAddr := fmt.Sprintf("%p", pv)336 pvAddr := fmt.Sprintf("%p", &pv)337 vt := "bool"338 vs := "true"339 addFormatterTest("%v", v, vs)340 addFormatterTest("%v", pv, "<*>"+vs)341 addFormatterTest("%v", &pv, "<**>"+vs)342 addFormatterTest("%v", nv, "<nil>")343 addFormatterTest("%+v", v, vs)344 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)345 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)346 addFormatterTest("%+v", nv, "<nil>")347 addFormatterTest("%#v", v, "("+vt+")"+vs)348 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)349 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)350 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")351 addFormatterTest("%#+v", v, "("+vt+")"+vs)352 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)353 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)354 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")355 // Boolean false.356 v2 := bool(false)357 pv2 := &v2358 v2Addr := fmt.Sprintf("%p", pv2)359 pv2Addr := fmt.Sprintf("%p", &pv2)360 v2t := "bool"361 v2s := "false"362 addFormatterTest("%v", v2, v2s)363 addFormatterTest("%v", pv2, "<*>"+v2s)364 addFormatterTest("%v", &pv2, "<**>"+v2s)365 addFormatterTest("%+v", v2, v2s)366 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)367 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)368 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)369 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)370 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)371 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)372 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)373 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)374}375func addFloatFormatterTests() {376 // Standard float32.377 v := float32(3.1415)378 nv := (*float32)(nil)379 pv := &v380 vAddr := fmt.Sprintf("%p", pv)381 pvAddr := fmt.Sprintf("%p", &pv)382 vt := "float32"383 vs := "3.1415"384 addFormatterTest("%v", v, vs)385 addFormatterTest("%v", pv, "<*>"+vs)386 addFormatterTest("%v", &pv, "<**>"+vs)387 addFormatterTest("%v", nv, "<nil>")388 addFormatterTest("%+v", v, vs)389 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)390 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)391 addFormatterTest("%+v", nv, "<nil>")392 addFormatterTest("%#v", v, "("+vt+")"+vs)393 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)394 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)395 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")396 addFormatterTest("%#+v", v, "("+vt+")"+vs)397 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)398 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)399 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")400 // Standard float64.401 v2 := float64(3.1415926)402 nv2 := (*float64)(nil)403 pv2 := &v2404 v2Addr := fmt.Sprintf("%p", pv2)405 pv2Addr := fmt.Sprintf("%p", &pv2)406 v2t := "float64"407 v2s := "3.1415926"408 addFormatterTest("%v", v2, v2s)409 addFormatterTest("%v", pv2, "<*>"+v2s)410 addFormatterTest("%v", &pv2, "<**>"+v2s)411 addFormatterTest("%+v", nv2, "<nil>")412 addFormatterTest("%+v", v2, v2s)413 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)414 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)415 addFormatterTest("%+v", nv2, "<nil>")416 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)417 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)418 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)419 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")420 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)421 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)422 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)423 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")424}425func addComplexFormatterTests() {426 // Standard complex64.427 v := complex(float32(6), -2)428 nv := (*complex64)(nil)429 pv := &v430 vAddr := fmt.Sprintf("%p", pv)431 pvAddr := fmt.Sprintf("%p", &pv)432 vt := "complex64"433 vs := "(6-2i)"434 addFormatterTest("%v", v, vs)435 addFormatterTest("%v", pv, "<*>"+vs)436 addFormatterTest("%v", &pv, "<**>"+vs)437 addFormatterTest("%+v", nv, "<nil>")438 addFormatterTest("%+v", v, vs)439 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)440 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)441 addFormatterTest("%+v", nv, "<nil>")442 addFormatterTest("%#v", v, "("+vt+")"+vs)443 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)444 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)445 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")446 addFormatterTest("%#+v", v, "("+vt+")"+vs)447 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)448 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)449 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")450 // Standard complex128.451 v2 := complex(float64(-6), 2)452 nv2 := (*complex128)(nil)453 pv2 := &v2454 v2Addr := fmt.Sprintf("%p", pv2)455 pv2Addr := fmt.Sprintf("%p", &pv2)456 v2t := "complex128"457 v2s := "(-6+2i)"458 addFormatterTest("%v", v2, v2s)459 addFormatterTest("%v", pv2, "<*>"+v2s)460 addFormatterTest("%v", &pv2, "<**>"+v2s)461 addFormatterTest("%+v", nv2, "<nil>")462 addFormatterTest("%+v", v2, v2s)463 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)464 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)465 addFormatterTest("%+v", nv2, "<nil>")466 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)467 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)468 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)469 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")470 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)471 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)472 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)473 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")474}475func addArrayFormatterTests() {476 // Array containing standard ints.477 v := [3]int{1, 2, 3}478 nv := (*[3]int)(nil)479 pv := &v480 vAddr := fmt.Sprintf("%p", pv)481 pvAddr := fmt.Sprintf("%p", &pv)482 vt := "[3]int"483 vs := "[1 2 3]"484 addFormatterTest("%v", v, vs)485 addFormatterTest("%v", pv, "<*>"+vs)486 addFormatterTest("%v", &pv, "<**>"+vs)487 addFormatterTest("%+v", nv, "<nil>")488 addFormatterTest("%+v", v, vs)489 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)490 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)491 addFormatterTest("%+v", nv, "<nil>")492 addFormatterTest("%#v", v, "("+vt+")"+vs)493 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)494 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)495 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")496 addFormatterTest("%#+v", v, "("+vt+")"+vs)497 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)498 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)499 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")500 // Array containing type with custom formatter on pointer receiver only.501 v2 := [3]pstringer{"1", "2", "3"}502 nv2 := (*[3]pstringer)(nil)503 pv2 := &v2504 v2Addr := fmt.Sprintf("%p", pv2)505 pv2Addr := fmt.Sprintf("%p", &pv2)506 v2t := "[3]spew_test.pstringer"507 v2sp := "[stringer 1 stringer 2 stringer 3]"508 v2s := v2sp509 if spew.UnsafeDisabled {510 v2s = "[1 2 3]"511 }512 addFormatterTest("%v", v2, v2s)513 addFormatterTest("%v", pv2, "<*>"+v2sp)514 addFormatterTest("%v", &pv2, "<**>"+v2sp)515 addFormatterTest("%+v", nv2, "<nil>")516 addFormatterTest("%+v", v2, v2s)517 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2sp)518 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2sp)519 addFormatterTest("%+v", nv2, "<nil>")520 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)521 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2sp)522 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2sp)523 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")524 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)525 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2sp)526 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2sp)527 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")528 // Array containing interfaces.529 v3 := [3]interface{}{"one", int(2), uint(3)}530 nv3 := (*[3]interface{})(nil)531 pv3 := &v3532 v3Addr := fmt.Sprintf("%p", pv3)533 pv3Addr := fmt.Sprintf("%p", &pv3)534 v3t := "[3]interface {}"535 v3t2 := "string"536 v3t3 := "int"537 v3t4 := "uint"538 v3s := "[one 2 3]"539 v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3]"540 addFormatterTest("%v", v3, v3s)541 addFormatterTest("%v", pv3, "<*>"+v3s)542 addFormatterTest("%v", &pv3, "<**>"+v3s)543 addFormatterTest("%+v", nv3, "<nil>")544 addFormatterTest("%+v", v3, v3s)545 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s)546 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s)547 addFormatterTest("%+v", nv3, "<nil>")548 addFormatterTest("%#v", v3, "("+v3t+")"+v3s2)549 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2)550 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2)551 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")552 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2)553 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2)554 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2)555 addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")556}557func addSliceFormatterTests() {558 // Slice containing standard float32 values.559 v := []float32{3.14, 6.28, 12.56}560 nv := (*[]float32)(nil)561 pv := &v562 vAddr := fmt.Sprintf("%p", pv)563 pvAddr := fmt.Sprintf("%p", &pv)564 vt := "[]float32"565 vs := "[3.14 6.28 12.56]"566 addFormatterTest("%v", v, vs)567 addFormatterTest("%v", pv, "<*>"+vs)568 addFormatterTest("%v", &pv, "<**>"+vs)569 addFormatterTest("%+v", nv, "<nil>")570 addFormatterTest("%+v", v, vs)571 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)572 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)573 addFormatterTest("%+v", nv, "<nil>")574 addFormatterTest("%#v", v, "("+vt+")"+vs)575 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)576 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)577 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")578 addFormatterTest("%#+v", v, "("+vt+")"+vs)579 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)580 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)581 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")582 // Slice containing type with custom formatter on pointer receiver only.583 v2 := []pstringer{"1", "2", "3"}584 nv2 := (*[]pstringer)(nil)585 pv2 := &v2586 v2Addr := fmt.Sprintf("%p", pv2)587 pv2Addr := fmt.Sprintf("%p", &pv2)588 v2t := "[]spew_test.pstringer"589 v2s := "[stringer 1 stringer 2 stringer 3]"590 addFormatterTest("%v", v2, v2s)591 addFormatterTest("%v", pv2, "<*>"+v2s)592 addFormatterTest("%v", &pv2, "<**>"+v2s)593 addFormatterTest("%+v", nv2, "<nil>")594 addFormatterTest("%+v", v2, v2s)595 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)596 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)597 addFormatterTest("%+v", nv2, "<nil>")598 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)599 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)600 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)601 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")602 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)603 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)604 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)605 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")606 // Slice containing interfaces.607 v3 := []interface{}{"one", int(2), uint(3), nil}608 nv3 := (*[]interface{})(nil)609 pv3 := &v3610 v3Addr := fmt.Sprintf("%p", pv3)611 pv3Addr := fmt.Sprintf("%p", &pv3)612 v3t := "[]interface {}"613 v3t2 := "string"614 v3t3 := "int"615 v3t4 := "uint"616 v3t5 := "interface {}"617 v3s := "[one 2 3 <nil>]"618 v3s2 := "[(" + v3t2 + ")one (" + v3t3 + ")2 (" + v3t4 + ")3 (" + v3t5 +619 ")<nil>]"620 addFormatterTest("%v", v3, v3s)621 addFormatterTest("%v", pv3, "<*>"+v3s)622 addFormatterTest("%v", &pv3, "<**>"+v3s)623 addFormatterTest("%+v", nv3, "<nil>")624 addFormatterTest("%+v", v3, v3s)625 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s)626 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s)627 addFormatterTest("%+v", nv3, "<nil>")628 addFormatterTest("%#v", v3, "("+v3t+")"+v3s2)629 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2)630 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2)631 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")632 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2)633 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2)634 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2)635 addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")636 // Nil slice.637 var v4 []int638 nv4 := (*[]int)(nil)639 pv4 := &v4640 v4Addr := fmt.Sprintf("%p", pv4)641 pv4Addr := fmt.Sprintf("%p", &pv4)642 v4t := "[]int"643 v4s := "<nil>"644 addFormatterTest("%v", v4, v4s)645 addFormatterTest("%v", pv4, "<*>"+v4s)646 addFormatterTest("%v", &pv4, "<**>"+v4s)647 addFormatterTest("%+v", nv4, "<nil>")648 addFormatterTest("%+v", v4, v4s)649 addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s)650 addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s)651 addFormatterTest("%+v", nv4, "<nil>")652 addFormatterTest("%#v", v4, "("+v4t+")"+v4s)653 addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s)654 addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s)655 addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")656 addFormatterTest("%#+v", v4, "("+v4t+")"+v4s)657 addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s)658 addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s)659 addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")660}661func addStringFormatterTests() {662 // Standard string.663 v := "test"664 nv := (*string)(nil)665 pv := &v666 vAddr := fmt.Sprintf("%p", pv)667 pvAddr := fmt.Sprintf("%p", &pv)668 vt := "string"669 vs := "test"670 addFormatterTest("%v", v, vs)671 addFormatterTest("%v", pv, "<*>"+vs)672 addFormatterTest("%v", &pv, "<**>"+vs)673 addFormatterTest("%+v", nv, "<nil>")674 addFormatterTest("%+v", v, vs)675 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)676 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)677 addFormatterTest("%+v", nv, "<nil>")678 addFormatterTest("%#v", v, "("+vt+")"+vs)679 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)680 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)681 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")682 addFormatterTest("%#+v", v, "("+vt+")"+vs)683 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)684 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)685 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")686}687func addInterfaceFormatterTests() {688 // Nil interface.689 var v interface{}690 nv := (*interface{})(nil)691 pv := &v692 vAddr := fmt.Sprintf("%p", pv)693 pvAddr := fmt.Sprintf("%p", &pv)694 vt := "interface {}"695 vs := "<nil>"696 addFormatterTest("%v", v, vs)697 addFormatterTest("%v", pv, "<*>"+vs)698 addFormatterTest("%v", &pv, "<**>"+vs)699 addFormatterTest("%+v", nv, "<nil>")700 addFormatterTest("%+v", v, vs)701 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)702 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)703 addFormatterTest("%+v", nv, "<nil>")704 addFormatterTest("%#v", v, "("+vt+")"+vs)705 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)706 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)707 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")708 addFormatterTest("%#+v", v, "("+vt+")"+vs)709 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)710 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)711 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")712 // Sub-interface.713 v2 := interface{}(uint16(65535))714 pv2 := &v2715 v2Addr := fmt.Sprintf("%p", pv2)716 pv2Addr := fmt.Sprintf("%p", &pv2)717 v2t := "uint16"718 v2s := "65535"719 addFormatterTest("%v", v2, v2s)720 addFormatterTest("%v", pv2, "<*>"+v2s)721 addFormatterTest("%v", &pv2, "<**>"+v2s)722 addFormatterTest("%+v", v2, v2s)723 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)724 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)725 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)726 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)727 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)728 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)729 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)730 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)731}732func addMapFormatterTests() {733 // Map with string keys and int vals.734 v := map[string]int{"one": 1, "two": 2}735 nilMap := map[string]int(nil)736 nv := (*map[string]int)(nil)737 pv := &v738 vAddr := fmt.Sprintf("%p", pv)739 pvAddr := fmt.Sprintf("%p", &pv)740 vt := "map[string]int"741 vs := "map[one:1 two:2]"742 vs2 := "map[two:2 one:1]"743 addFormatterTest("%v", v, vs, vs2)744 addFormatterTest("%v", pv, "<*>"+vs, "<*>"+vs2)745 addFormatterTest("%v", &pv, "<**>"+vs, "<**>"+vs2)746 addFormatterTest("%+v", nilMap, "<nil>")747 addFormatterTest("%+v", nv, "<nil>")748 addFormatterTest("%+v", v, vs, vs2)749 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs, "<*>("+vAddr+")"+vs2)750 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs,751 "<**>("+pvAddr+"->"+vAddr+")"+vs2)752 addFormatterTest("%+v", nilMap, "<nil>")753 addFormatterTest("%+v", nv, "<nil>")754 addFormatterTest("%#v", v, "("+vt+")"+vs, "("+vt+")"+vs2)755 addFormatterTest("%#v", pv, "(*"+vt+")"+vs, "(*"+vt+")"+vs2)756 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs, "(**"+vt+")"+vs2)757 addFormatterTest("%#v", nilMap, "("+vt+")"+"<nil>")758 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")759 addFormatterTest("%#+v", v, "("+vt+")"+vs, "("+vt+")"+vs2)760 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs,761 "(*"+vt+")("+vAddr+")"+vs2)762 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs,763 "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs2)764 addFormatterTest("%#+v", nilMap, "("+vt+")"+"<nil>")765 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")766 // Map with custom formatter type on pointer receiver only keys and vals.767 v2 := map[pstringer]pstringer{"one": "1"}768 nv2 := (*map[pstringer]pstringer)(nil)769 pv2 := &v2770 v2Addr := fmt.Sprintf("%p", pv2)771 pv2Addr := fmt.Sprintf("%p", &pv2)772 v2t := "map[spew_test.pstringer]spew_test.pstringer"773 v2s := "map[stringer one:stringer 1]"774 if spew.UnsafeDisabled {775 v2s = "map[one:1]"776 }777 addFormatterTest("%v", v2, v2s)778 addFormatterTest("%v", pv2, "<*>"+v2s)779 addFormatterTest("%v", &pv2, "<**>"+v2s)780 addFormatterTest("%+v", nv2, "<nil>")781 addFormatterTest("%+v", v2, v2s)782 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)783 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)784 addFormatterTest("%+v", nv2, "<nil>")785 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)786 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)787 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)788 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")789 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)790 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)791 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)792 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")793 // Map with interface keys and values.794 v3 := map[interface{}]interface{}{"one": 1}795 nv3 := (*map[interface{}]interface{})(nil)796 pv3 := &v3797 v3Addr := fmt.Sprintf("%p", pv3)798 pv3Addr := fmt.Sprintf("%p", &pv3)799 v3t := "map[interface {}]interface {}"800 v3t1 := "string"801 v3t2 := "int"802 v3s := "map[one:1]"803 v3s2 := "map[(" + v3t1 + ")one:(" + v3t2 + ")1]"804 addFormatterTest("%v", v3, v3s)805 addFormatterTest("%v", pv3, "<*>"+v3s)806 addFormatterTest("%v", &pv3, "<**>"+v3s)807 addFormatterTest("%+v", nv3, "<nil>")808 addFormatterTest("%+v", v3, v3s)809 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s)810 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s)811 addFormatterTest("%+v", nv3, "<nil>")812 addFormatterTest("%#v", v3, "("+v3t+")"+v3s2)813 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s2)814 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s2)815 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")816 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s2)817 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s2)818 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s2)819 addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")820 // Map with nil interface value821 v4 := map[string]interface{}{"nil": nil}822 nv4 := (*map[string]interface{})(nil)823 pv4 := &v4824 v4Addr := fmt.Sprintf("%p", pv4)825 pv4Addr := fmt.Sprintf("%p", &pv4)826 v4t := "map[string]interface {}"827 v4t1 := "interface {}"828 v4s := "map[nil:<nil>]"829 v4s2 := "map[nil:(" + v4t1 + ")<nil>]"830 addFormatterTest("%v", v4, v4s)831 addFormatterTest("%v", pv4, "<*>"+v4s)832 addFormatterTest("%v", &pv4, "<**>"+v4s)833 addFormatterTest("%+v", nv4, "<nil>")834 addFormatterTest("%+v", v4, v4s)835 addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s)836 addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s)837 addFormatterTest("%+v", nv4, "<nil>")838 addFormatterTest("%#v", v4, "("+v4t+")"+v4s2)839 addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s2)840 addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s2)841 addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")842 addFormatterTest("%#+v", v4, "("+v4t+")"+v4s2)843 addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s2)844 addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s2)845 addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")846}847func addStructFormatterTests() {848 // Struct with primitives.849 type s1 struct {850 a int8851 b uint8852 }853 v := s1{127, 255}854 nv := (*s1)(nil)855 pv := &v856 vAddr := fmt.Sprintf("%p", pv)857 pvAddr := fmt.Sprintf("%p", &pv)858 vt := "spew_test.s1"859 vt2 := "int8"860 vt3 := "uint8"861 vs := "{127 255}"862 vs2 := "{a:127 b:255}"863 vs3 := "{a:(" + vt2 + ")127 b:(" + vt3 + ")255}"864 addFormatterTest("%v", v, vs)865 addFormatterTest("%v", pv, "<*>"+vs)866 addFormatterTest("%v", &pv, "<**>"+vs)867 addFormatterTest("%+v", nv, "<nil>")868 addFormatterTest("%+v", v, vs2)869 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs2)870 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs2)871 addFormatterTest("%+v", nv, "<nil>")872 addFormatterTest("%#v", v, "("+vt+")"+vs3)873 addFormatterTest("%#v", pv, "(*"+vt+")"+vs3)874 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs3)875 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")876 addFormatterTest("%#+v", v, "("+vt+")"+vs3)877 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs3)878 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs3)879 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")880 // Struct that contains another struct.881 type s2 struct {882 s1 s1883 b bool884 }885 v2 := s2{s1{127, 255}, true}886 nv2 := (*s2)(nil)887 pv2 := &v2888 v2Addr := fmt.Sprintf("%p", pv2)889 pv2Addr := fmt.Sprintf("%p", &pv2)890 v2t := "spew_test.s2"891 v2t2 := "spew_test.s1"892 v2t3 := "int8"893 v2t4 := "uint8"894 v2t5 := "bool"895 v2s := "{{127 255} true}"896 v2s2 := "{s1:{a:127 b:255} b:true}"897 v2s3 := "{s1:(" + v2t2 + "){a:(" + v2t3 + ")127 b:(" + v2t4 + ")255} b:(" +898 v2t5 + ")true}"899 addFormatterTest("%v", v2, v2s)900 addFormatterTest("%v", pv2, "<*>"+v2s)901 addFormatterTest("%v", &pv2, "<**>"+v2s)902 addFormatterTest("%+v", nv2, "<nil>")903 addFormatterTest("%+v", v2, v2s2)904 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s2)905 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s2)906 addFormatterTest("%+v", nv2, "<nil>")907 addFormatterTest("%#v", v2, "("+v2t+")"+v2s3)908 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s3)909 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s3)910 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")911 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s3)912 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s3)913 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s3)914 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")915 // Struct that contains custom type with Stringer pointer interface via both916 // exported and unexported fields.917 type s3 struct {918 s pstringer919 S pstringer920 }921 v3 := s3{"test", "test2"}922 nv3 := (*s3)(nil)923 pv3 := &v3924 v3Addr := fmt.Sprintf("%p", pv3)925 pv3Addr := fmt.Sprintf("%p", &pv3)926 v3t := "spew_test.s3"927 v3t2 := "spew_test.pstringer"928 v3s := "{stringer test stringer test2}"929 v3sp := v3s930 v3s2 := "{s:stringer test S:stringer test2}"931 v3s2p := v3s2932 v3s3 := "{s:(" + v3t2 + ")stringer test S:(" + v3t2 + ")stringer test2}"933 v3s3p := v3s3934 if spew.UnsafeDisabled {935 v3s = "{test test2}"936 v3sp = "{test stringer test2}"937 v3s2 = "{s:test S:test2}"938 v3s2p = "{s:test S:stringer test2}"939 v3s3 = "{s:(" + v3t2 + ")test S:(" + v3t2 + ")test2}"940 v3s3p = "{s:(" + v3t2 + ")test S:(" + v3t2 + ")stringer test2}"941 }942 addFormatterTest("%v", v3, v3s)943 addFormatterTest("%v", pv3, "<*>"+v3sp)944 addFormatterTest("%v", &pv3, "<**>"+v3sp)945 addFormatterTest("%+v", nv3, "<nil>")946 addFormatterTest("%+v", v3, v3s2)947 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s2p)948 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s2p)949 addFormatterTest("%+v", nv3, "<nil>")950 addFormatterTest("%#v", v3, "("+v3t+")"+v3s3)951 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s3p)952 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s3p)953 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")954 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s3)955 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s3p)956 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s3p)957 addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")958 // Struct that contains embedded struct and field to same struct.959 e := embed{"embedstr"}960 v4 := embedwrap{embed: &e, e: &e}961 nv4 := (*embedwrap)(nil)962 pv4 := &v4963 eAddr := fmt.Sprintf("%p", &e)964 v4Addr := fmt.Sprintf("%p", pv4)965 pv4Addr := fmt.Sprintf("%p", &pv4)966 v4t := "spew_test.embedwrap"967 v4t2 := "spew_test.embed"968 v4t3 := "string"969 v4s := "{<*>{embedstr} <*>{embedstr}}"970 v4s2 := "{embed:<*>(" + eAddr + "){a:embedstr} e:<*>(" + eAddr +971 "){a:embedstr}}"972 v4s3 := "{embed:(*" + v4t2 + "){a:(" + v4t3 + ")embedstr} e:(*" + v4t2 +973 "){a:(" + v4t3 + ")embedstr}}"974 v4s4 := "{embed:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 +975 ")embedstr} e:(*" + v4t2 + ")(" + eAddr + "){a:(" + v4t3 + ")embedstr}}"976 addFormatterTest("%v", v4, v4s)977 addFormatterTest("%v", pv4, "<*>"+v4s)978 addFormatterTest("%v", &pv4, "<**>"+v4s)979 addFormatterTest("%+v", nv4, "<nil>")980 addFormatterTest("%+v", v4, v4s2)981 addFormatterTest("%+v", pv4, "<*>("+v4Addr+")"+v4s2)982 addFormatterTest("%+v", &pv4, "<**>("+pv4Addr+"->"+v4Addr+")"+v4s2)983 addFormatterTest("%+v", nv4, "<nil>")984 addFormatterTest("%#v", v4, "("+v4t+")"+v4s3)985 addFormatterTest("%#v", pv4, "(*"+v4t+")"+v4s3)986 addFormatterTest("%#v", &pv4, "(**"+v4t+")"+v4s3)987 addFormatterTest("%#v", nv4, "(*"+v4t+")"+"<nil>")988 addFormatterTest("%#+v", v4, "("+v4t+")"+v4s4)989 addFormatterTest("%#+v", pv4, "(*"+v4t+")("+v4Addr+")"+v4s4)990 addFormatterTest("%#+v", &pv4, "(**"+v4t+")("+pv4Addr+"->"+v4Addr+")"+v4s4)991 addFormatterTest("%#+v", nv4, "(*"+v4t+")"+"<nil>")992}993func addUintptrFormatterTests() {994 // Null pointer.995 v := uintptr(0)996 nv := (*uintptr)(nil)997 pv := &v998 vAddr := fmt.Sprintf("%p", pv)999 pvAddr := fmt.Sprintf("%p", &pv)1000 vt := "uintptr"1001 vs := "<nil>"1002 addFormatterTest("%v", v, vs)1003 addFormatterTest("%v", pv, "<*>"+vs)1004 addFormatterTest("%v", &pv, "<**>"+vs)1005 addFormatterTest("%+v", nv, "<nil>")1006 addFormatterTest("%+v", v, vs)1007 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)1008 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)1009 addFormatterTest("%+v", nv, "<nil>")1010 addFormatterTest("%#v", v, "("+vt+")"+vs)1011 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)1012 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)1013 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")1014 addFormatterTest("%#+v", v, "("+vt+")"+vs)1015 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)1016 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)1017 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")1018 // Address of real variable.1019 i := 11020 v2 := uintptr(unsafe.Pointer(&i))1021 pv2 := &v21022 v2Addr := fmt.Sprintf("%p", pv2)1023 pv2Addr := fmt.Sprintf("%p", &pv2)1024 v2t := "uintptr"1025 v2s := fmt.Sprintf("%p", &i)1026 addFormatterTest("%v", v2, v2s)1027 addFormatterTest("%v", pv2, "<*>"+v2s)1028 addFormatterTest("%v", &pv2, "<**>"+v2s)1029 addFormatterTest("%+v", v2, v2s)1030 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)1031 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)1032 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)1033 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)1034 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)1035 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)1036 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)1037 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)1038}1039func addUnsafePointerFormatterTests() {1040 // Null pointer.1041 v := unsafe.Pointer(uintptr(0))1042 nv := (*unsafe.Pointer)(nil)1043 pv := &v1044 vAddr := fmt.Sprintf("%p", pv)1045 pvAddr := fmt.Sprintf("%p", &pv)1046 vt := "unsafe.Pointer"1047 vs := "<nil>"1048 addFormatterTest("%v", v, vs)1049 addFormatterTest("%v", pv, "<*>"+vs)1050 addFormatterTest("%v", &pv, "<**>"+vs)1051 addFormatterTest("%+v", nv, "<nil>")1052 addFormatterTest("%+v", v, vs)1053 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)1054 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)1055 addFormatterTest("%+v", nv, "<nil>")1056 addFormatterTest("%#v", v, "("+vt+")"+vs)1057 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)1058 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)1059 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")1060 addFormatterTest("%#+v", v, "("+vt+")"+vs)1061 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)1062 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)1063 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")1064 // Address of real variable.1065 i := 11066 v2 := unsafe.Pointer(&i)1067 pv2 := &v21068 v2Addr := fmt.Sprintf("%p", pv2)1069 pv2Addr := fmt.Sprintf("%p", &pv2)1070 v2t := "unsafe.Pointer"1071 v2s := fmt.Sprintf("%p", &i)1072 addFormatterTest("%v", v2, v2s)1073 addFormatterTest("%v", pv2, "<*>"+v2s)1074 addFormatterTest("%v", &pv2, "<**>"+v2s)1075 addFormatterTest("%+v", v2, v2s)1076 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)1077 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)1078 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)1079 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)1080 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)1081 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)1082 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)1083 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)1084}1085func addChanFormatterTests() {1086 // Nil channel.1087 var v chan int1088 pv := &v1089 nv := (*chan int)(nil)1090 vAddr := fmt.Sprintf("%p", pv)1091 pvAddr := fmt.Sprintf("%p", &pv)1092 vt := "chan int"1093 vs := "<nil>"1094 addFormatterTest("%v", v, vs)1095 addFormatterTest("%v", pv, "<*>"+vs)1096 addFormatterTest("%v", &pv, "<**>"+vs)1097 addFormatterTest("%+v", nv, "<nil>")1098 addFormatterTest("%+v", v, vs)1099 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)1100 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)1101 addFormatterTest("%+v", nv, "<nil>")1102 addFormatterTest("%#v", v, "("+vt+")"+vs)1103 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)1104 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)1105 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")1106 addFormatterTest("%#+v", v, "("+vt+")"+vs)1107 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)1108 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)1109 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")1110 // Real channel.1111 v2 := make(chan int)1112 pv2 := &v21113 v2Addr := fmt.Sprintf("%p", pv2)1114 pv2Addr := fmt.Sprintf("%p", &pv2)1115 v2t := "chan int"1116 v2s := fmt.Sprintf("%p", v2)1117 addFormatterTest("%v", v2, v2s)1118 addFormatterTest("%v", pv2, "<*>"+v2s)1119 addFormatterTest("%v", &pv2, "<**>"+v2s)1120 addFormatterTest("%+v", v2, v2s)1121 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)1122 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)1123 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)1124 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)1125 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)1126 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)1127 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)1128 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)1129}1130func addFuncFormatterTests() {1131 // Function with no params and no returns.1132 v := addIntFormatterTests1133 nv := (*func())(nil)1134 pv := &v1135 vAddr := fmt.Sprintf("%p", pv)1136 pvAddr := fmt.Sprintf("%p", &pv)1137 vt := "func()"1138 vs := fmt.Sprintf("%p", v)1139 addFormatterTest("%v", v, vs)1140 addFormatterTest("%v", pv, "<*>"+vs)1141 addFormatterTest("%v", &pv, "<**>"+vs)1142 addFormatterTest("%+v", nv, "<nil>")1143 addFormatterTest("%+v", v, vs)1144 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)1145 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)1146 addFormatterTest("%+v", nv, "<nil>")1147 addFormatterTest("%#v", v, "("+vt+")"+vs)1148 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)1149 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)1150 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")1151 addFormatterTest("%#+v", v, "("+vt+")"+vs)1152 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)1153 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)1154 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")1155 // Function with param and no returns.1156 v2 := TestFormatter1157 nv2 := (*func(*testing.T))(nil)1158 pv2 := &v21159 v2Addr := fmt.Sprintf("%p", pv2)1160 pv2Addr := fmt.Sprintf("%p", &pv2)1161 v2t := "func(*testing.T)"1162 v2s := fmt.Sprintf("%p", v2)1163 addFormatterTest("%v", v2, v2s)1164 addFormatterTest("%v", pv2, "<*>"+v2s)1165 addFormatterTest("%v", &pv2, "<**>"+v2s)1166 addFormatterTest("%+v", nv2, "<nil>")1167 addFormatterTest("%+v", v2, v2s)1168 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s)1169 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s)1170 addFormatterTest("%+v", nv2, "<nil>")1171 addFormatterTest("%#v", v2, "("+v2t+")"+v2s)1172 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s)1173 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s)1174 addFormatterTest("%#v", nv2, "(*"+v2t+")"+"<nil>")1175 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s)1176 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s)1177 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s)1178 addFormatterTest("%#+v", nv2, "(*"+v2t+")"+"<nil>")1179 // Function with multiple params and multiple returns.1180 var v3 = func(i int, s string) (b bool, err error) {1181 return true, nil1182 }1183 nv3 := (*func(int, string) (bool, error))(nil)1184 pv3 := &v31185 v3Addr := fmt.Sprintf("%p", pv3)1186 pv3Addr := fmt.Sprintf("%p", &pv3)1187 v3t := "func(int, string) (bool, error)"1188 v3s := fmt.Sprintf("%p", v3)1189 addFormatterTest("%v", v3, v3s)1190 addFormatterTest("%v", pv3, "<*>"+v3s)1191 addFormatterTest("%v", &pv3, "<**>"+v3s)1192 addFormatterTest("%+v", nv3, "<nil>")1193 addFormatterTest("%+v", v3, v3s)1194 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s)1195 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s)1196 addFormatterTest("%+v", nv3, "<nil>")1197 addFormatterTest("%#v", v3, "("+v3t+")"+v3s)1198 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s)1199 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s)1200 addFormatterTest("%#v", nv3, "(*"+v3t+")"+"<nil>")1201 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s)1202 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s)1203 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s)1204 addFormatterTest("%#+v", nv3, "(*"+v3t+")"+"<nil>")1205}1206func addCircularFormatterTests() {1207 // Struct that is circular through self referencing.1208 type circular struct {1209 c *circular1210 }1211 v := circular{nil}1212 v.c = &v1213 pv := &v1214 vAddr := fmt.Sprintf("%p", pv)1215 pvAddr := fmt.Sprintf("%p", &pv)1216 vt := "spew_test.circular"1217 vs := "{<*>{<*><shown>}}"1218 vs2 := "{<*><shown>}"1219 vs3 := "{c:<*>(" + vAddr + "){c:<*>(" + vAddr + ")<shown>}}"1220 vs4 := "{c:<*>(" + vAddr + ")<shown>}"1221 vs5 := "{c:(*" + vt + "){c:(*" + vt + ")<shown>}}"1222 vs6 := "{c:(*" + vt + ")<shown>}"1223 vs7 := "{c:(*" + vt + ")(" + vAddr + "){c:(*" + vt + ")(" + vAddr +1224 ")<shown>}}"1225 vs8 := "{c:(*" + vt + ")(" + vAddr + ")<shown>}"1226 addFormatterTest("%v", v, vs)1227 addFormatterTest("%v", pv, "<*>"+vs2)1228 addFormatterTest("%v", &pv, "<**>"+vs2)1229 addFormatterTest("%+v", v, vs3)1230 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs4)1231 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs4)1232 addFormatterTest("%#v", v, "("+vt+")"+vs5)1233 addFormatterTest("%#v", pv, "(*"+vt+")"+vs6)1234 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs6)1235 addFormatterTest("%#+v", v, "("+vt+")"+vs7)1236 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs8)1237 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs8)1238 // Structs that are circular through cross referencing.1239 v2 := xref1{nil}1240 ts2 := xref2{&v2}1241 v2.ps2 = &ts21242 pv2 := &v21243 ts2Addr := fmt.Sprintf("%p", &ts2)1244 v2Addr := fmt.Sprintf("%p", pv2)1245 pv2Addr := fmt.Sprintf("%p", &pv2)1246 v2t := "spew_test.xref1"1247 v2t2 := "spew_test.xref2"1248 v2s := "{<*>{<*>{<*><shown>}}}"1249 v2s2 := "{<*>{<*><shown>}}"1250 v2s3 := "{ps2:<*>(" + ts2Addr + "){ps1:<*>(" + v2Addr + "){ps2:<*>(" +1251 ts2Addr + ")<shown>}}}"1252 v2s4 := "{ps2:<*>(" + ts2Addr + "){ps1:<*>(" + v2Addr + ")<shown>}}"1253 v2s5 := "{ps2:(*" + v2t2 + "){ps1:(*" + v2t + "){ps2:(*" + v2t2 +1254 ")<shown>}}}"1255 v2s6 := "{ps2:(*" + v2t2 + "){ps1:(*" + v2t + ")<shown>}}"1256 v2s7 := "{ps2:(*" + v2t2 + ")(" + ts2Addr + "){ps1:(*" + v2t +1257 ")(" + v2Addr + "){ps2:(*" + v2t2 + ")(" + ts2Addr +1258 ")<shown>}}}"1259 v2s8 := "{ps2:(*" + v2t2 + ")(" + ts2Addr + "){ps1:(*" + v2t +1260 ")(" + v2Addr + ")<shown>}}"1261 addFormatterTest("%v", v2, v2s)1262 addFormatterTest("%v", pv2, "<*>"+v2s2)1263 addFormatterTest("%v", &pv2, "<**>"+v2s2)1264 addFormatterTest("%+v", v2, v2s3)1265 addFormatterTest("%+v", pv2, "<*>("+v2Addr+")"+v2s4)1266 addFormatterTest("%+v", &pv2, "<**>("+pv2Addr+"->"+v2Addr+")"+v2s4)1267 addFormatterTest("%#v", v2, "("+v2t+")"+v2s5)1268 addFormatterTest("%#v", pv2, "(*"+v2t+")"+v2s6)1269 addFormatterTest("%#v", &pv2, "(**"+v2t+")"+v2s6)1270 addFormatterTest("%#+v", v2, "("+v2t+")"+v2s7)1271 addFormatterTest("%#+v", pv2, "(*"+v2t+")("+v2Addr+")"+v2s8)1272 addFormatterTest("%#+v", &pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")"+v2s8)1273 // Structs that are indirectly circular.1274 v3 := indirCir1{nil}1275 tic2 := indirCir2{nil}1276 tic3 := indirCir3{&v3}1277 tic2.ps3 = &tic31278 v3.ps2 = &tic21279 pv3 := &v31280 tic2Addr := fmt.Sprintf("%p", &tic2)1281 tic3Addr := fmt.Sprintf("%p", &tic3)1282 v3Addr := fmt.Sprintf("%p", pv3)1283 pv3Addr := fmt.Sprintf("%p", &pv3)1284 v3t := "spew_test.indirCir1"1285 v3t2 := "spew_test.indirCir2"1286 v3t3 := "spew_test.indirCir3"1287 v3s := "{<*>{<*>{<*>{<*><shown>}}}}"1288 v3s2 := "{<*>{<*>{<*><shown>}}}"1289 v3s3 := "{ps2:<*>(" + tic2Addr + "){ps3:<*>(" + tic3Addr + "){ps1:<*>(" +1290 v3Addr + "){ps2:<*>(" + tic2Addr + ")<shown>}}}}"1291 v3s4 := "{ps2:<*>(" + tic2Addr + "){ps3:<*>(" + tic3Addr + "){ps1:<*>(" +1292 v3Addr + ")<shown>}}}"1293 v3s5 := "{ps2:(*" + v3t2 + "){ps3:(*" + v3t3 + "){ps1:(*" + v3t +1294 "){ps2:(*" + v3t2 + ")<shown>}}}}"1295 v3s6 := "{ps2:(*" + v3t2 + "){ps3:(*" + v3t3 + "){ps1:(*" + v3t +1296 ")<shown>}}}"1297 v3s7 := "{ps2:(*" + v3t2 + ")(" + tic2Addr + "){ps3:(*" + v3t3 + ")(" +1298 tic3Addr + "){ps1:(*" + v3t + ")(" + v3Addr + "){ps2:(*" + v3t2 +1299 ")(" + tic2Addr + ")<shown>}}}}"1300 v3s8 := "{ps2:(*" + v3t2 + ")(" + tic2Addr + "){ps3:(*" + v3t3 + ")(" +1301 tic3Addr + "){ps1:(*" + v3t + ")(" + v3Addr + ")<shown>}}}"1302 addFormatterTest("%v", v3, v3s)1303 addFormatterTest("%v", pv3, "<*>"+v3s2)1304 addFormatterTest("%v", &pv3, "<**>"+v3s2)1305 addFormatterTest("%+v", v3, v3s3)1306 addFormatterTest("%+v", pv3, "<*>("+v3Addr+")"+v3s4)1307 addFormatterTest("%+v", &pv3, "<**>("+pv3Addr+"->"+v3Addr+")"+v3s4)1308 addFormatterTest("%#v", v3, "("+v3t+")"+v3s5)1309 addFormatterTest("%#v", pv3, "(*"+v3t+")"+v3s6)1310 addFormatterTest("%#v", &pv3, "(**"+v3t+")"+v3s6)1311 addFormatterTest("%#+v", v3, "("+v3t+")"+v3s7)1312 addFormatterTest("%#+v", pv3, "(*"+v3t+")("+v3Addr+")"+v3s8)1313 addFormatterTest("%#+v", &pv3, "(**"+v3t+")("+pv3Addr+"->"+v3Addr+")"+v3s8)1314}1315func addPanicFormatterTests() {1316 // Type that panics in its Stringer interface.1317 v := panicer(127)1318 nv := (*panicer)(nil)1319 pv := &v1320 vAddr := fmt.Sprintf("%p", pv)1321 pvAddr := fmt.Sprintf("%p", &pv)1322 vt := "spew_test.panicer"1323 vs := "(PANIC=test panic)127"1324 addFormatterTest("%v", v, vs)1325 addFormatterTest("%v", pv, "<*>"+vs)1326 addFormatterTest("%v", &pv, "<**>"+vs)1327 addFormatterTest("%v", nv, "<nil>")1328 addFormatterTest("%+v", v, vs)1329 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)1330 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)1331 addFormatterTest("%+v", nv, "<nil>")1332 addFormatterTest("%#v", v, "("+vt+")"+vs)1333 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)1334 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)1335 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")1336 addFormatterTest("%#+v", v, "("+vt+")"+vs)1337 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)1338 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)1339 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")1340}1341func addErrorFormatterTests() {1342 // Type that has a custom Error interface.1343 v := customError(127)1344 nv := (*customError)(nil)1345 pv := &v1346 vAddr := fmt.Sprintf("%p", pv)1347 pvAddr := fmt.Sprintf("%p", &pv)1348 vt := "spew_test.customError"1349 vs := "error: 127"1350 addFormatterTest("%v", v, vs)1351 addFormatterTest("%v", pv, "<*>"+vs)1352 addFormatterTest("%v", &pv, "<**>"+vs)1353 addFormatterTest("%v", nv, "<nil>")1354 addFormatterTest("%+v", v, vs)1355 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs)1356 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs)1357 addFormatterTest("%+v", nv, "<nil>")1358 addFormatterTest("%#v", v, "("+vt+")"+vs)1359 addFormatterTest("%#v", pv, "(*"+vt+")"+vs)1360 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs)1361 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")1362 addFormatterTest("%#+v", v, "("+vt+")"+vs)1363 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs)1364 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs)1365 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")1366}1367func addPassthroughFormatterTests() {1368 // %x passthrough with uint.1369 v := uint(4294967295)1370 pv := &v1371 vAddr := fmt.Sprintf("%x", pv)1372 pvAddr := fmt.Sprintf("%x", &pv)1373 vs := "ffffffff"1374 addFormatterTest("%x", v, vs)1375 addFormatterTest("%x", pv, vAddr)1376 addFormatterTest("%x", &pv, pvAddr)1377 // %#x passthrough with uint.1378 v2 := int(2147483647)1379 pv2 := &v21380 v2Addr := fmt.Sprintf("%#x", pv2)1381 pv2Addr := fmt.Sprintf("%#x", &pv2)1382 v2s := "0x7fffffff"1383 addFormatterTest("%#x", v2, v2s)1384 addFormatterTest("%#x", pv2, v2Addr)1385 addFormatterTest("%#x", &pv2, pv2Addr)1386 // %f passthrough with precision.1387 addFormatterTest("%.2f", 3.1415, "3.14")1388 addFormatterTest("%.3f", 3.1415, "3.142")1389 addFormatterTest("%.4f", 3.1415, "3.1415")1390 // %f passthrough with width and precision.1391 addFormatterTest("%5.2f", 3.1415, " 3.14")1392 addFormatterTest("%6.3f", 3.1415, " 3.142")1393 addFormatterTest("%7.4f", 3.1415, " 3.1415")1394 // %d passthrough with width.1395 addFormatterTest("%3d", 127, "127")1396 addFormatterTest("%4d", 127, " 127")1397 addFormatterTest("%5d", 127, " 127")1398 // %q passthrough with string.1399 addFormatterTest("%q", "test", "\"test\"")1400}1401// TestFormatter executes all of the tests described by formatterTests.1402func TestFormatter(t *testing.T) {1403 // Setup tests.1404 addIntFormatterTests()1405 addUintFormatterTests()1406 addBoolFormatterTests()1407 addFloatFormatterTests()1408 addComplexFormatterTests()1409 addArrayFormatterTests()1410 addSliceFormatterTests()1411 addStringFormatterTests()1412 addInterfaceFormatterTests()1413 addMapFormatterTests()1414 addStructFormatterTests()1415 addUintptrFormatterTests()1416 addUnsafePointerFormatterTests()1417 addChanFormatterTests()1418 addFuncFormatterTests()1419 addCircularFormatterTests()1420 addPanicFormatterTests()1421 addErrorFormatterTests()1422 addPassthroughFormatterTests()1423 t.Logf("Running %d tests", len(formatterTests))1424 for i, test := range formatterTests {1425 buf := new(bytes.Buffer)1426 spew.Fprintf(buf, test.format, test.in)1427 s := buf.String()1428 if testFailed(s, test.wants) {1429 t.Errorf("Formatter #%d format: %s got: %s %s", i, test.format, s,1430 stringizeWants(test.wants))1431 continue1432 }1433 }1434}1435type testStruct struct {1436 x int1437}1438func (ts testStruct) String() string {1439 return fmt.Sprintf("ts.%d", ts.x)1440}1441type testStructP struct {1442 x int1443}1444func (ts *testStructP) String() string {1445 return fmt.Sprintf("ts.%d", ts.x)1446}1447func TestPrintSortedKeys(t *testing.T) {1448 cfg := spew.ConfigState{SortKeys: true}1449 s := cfg.Sprint(map[int]string{1: "1", 3: "3", 2: "2"})1450 expected := "map[1:1 2:2 3:3]"1451 if s != expected {1452 t.Errorf("Sorted keys mismatch 1:\n %v %v", s, expected)1453 }1454 s = cfg.Sprint(map[stringer]int{"1": 1, "3": 3, "2": 2})1455 expected = "map[stringer 1:1 stringer 2:2 stringer 3:3]"1456 if s != expected {1457 t.Errorf("Sorted keys mismatch 2:\n %v %v", s, expected)1458 }1459 s = cfg.Sprint(map[pstringer]int{pstringer("1"): 1, pstringer("3"): 3, pstringer("2"): 2})1460 expected = "map[stringer 1:1 stringer 2:2 stringer 3:3]"1461 if spew.UnsafeDisabled {...
Test
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4}5import (6func main() {7 fmt.Println("Hello World")8}9import (10func main() {11 fmt.Println("Hello World")12}13import (14func main() {15 fmt.Println("Hello World")16}17import (18func main() {19 fmt.Println("Hello World")20}21import (22func main() {23 fmt.Println("Hello World")24}25import (26func main() {27 fmt.Println("Hello World")28}29import (30func main() {31 fmt.Println("Hello World")32}33import (34func main() {35 fmt.Println("Hello World")36}37import (38func main() {39 fmt.Println("Hello World")40}
Test
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Print("Enter your name: ")4 fmt.Scan(&name)5 fmt.Printf("Hello, %s!\n", name)6}
Test
Using AI Code Generation
1import (2func main() {3 fmtr := new(fmt.Formatter)4 f, err := os.Create("test.txt")5 if err != nil {6 fmt.Println(err)7 }8 fmtr.Write(f, "Hello world")9}
Test
Using AI Code Generation
1import (2func main() {3 fmt.Println(regexp.MustCompile("a([a-z]+)e").Test("apple"))4 fmt.Println(regexp.MustCompile("a([a-z]+)e").Test("orange"))5 fmt.Println(regexp.MustCompile("a([a-z]+)e").Test("grape"))6}
Test
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println("Hello World")4 fmt.Printf("Hello %s\n", "World")5 fmt.Printf("Hello %s, %s\n", "World", "golang")6 fmt.Printf("Hello %s, %s %d\n", "World", "golang", 2019)7 fmt.Printf("Hello %s, %s %d\n", "World", "golang", 2019)8 fmt.Printf("Hello %s, %s %d\n", "World", "golang", 2019)9 fmt.Printf("Hello %s, %s %d\n", "World", "golang", 2019)10 fmt.Printf("Hello %s, %s %d\n", "World", "golang", 2019)11}
Test
Using AI Code Generation
1import (2func main() {3 fmt.Printf("It is %v now. \n", time.Now())4 fmt.Printf("The time is %v. \n", time.Now().Format("15:04:05"))5 fmt.Printf("The time is %v. \n", time.Now().Format("3:04PM"))6 fmt.Printf("The time is %v. \n", time.Now().Format("Mon Jan _2 15:04:05 2006"))7 fmt.Printf("The time is %v. \n", time.Now().Format("2006-01-02T15:04:05.999999-07:00"))8 fmt.Printf("The time is %v. \n", time.Now().Format("2006-01-02T15:04:05.999999-07:00 MST"))9 fmt.Printf("The time is %v. \n", time.Now().Format("2006-01-02T15:04:05.999999-07:00 MST Monday"))10}
Test
Using AI Code Generation
1import (2func main() {3 f := new(fmt.Formatter)4 f.Test("Hello, World!")5 f.Test(42)6 f.Test(true)7 f.Test(false)8 f.Test(os.Stdout)9 f.Test(os.Stderr)10 f.Test(os.Stdin)11}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!