1
0
mirror of https://github.com/golang/go synced 2024-11-11 23:40:22 -07:00

[dev.typealias] cmd/doc: update for type alias

For #18130.

Change-Id: I06b05a2b45a2aa6764053fc51e05883063572dad
Reviewed-on: https://go-review.googlesource.com/35670
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Russ Cox 2017-01-24 14:53:31 -05:00
parent de2e5459ae
commit 9657e0b077
3 changed files with 23 additions and 1 deletions

View File

@ -71,6 +71,7 @@ var tests = []test{
`const MultiLineConst = ...`, // Multi line constant.
`var MultiLineVar = map\[struct{ ... }\]struct{ ... }{ ... }`, // Multi line variable.
`func MultiLineFunc\(x interface{ ... }\) \(r struct{ ... }\)`, // Multi line function.
`type T1 = T2`, // Type alias
},
[]string{
`const internalConstant = 2`, // No internal constants.
@ -89,6 +90,7 @@ var tests = []test{
`unexportedTypedConstant`, // No unexported typed constant.
`Field`, // No fields.
`Method`, // No methods.
`type T1 T2`, // Type alias does not display as type declaration.
},
},
// Package dump -u
@ -265,6 +267,18 @@ var tests = []test{
`error`, // No embedded error.
},
},
// Type T1 dump (alias).
{
"type T1",
[]string{p+".T1"},
[]string{
`type T1 = T2`,
},
[]string{
`type T1 T2`,
`type ExportedType`,
},
},
// Type -u with unexported fields.
{
"type with unexported fields and -u",

View File

@ -258,7 +258,11 @@ func (pkg *Package) oneLineNodeDepth(node ast.Node, depth int) string {
return fmt.Sprintf("func %s%s%s", recv, name, fnc)
case *ast.TypeSpec:
return fmt.Sprintf("type %s %s", n.Name.Name, pkg.oneLineNodeDepth(n.Type, depth))
sep := " "
if n.Assign.IsValid() {
sep = " = "
}
return fmt.Sprintf("type %s%s%s", n.Name.Name, sep, pkg.oneLineNodeDepth(n.Type, depth))
case *ast.FuncType:
var params []string

View File

@ -172,3 +172,7 @@ const (
)
const ConstGroup4 ExportedType = ExportedType{}
type T2 int
type T1 = T2