mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
de2e5459ae
commit
9657e0b077
3 changed files with 23 additions and 1 deletions
|
|
@ -71,6 +71,7 @@ var tests = []test{
|
||||||
`const MultiLineConst = ...`, // Multi line constant.
|
`const MultiLineConst = ...`, // Multi line constant.
|
||||||
`var MultiLineVar = map\[struct{ ... }\]struct{ ... }{ ... }`, // Multi line variable.
|
`var MultiLineVar = map\[struct{ ... }\]struct{ ... }{ ... }`, // Multi line variable.
|
||||||
`func MultiLineFunc\(x interface{ ... }\) \(r struct{ ... }\)`, // Multi line function.
|
`func MultiLineFunc\(x interface{ ... }\) \(r struct{ ... }\)`, // Multi line function.
|
||||||
|
`type T1 = T2`, // Type alias
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
`const internalConstant = 2`, // No internal constants.
|
`const internalConstant = 2`, // No internal constants.
|
||||||
|
|
@ -89,6 +90,7 @@ var tests = []test{
|
||||||
`unexportedTypedConstant`, // No unexported typed constant.
|
`unexportedTypedConstant`, // No unexported typed constant.
|
||||||
`Field`, // No fields.
|
`Field`, // No fields.
|
||||||
`Method`, // No methods.
|
`Method`, // No methods.
|
||||||
|
`type T1 T2`, // Type alias does not display as type declaration.
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Package dump -u
|
// Package dump -u
|
||||||
|
|
@ -265,6 +267,18 @@ var tests = []test{
|
||||||
`error`, // No embedded error.
|
`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 -u with unexported fields.
|
||||||
{
|
{
|
||||||
"type with unexported fields and -u",
|
"type with unexported fields and -u",
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,11 @@ func (pkg *Package) oneLineNodeDepth(node ast.Node, depth int) string {
|
||||||
return fmt.Sprintf("func %s%s%s", recv, name, fnc)
|
return fmt.Sprintf("func %s%s%s", recv, name, fnc)
|
||||||
|
|
||||||
case *ast.TypeSpec:
|
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:
|
case *ast.FuncType:
|
||||||
var params []string
|
var params []string
|
||||||
|
|
|
||||||
4
src/cmd/doc/testdata/pkg.go
vendored
4
src/cmd/doc/testdata/pkg.go
vendored
|
|
@ -172,3 +172,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
const ConstGroup4 ExportedType = ExportedType{}
|
const ConstGroup4 ExportedType = ExportedType{}
|
||||||
|
|
||||||
|
type T2 int
|
||||||
|
|
||||||
|
type T1 = T2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue