`VarFive = 5`, // From block starting with unexported variable.
`type unexportedType`, // No unexported type.
`unexportedTypedConstant`, // No unexported typed constant.
- `Field`, // No fields.
+ `\bField`, // No fields.
`Method`, // No methods.
`someArgument[5-8]`, // No truncated arguments.
`type T1 T2`, // Type alias does not display as type declaration.
"field",
[]string{p, `ExportedType.ExportedField`},
[]string{
+ `type ExportedType struct`,
`ExportedField int`,
`Comment before exported field.`,
`Comment on line with exported field.`,
+ `other fields elided`,
},
nil,
},
- // Field with -u.
+ // Field with -u.
{
"method with -u",
[]string{"-u", p, `ExportedType.unexportedField`},
nil,
},
+ // Field of struct with only one field.
+ {
+ "single-field struct",
+ []string{p, `ExportedStructOneField.OnlyField`},
+ []string{`the only field`},
+ []string{`other fields elided`},
+ },
+
// Case matching off.
{
"case matching off",
pkg.Fatalf("symbol %s is not a type in package %s installed in %q", symbol, pkg.name, pkg.build.ImportPath)
}
found := false
+ numUnmatched := 0
for _, typ := range types {
// Type must be a struct.
spec := pkg.findTypeSpec(typ.Decl, typ.Name)
for _, field := range structType.Fields.List {
// TODO: Anonymous fields.
for _, name := range field.Names {
- if match(fieldName, name.Name) {
- if !found {
- pkg.Printf("struct %s {\n", typ.Name)
- }
- if field.Doc != nil {
- for _, comment := range field.Doc.List {
- doc.ToText(&pkg.buf, comment.Text, indent, indent, indentedWidth)
- }
- }
- s := pkg.oneLineNode(field.Type)
- lineComment := ""
- if field.Comment != nil {
- lineComment = fmt.Sprintf(" %s", field.Comment.List[0].Text)
+ if !match(fieldName, name.Name) {
+ numUnmatched++
+ continue
+ }
+ if !found {
+ pkg.Printf("type %s struct {\n", typ.Name)
+ }
+ if field.Doc != nil {
+ for _, comment := range field.Doc.List {
+ doc.ToText(&pkg.buf, comment.Text, indent, indent, indentedWidth)
}
- pkg.Printf("%s%s %s%s\n", indent, name, s, lineComment)
- found = true
}
+ s := pkg.oneLineNode(field.Type)
+ lineComment := ""
+ if field.Comment != nil {
+ lineComment = fmt.Sprintf(" %s", field.Comment.List[0].Text)
+ }
+ pkg.Printf("%s%s %s%s\n", indent, name, s, lineComment)
+ found = true
}
}
}
if found {
+ if numUnmatched > 0 {
+ pkg.Printf("\n // ... other fields elided ...\n")
+ }
pkg.Printf("}\n")
}
return found