Codebase list golang-github-go-logr-logr / 4610455
Reformat existing test cases Tim Hockin 2 years ago
1 changed file(s) with 331 addition(s) and 336 deletion(s). Raw diff Collapse all Expand all
238238 cases := []struct {
239239 val interface{}
240240 exp string // used in cases where JSON can't handle it
241 }{
242 {val: "strval"},
243 {val: "strval\nwith\t\"escapes\""},
244 {val: substr("substrval")},
245 {val: substr("substrval\nwith\t\"escapes\"")},
246 {val: true},
247 {val: false},
248 {val: int(93)},
249 {val: int8(93)},
250 {val: int16(93)},
251 {val: int32(93)},
252 {val: int64(93)},
253 {val: int(-93)},
254 {val: int8(-93)},
255 {val: int16(-93)},
256 {val: int32(-93)},
257 {val: int64(-93)},
258 {val: uint(93)},
259 {val: uint8(93)},
260 {val: uint16(93)},
261 {val: uint32(93)},
262 {val: uint64(93)},
263 {val: uintptr(93)},
264 {val: float32(93.76)},
265 {val: float64(93.76)},
266 {
267 val: complex64(93i),
268 exp: `"(0+93i)"`,
269 },
270 {
271 val: complex128(93i),
272 exp: `"(0+93i)"`,
273 },
274 {val: ptrint(93)},
275 {val: ptrstr("pstrval")},
276 {val: []int{}},
277 {
278 val: []int(nil),
279 exp: `[]`,
280 },
281 {val: []int{9, 3, 7, 6}},
282 {val: []string{"str", "with\tescape"}},
283 {val: []substr{"substr", "with\tescape"}},
284 {val: [4]int{9, 3, 7, 6}},
285 {val: [2]string{"str", "with\tescape"}},
286 {val: [2]substr{"substr", "with\tescape"}},
287 {
288 val: struct {
289 Int int
290 notExported string
291 String string
292 }{
293 93, "you should not see this", "seventy-six",
294 },
295 },
296 {val: map[string]int{}},
297 {
298 val: map[string]int(nil),
299 exp: `{}`,
300 },
301 {
302 val: map[string]int{
303 "nine": 3,
304 },
305 },
306 {
307 val: map[string]int{
308 "with\tescape": 76,
309 },
310 },
311 {
312 val: map[substr]int{
313 "nine": 3,
314 },
315 },
316 {
317 val: map[substr]int{
318 "with\tescape": 76,
319 },
320 },
321 {
322 val: map[int]int{
323 9: 3,
324 },
325 },
326 {
327 val: map[float64]int{
328 9.5: 3,
329 },
330 exp: `{"9.5":3}`,
331 },
332 {
333 val: map[point]int{
334 {x: 1, y: 2}: 3,
335 },
336 },
337 {
338 val: map[pointErr]int{
339 {x: 1, y: 2}: 3,
340 },
341 exp: `{"<error-MarshalText: uh oh: 1, 2>":3}`,
342 },
343 {
344 val: struct {
345 X int `json:"x"`
346 Y int `json:"y"`
347 }{
348 93, 76,
349 },
350 },
351 {
352 val: struct {
353 X []int
354 Y map[int]int
355 Z struct{ P, Q int }
356 }{
357 []int{9, 3, 7, 6},
358 map[int]int{9: 3},
359 struct{ P, Q int }{9, 3},
360 },
361 },
362 {
363 val: []struct{ X, Y string }{
364 {"nine", "three"},
365 {"seven", "six"},
366 {"with\t", "\tescapes"},
367 },
368 },
369 {
370 val: struct {
371 A *int
372 B *int
373 C interface{}
374 D interface{}
375 }{
376 B: ptrint(1),
377 D: interface{}(2),
378 },
379 },
380 {
381 val: Tmarshaler{"foobar"},
382 exp: `{"Inner":"I am a logr.Marshaler"}`,
383 },
384 {
385 val: &Tmarshaler{"foobar"},
386 exp: `{"Inner":"I am a logr.Marshaler"}`,
387 },
388 {
389 val: (*Tmarshaler)(nil),
390 exp: `"<panic: value method github.com/go-logr/logr/funcr.Tmarshaler.MarshalLog called using nil *Tmarshaler pointer>"`,
391 },
392 {
393 val: Tmarshalerpanic{"foobar"},
394 exp: `"<panic: Tmarshalerpanic>"`,
395 },
396 {
397 val: Tstringer{"foobar"},
398 exp: `"I am a fmt.Stringer"`,
399 },
400 {
401 val: &Tstringer{"foobar"},
402 exp: `"I am a fmt.Stringer"`,
403 },
404 {
405 val: (*Tstringer)(nil),
406 exp: `"<panic: value method github.com/go-logr/logr/funcr.Tstringer.String called using nil *Tstringer pointer>"`,
407 },
408 {
409 val: Tstringerpanic{"foobar"},
410 exp: `"<panic: Tstringerpanic>"`,
411 },
412 {
413 val: Terror{"foobar"},
414 exp: `"I am an error"`,
415 },
416 {
417 val: &Terror{"foobar"},
418 exp: `"I am an error"`,
419 },
420 {
421 val: (*Terror)(nil),
422 exp: `"<panic: value method github.com/go-logr/logr/funcr.Terror.Error called using nil *Terror pointer>"`,
423 },
424 {
425 val: Terrorpanic{"foobar"},
426 exp: `"<panic: Terrorpanic>"`,
427 },
428 {
429 val: TjsontagsString{
430 String1: "v1",
431 String2: "v2",
432 String3: "v3",
433 String4: "v4",
434 String5: "v5",
435 String6: "v6",
436 },
437 },
438 {val: TjsontagsString{}},
439 {
440 val: TjsontagsBool{
441 Bool1: true,
442 Bool2: true,
443 Bool3: true,
444 Bool4: true,
445 Bool5: true,
446 Bool6: true,
447 },
448 },
449 {val: TjsontagsBool{}},
450 {
451 val: TjsontagsInt{
452 Int1: 1,
453 Int2: 2,
454 Int3: 3,
455 Int4: 4,
456 Int5: 5,
457 Int6: 6,
458 },
459 },
460 {val: TjsontagsInt{}},
461 {
462 val: TjsontagsUint{
463 Uint1: 1,
464 Uint2: 2,
465 Uint3: 3,
466 Uint4: 4,
467 Uint5: 5,
468 Uint6: 6,
469 },
470 },
471 {val: TjsontagsUint{}},
472 {
473 val: TjsontagsFloat{
474 Float1: 1.1,
475 Float2: 2.2,
476 Float3: 3.3,
477 Float4: 4.4,
478 Float5: 5.5,
479 Float6: 6.6,
480 },
481 },
482 {val: TjsontagsFloat{}},
483 {
484 val: TjsontagsComplex{
485 Complex1: 1i,
486 Complex2: 2i,
487 Complex3: 3i,
488 Complex4: 4i,
489 Complex5: 5i,
490 Complex6: 6i,
491 },
492 exp: `{"complex1":"(0+1i)","-":"(0+3i)","complex4":"(0+4i)","Complex5":"(0+5i)","Complex6":"(0+6i)"}`,
493 },
494 {
495 val: TjsontagsComplex{},
496 exp: `{"complex1":"(0+0i)","-":"(0+0i)","Complex5":"(0+0i)"}`,
497 },
498 {
499 val: TjsontagsPtr{
500 Ptr1: newStr("1"),
501 Ptr2: newStr("2"),
502 Ptr3: newStr("3"),
503 Ptr4: newStr("4"),
504 Ptr5: newStr("5"),
505 Ptr6: newStr("6"),
506 },
507 },
508 {val: TjsontagsPtr{}},
509 {
510 val: TjsontagsArray{
511 Array1: [2]string{"v1", "v1"},
512 Array2: [2]string{"v2", "v2"},
513 Array3: [2]string{"v3", "v3"},
514 Array4: [2]string{"v4", "v4"},
515 Array5: [2]string{"v5", "v5"},
516 Array6: [2]string{"v6", "v6"},
517 },
518 },
519 {val: TjsontagsArray{}},
520 {
521 val: TjsontagsSlice{
522 Slice1: []string{"v1", "v1"},
523 Slice2: []string{"v2", "v2"},
524 Slice3: []string{"v3", "v3"},
525 Slice4: []string{"v4", "v4"},
526 Slice5: []string{"v5", "v5"},
527 Slice6: []string{"v6", "v6"},
528 },
529 },
530 {
531 val: TjsontagsSlice{},
532 exp: `{"slice1":[],"-":[],"Slice5":[]}`,
533 },
534 {
535 val: TjsontagsMap{
536 Map1: map[string]string{"k1": "v1"},
537 Map2: map[string]string{"k2": "v2"},
538 Map3: map[string]string{"k3": "v3"},
539 Map4: map[string]string{"k4": "v4"},
540 Map5: map[string]string{"k5": "v5"},
541 Map6: map[string]string{"k6": "v6"},
542 },
543 },
544 {
545 val: TjsontagsMap{},
546 exp: `{"map1":{},"-":{},"Map5":{}}`,
547 },
548 {val: Tembedstruct{}},
549 {
550 val: Tembednonstruct{},
551 exp: `{"Tinnerint":0,"Tinnermap":{},"Tinnerslice":[]}`,
552 },
553 {val: Tembedjsontags{}},
554 {
555 val: PseudoStruct(makeKV("f1", 1, "f2", true, "f3", []int{})),
556 exp: `{"f1":1,"f2":true,"f3":[]}`,
557 },
558 {
559 val: map[TjsontagsString]int{
560 {String1: `"quoted"`, String4: `unquoted`}: 1,
561 },
562 exp: `{"{\"string1\":\"\\\"quoted\\\"\",\"-\":\"\",\"string4\":\"unquoted\",\"String5\":\"\"}":1}`,
563 },
564 {
565 val: map[TjsontagsInt]int{
566 {Int1: 1, Int2: 2}: 3,
567 },
568 exp: `{"{\"int1\":1,\"-\":0,\"Int5\":0}":3}`,
569 },
570 {
571 val: map[[2]struct{ S string }]int{
572 {{S: `"quoted"`}, {S: "unquoted"}}: 1,
573 },
574 exp: `{"[{\"S\":\"\\\"quoted\\\"\"},{\"S\":\"unquoted\"}]":1}`,
575 },
576 }
241 }{{
242 val: "strval",
243 }, {
244 val: "strval\nwith\t\"escapes\"",
245 }, {
246 val: substr("substrval"),
247 }, {
248 val: substr("substrval\nwith\t\"escapes\""),
249 }, {
250 val: true,
251 }, {
252 val: false,
253 }, {
254 val: int(93),
255 }, {
256 val: int8(93),
257 }, {
258 val: int16(93),
259 }, {
260 val: int32(93),
261 }, {
262 val: int64(93),
263 }, {
264 val: int(-93),
265 }, {
266 val: int8(-93),
267 }, {
268 val: int16(-93),
269 }, {
270 val: int32(-93),
271 }, {
272 val: int64(-93),
273 }, {
274 val: uint(93),
275 }, {
276 val: uint8(93),
277 }, {
278 val: uint16(93),
279 }, {
280 val: uint32(93),
281 }, {
282 val: uint64(93),
283 }, {
284 val: uintptr(93),
285 }, {
286 val: float32(93.76),
287 }, {
288 val: float64(93.76),
289 }, {
290 val: complex64(93i),
291 exp: `"(0+93i)"`,
292 }, {
293 val: complex128(93i),
294 exp: `"(0+93i)"`,
295 }, {
296 val: ptrint(93),
297 }, {
298 val: ptrstr("pstrval"),
299 }, {
300 val: []int{},
301 }, {
302 val: []int(nil),
303 exp: `[]`,
304 }, {
305 val: []int{9, 3, 7, 6},
306 }, {
307 val: []string{"str", "with\tescape"},
308 }, {
309 val: []substr{"substr", "with\tescape"},
310 }, {
311 val: [4]int{9, 3, 7, 6},
312 }, {
313 val: [2]string{"str", "with\tescape"},
314 }, {
315 val: [2]substr{"substr", "with\tescape"},
316 }, {
317 val: struct {
318 Int int
319 notExported string
320 String string
321 }{
322 93, "you should not see this", "seventy-six",
323 },
324 }, {
325 val: map[string]int{},
326 }, {
327 val: map[string]int(nil),
328 exp: `{}`,
329 }, {
330 val: map[string]int{
331 "nine": 3,
332 },
333 }, {
334 val: map[string]int{
335 "with\tescape": 76,
336 },
337 }, {
338 val: map[substr]int{
339 "nine": 3,
340 },
341 }, {
342 val: map[substr]int{
343 "with\tescape": 76,
344 },
345 }, {
346 val: map[int]int{
347 9: 3,
348 },
349 }, {
350 val: map[float64]int{
351 9.5: 3,
352 },
353 exp: `{"9.5":3}`,
354 }, {
355 val: map[point]int{
356 {x: 1, y: 2}: 3,
357 },
358 }, {
359 val: map[pointErr]int{
360 {x: 1, y: 2}: 3,
361 },
362 exp: `{"<error-MarshalText: uh oh: 1, 2>":3}`,
363 }, {
364 val: struct {
365 X int `json:"x"`
366 Y int `json:"y"`
367 }{
368 93, 76,
369 },
370 }, {
371 val: struct {
372 X []int
373 Y map[int]int
374 Z struct{ P, Q int }
375 }{
376 []int{9, 3, 7, 6},
377 map[int]int{9: 3},
378 struct{ P, Q int }{9, 3},
379 },
380 }, {
381 val: []struct{ X, Y string }{
382 {"nine", "three"},
383 {"seven", "six"},
384 {"with\t", "\tescapes"},
385 },
386 }, {
387 val: struct {
388 A *int
389 B *int
390 C interface{}
391 D interface{}
392 }{
393 B: ptrint(1),
394 D: interface{}(2),
395 },
396 }, {
397 val: Tmarshaler{"foobar"},
398 exp: `{"Inner":"I am a logr.Marshaler"}`,
399 }, {
400 val: &Tmarshaler{"foobar"},
401 exp: `{"Inner":"I am a logr.Marshaler"}`,
402 }, {
403 val: (*Tmarshaler)(nil),
404 exp: `"<panic: value method github.com/go-logr/logr/funcr.Tmarshaler.MarshalLog called using nil *Tmarshaler pointer>"`,
405 }, {
406 val: Tmarshalerpanic{"foobar"},
407 exp: `"<panic: Tmarshalerpanic>"`,
408 }, {
409 val: Tstringer{"foobar"},
410 exp: `"I am a fmt.Stringer"`,
411 }, {
412 val: &Tstringer{"foobar"},
413 exp: `"I am a fmt.Stringer"`,
414 }, {
415 val: (*Tstringer)(nil),
416 exp: `"<panic: value method github.com/go-logr/logr/funcr.Tstringer.String called using nil *Tstringer pointer>"`,
417 }, {
418 val: Tstringerpanic{"foobar"},
419 exp: `"<panic: Tstringerpanic>"`,
420 }, {
421 val: Terror{"foobar"},
422 exp: `"I am an error"`,
423 }, {
424 val: &Terror{"foobar"},
425 exp: `"I am an error"`,
426 }, {
427 val: (*Terror)(nil),
428 exp: `"<panic: value method github.com/go-logr/logr/funcr.Terror.Error called using nil *Terror pointer>"`,
429 }, {
430 val: Terrorpanic{"foobar"},
431 exp: `"<panic: Terrorpanic>"`,
432 }, {
433 val: TjsontagsString{
434 String1: "v1",
435 String2: "v2",
436 String3: "v3",
437 String4: "v4",
438 String5: "v5",
439 String6: "v6",
440 },
441 }, {
442 val: TjsontagsString{},
443 }, {
444 val: TjsontagsBool{
445 Bool1: true,
446 Bool2: true,
447 Bool3: true,
448 Bool4: true,
449 Bool5: true,
450 Bool6: true,
451 },
452 }, {
453 val: TjsontagsBool{},
454 }, {
455 val: TjsontagsInt{
456 Int1: 1,
457 Int2: 2,
458 Int3: 3,
459 Int4: 4,
460 Int5: 5,
461 Int6: 6,
462 },
463 }, {
464 val: TjsontagsInt{},
465 }, {
466 val: TjsontagsUint{
467 Uint1: 1,
468 Uint2: 2,
469 Uint3: 3,
470 Uint4: 4,
471 Uint5: 5,
472 Uint6: 6,
473 },
474 }, {
475 val: TjsontagsUint{},
476 }, {
477 val: TjsontagsFloat{
478 Float1: 1.1,
479 Float2: 2.2,
480 Float3: 3.3,
481 Float4: 4.4,
482 Float5: 5.5,
483 Float6: 6.6,
484 },
485 }, {
486 val: TjsontagsFloat{},
487 }, {
488 val: TjsontagsComplex{
489 Complex1: 1i,
490 Complex2: 2i,
491 Complex3: 3i,
492 Complex4: 4i,
493 Complex5: 5i,
494 Complex6: 6i,
495 },
496 exp: `{"complex1":"(0+1i)","-":"(0+3i)","complex4":"(0+4i)","Complex5":"(0+5i)","Complex6":"(0+6i)"}`,
497 }, {
498 val: TjsontagsComplex{},
499 exp: `{"complex1":"(0+0i)","-":"(0+0i)","Complex5":"(0+0i)"}`,
500 }, {
501 val: TjsontagsPtr{
502 Ptr1: newStr("1"),
503 Ptr2: newStr("2"),
504 Ptr3: newStr("3"),
505 Ptr4: newStr("4"),
506 Ptr5: newStr("5"),
507 Ptr6: newStr("6"),
508 },
509 }, {
510 val: TjsontagsPtr{},
511 }, {
512 val: TjsontagsArray{
513 Array1: [2]string{"v1", "v1"},
514 Array2: [2]string{"v2", "v2"},
515 Array3: [2]string{"v3", "v3"},
516 Array4: [2]string{"v4", "v4"},
517 Array5: [2]string{"v5", "v5"},
518 Array6: [2]string{"v6", "v6"},
519 },
520 }, {
521 val: TjsontagsArray{},
522 }, {
523 val: TjsontagsSlice{
524 Slice1: []string{"v1", "v1"},
525 Slice2: []string{"v2", "v2"},
526 Slice3: []string{"v3", "v3"},
527 Slice4: []string{"v4", "v4"},
528 Slice5: []string{"v5", "v5"},
529 Slice6: []string{"v6", "v6"},
530 },
531 }, {
532 val: TjsontagsSlice{},
533 exp: `{"slice1":[],"-":[],"Slice5":[]}`,
534 }, {
535 val: TjsontagsMap{
536 Map1: map[string]string{"k1": "v1"},
537 Map2: map[string]string{"k2": "v2"},
538 Map3: map[string]string{"k3": "v3"},
539 Map4: map[string]string{"k4": "v4"},
540 Map5: map[string]string{"k5": "v5"},
541 Map6: map[string]string{"k6": "v6"},
542 },
543 }, {
544 val: TjsontagsMap{},
545 exp: `{"map1":{},"-":{},"Map5":{}}`,
546 }, {
547 val: Tembedstruct{},
548 }, {
549 val: Tembednonstruct{},
550 exp: `{"Tinnerint":0,"Tinnermap":{},"Tinnerslice":[]}`,
551 }, {
552 val: Tembedjsontags{},
553 }, {
554 val: PseudoStruct(makeKV("f1", 1, "f2", true, "f3", []int{})),
555 exp: `{"f1":1,"f2":true,"f3":[]}`,
556 }, {
557 val: map[TjsontagsString]int{
558 {String1: `"quoted"`, String4: `unquoted`}: 1,
559 },
560 exp: `{"{\"string1\":\"\\\"quoted\\\"\",\"-\":\"\",\"string4\":\"unquoted\",\"String5\":\"\"}":1}`,
561 }, {
562 val: map[TjsontagsInt]int{
563 {Int1: 1, Int2: 2}: 3,
564 },
565 exp: `{"{\"int1\":1,\"-\":0,\"Int5\":0}":3}`,
566 }, {
567 val: map[[2]struct{ S string }]int{
568 {{S: `"quoted"`}, {S: "unquoted"}}: 1,
569 },
570 exp: `{"[{\"S\":\"\\\"quoted\\\"\"},{\"S\":\"unquoted\"}]":1}`,
571 }}
577572
578573 f := NewFormatter(Options{})
579574 for i, tc := range cases {