[]string{
`Comment about exported type`, // Include comment.
`type ExportedType struct`, // Type definition.
- `Comment before exported field.*\n.*ExportedField +int`,
+ `Comment before exported field.*\n.*ExportedField +int` +
+ `.*Comment on line with exported field.`,
`Has unexported fields`,
`func \(ExportedType\) ExportedMethod\(a int\) bool`,
`const ExportedTypedConstant ExportedType = iota`, // Must include associated constant.
nil,
},
+ // Interface.
+ {
+ "type",
+ []string{p, `ExportedInterface`},
+ []string{
+ `Comment about exported interface`, // Include comment.
+ `type ExportedInterface interface`, // Interface definition.
+ `Comment before exported method.*\n.*ExportedMethod\(\)` +
+ `.*Comment on line with exported method`,
+ `Has unexported methods`,
+ },
+ []string{
+ `unexportedField`, // No unexported field.
+ `Comment about exported method`, // No comment about exported method.
+ `unexportedMethod`, // No unexported method.
+ `unexportedTypedConstant`, // No unexported constant.
+ },
+ },
+ // Interface -u with unexported methods.
+ {
+ "type with unexported methods and -u",
+ []string{"-u", p, `ExportedInterface`},
+ []string{
+ `Comment about exported interface`, // Include comment.
+ `type ExportedInterface interface`, // Interface definition.
+ `Comment before exported method.*\n.*ExportedMethod\(\)` +
+ `.*Comment on line with exported method`,
+ `unexportedMethod\(\).*Comment on line with unexported method.`,
+ },
+ []string{
+ `Has unexported methods`,
+ },
+ },
+
// Method.
{
"method",
return fields
}
unexportedField := &ast.Field{
- Type: ast.NewIdent(""), // Hack: printer will treat this as a field with a named type.
+ Type: &ast.Ident{
+ // Hack: printer will treat this as a field with a named type.
+ // Setting Name and NamePos to ("", fields.Closing-1) ensures that
+ // when Pos and End are called on this field, they return the
+ // position right before closing '}' character.
+ Name: "",
+ NamePos: fields.Closing - 1,
+ },
Comment: &ast.CommentGroup{
List: []*ast.Comment{{Text: fmt.Sprintf("// Has unexported %s.\n", what)}},
},
// Comment about exported type.
type ExportedType struct {
// Comment before exported field.
- ExportedField int
+ ExportedField int // Comment on line with exported field.
unexportedField int // Comment on line with unexported field.
}
const unexportedTypedConstant ExportedType = 1 // In a separate section to test -u.
+// Comment about exported interface.
+type ExportedInterface interface {
+ // Comment before exported method.
+ ExportedMethod() // Comment on line with exported method.
+ unexportedMethod() // Comment on line with unexported method.
+}
+
// Comment about unexported type.
type unexportedType int