]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typealias] cmd/doc: update for type alias
authorRuss Cox <rsc@golang.org>
Tue, 24 Jan 2017 19:53:31 +0000 (14:53 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 25 Jan 2017 17:27:07 +0000 (17:27 +0000)
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>
src/cmd/doc/doc_test.go
src/cmd/doc/pkg.go
src/cmd/doc/testdata/pkg.go

index 1c054fd566a0a3683ddbf86c56e833821a23580f..1244476ab2f18b05b04b6e4a54e178011696681e 100644 (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",
index daa6ed358cdce0e2234421532cc7eb9753e97c1c..32d08f21fd04a33d4136a3f30e7355cd1fc5b8a7 100644 (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
index 924daa171b259a38aa7f12523a85e4262b18d822..0ebea67d58e50a942b2dc371f7c78b04cc78498c 100644 (file)
@@ -172,3 +172,7 @@ const (
 )
 
 const ConstGroup4 ExportedType = ExportedType{}
+
+type T2 int
+
+type T1 = T2