Skip to content

Commit ed9d275

Browse files
committed
fix tests
1 parent f207870 commit ed9d275

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

github/gen-stringify-test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

github/github-stringify_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)