@@ -48,13 +48,29 @@ var (
4848 "RateLimits" : true ,
4949 }
5050
51+ // namedStructZeroStr maps named struct type names to their Stringify output
52+ // when zero-valued, for structs whose zero value is not simply "{}".
53+ // Stringify always prints non-pointer value fields (ints, strings, etc.) but
54+ // skips nil pointers/slices/maps, so only structs containing non-pointer
55+ // value fields need an entry here.
56+ namedStructZeroStr = map [string ]string {
57+ "IssueDependenciesSummary" : `github.IssueDependenciesSummary{BlockedBy:0, Blocking:0, TotalBlockedBy:0, TotalBlocking:0}` ,
58+ "SubIssuesSummary" : `github.SubIssuesSummary{Total:0, Completed:0, PercentCompleted:0}` ,
59+ }
60+
5161 funcMap = template.FuncMap {
5262 "isNotLast" : func (index int , slice []* structField ) string {
5363 if index + 1 < len (slice ) {
5464 return ", "
5565 }
5666 return ""
5767 },
68+ "namedStructStr" : func (pkg , fieldType string ) string {
69+ if s , ok := namedStructZeroStr [fieldType ]; ok {
70+ return s
71+ }
72+ return fmt .Sprintf ("%s.%s{}" , pkg , fieldType )
73+ },
5874 "processZeroValue" : func (v string ) string {
5975 switch v {
6076 case "Ptr(false)" :
@@ -435,7 +451,7 @@ func Test{{ $key }}_String(t *testing.T) {
435451 {{ .FieldName }}: {{.ZeroValue}},{{end}}{{end}}
436452 }
437453 want := ` + "`" + `{{ $package }}.{{ $key }}{{ $slice := . }}{
438- {{- range $ind, $val := .}}{{if .NamedStruct}}{{ .FieldName }}:{{ $package }}.{{ . FieldType }}{ }{{else}}{{ .FieldName }}:{{ processZeroValue .ZeroValue }}{{end}}{{ isNotLast $ind $slice }}{{end}}}` + "`" + `
454+ {{- range $ind, $val := .}}{{if .NamedStruct}}{{ .FieldName }}:{{ namedStructStr $package . FieldType }}{{else}}{{ .FieldName }}:{{ processZeroValue .ZeroValue }}{{end}}{{ isNotLast $ind $slice }}{{end}}}` + "`" + `
439455 if got := v.String(); got != want {
440456 t.Errorf("{{ $key }}.String = %v, want %v", got, want)
441457 }
0 commit comments