MCPcopy Create free account
hub / github.com/expr-lang/expr / addStructDumpTests

Function addStructDumpTests

internal/spew/dump_test.go:651–740  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

649}
650
651func addStructDumpTests() {
652 // Struct with primitives.
653 type s1 struct {
654 a int8
655 b uint8
656 }
657 v := s1{127, 255}
658 nv := (*s1)(nil)
659 pv := &v
660 vAddr := fmt.Sprintf("%p", pv)
661 pvAddr := fmt.Sprintf("%p", &pv)
662 vt := "spew_test.s1"
663 vt2 := "int8"
664 vt3 := "uint8"
665 vs := "{\n a: (" + vt2 + ") 127,\n b: (" + vt3 + ") 255\n}"
666 addDumpTest(v, "("+vt+") "+vs+"\n")
667 addDumpTest(pv, "(*"+vt+")("+vAddr+")("+vs+")\n")
668 addDumpTest(&pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")("+vs+")\n")
669 addDumpTest(nv, "(*"+vt+")(<nil>)\n")
670
671 // Struct that contains another struct.
672 type s2 struct {
673 s1 s1
674 b bool
675 }
676 v2 := s2{s1{127, 255}, true}
677 nv2 := (*s2)(nil)
678 pv2 := &v2
679 v2Addr := fmt.Sprintf("%p", pv2)
680 pv2Addr := fmt.Sprintf("%p", &pv2)
681 v2t := "spew_test.s2"
682 v2t2 := "spew_test.s1"
683 v2t3 := "int8"
684 v2t4 := "uint8"
685 v2t5 := "bool"
686 v2s := "{\n s1: (" + v2t2 + ") {\n a: (" + v2t3 + ") 127,\n b: (" +
687 v2t4 + ") 255\n },\n b: (" + v2t5 + ") true\n}"
688 addDumpTest(v2, "("+v2t+") "+v2s+"\n")
689 addDumpTest(pv2, "(*"+v2t+")("+v2Addr+")("+v2s+")\n")
690 addDumpTest(&pv2, "(**"+v2t+")("+pv2Addr+"->"+v2Addr+")("+v2s+")\n")
691 addDumpTest(nv2, "(*"+v2t+")(<nil>)\n")
692
693 // Struct that contains custom type with Stringer pointer interface via both
694 // exported and unexported fields.
695 type s3 struct {
696 s pstringer
697 S pstringer
698 }
699 v3 := s3{"test", "test2"}
700 nv3 := (*s3)(nil)
701 pv3 := &v3
702 v3Addr := fmt.Sprintf("%p", pv3)
703 pv3Addr := fmt.Sprintf("%p", &pv3)
704 v3t := "spew_test.s3"
705 v3t2 := "spew_test.pstringer"
706 v3s := "{\n s: (" + v3t2 + ") (len=4) stringer test,\n S: (" + v3t2 +
707 ") (len=5) stringer test2\n}"
708 v3sp := v3s

Callers 1

TestDumpFunction · 0.85

Calls 2

addDumpTestFunction · 0.85
SprintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…