MCPcopy
hub / github.com/expr-lang/expr / addStructFormatterTests

Function addStructFormatterTests

internal/spew/format_test.go:886–1034  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

884}
885
886func addStructFormatterTests() {
887 // Struct with primitives.
888 type s1 struct {
889 a int8
890 b uint8
891 }
892 v := s1{127, 255}
893 nv := (*s1)(nil)
894 pv := &v
895 vAddr := fmt.Sprintf("%p", pv)
896 pvAddr := fmt.Sprintf("%p", &pv)
897 vt := "spew_test.s1"
898 vt2 := "int8"
899 vt3 := "uint8"
900 vs := "{127 255}"
901 vs2 := "{a:127 b:255}"
902 vs3 := "{a:(" + vt2 + ")127 b:(" + vt3 + ")255}"
903 addFormatterTest("%v", v, vs)
904 addFormatterTest("%v", pv, "<*>"+vs)
905 addFormatterTest("%v", &pv, "<**>"+vs)
906 addFormatterTest("%+v", nv, "<nil>")
907 addFormatterTest("%+v", v, vs2)
908 addFormatterTest("%+v", pv, "<*>("+vAddr+")"+vs2)
909 addFormatterTest("%+v", &pv, "<**>("+pvAddr+"->"+vAddr+")"+vs2)
910 addFormatterTest("%+v", nv, "<nil>")
911 addFormatterTest("%#v", v, "("+vt+")"+vs3)
912 addFormatterTest("%#v", pv, "(*"+vt+")"+vs3)
913 addFormatterTest("%#v", &pv, "(**"+vt+")"+vs3)
914 addFormatterTest("%#v", nv, "(*"+vt+")"+"<nil>")
915 addFormatterTest("%#+v", v, "("+vt+")"+vs3)
916 addFormatterTest("%#+v", pv, "(*"+vt+")("+vAddr+")"+vs3)
917 addFormatterTest("%#+v", &pv, "(**"+vt+")("+pvAddr+"->"+vAddr+")"+vs3)
918 addFormatterTest("%#+v", nv, "(*"+vt+")"+"<nil>")
919
920 // Struct that contains another struct.
921 type s2 struct {
922 s1 s1
923 b bool
924 }
925 v2 := s2{s1{127, 255}, true}
926 nv2 := (*s2)(nil)
927 pv2 := &v2
928 v2Addr := fmt.Sprintf("%p", pv2)
929 pv2Addr := fmt.Sprintf("%p", &pv2)
930 v2t := "spew_test.s2"
931 v2t2 := "spew_test.s1"
932 v2t3 := "int8"
933 v2t4 := "uint8"
934 v2t5 := "bool"
935 v2s := "{{127 255} true}"
936 v2s2 := "{s1:{a:127 b:255} b:true}"
937 v2s3 := "{s1:(" + v2t2 + "){a:(" + v2t3 + ")127 b:(" + v2t4 + ")255} b:(" +
938 v2t5 + ")true}"
939 addFormatterTest("%v", v2, v2s)
940 addFormatterTest("%v", pv2, "<*>"+v2s)
941 addFormatterTest("%v", &pv2, "<**>"+v2s)
942 addFormatterTest("%+v", nv2, "<nil>")
943 addFormatterTest("%+v", v2, v2s2)

Callers 1

TestFormatterFunction · 0.85

Calls 2

addFormatterTestFunction · 0.85
SprintfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…