1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This is a package for testing comment placement by go/printer.
17 // Alignment of comments in declarations>
47 // The SZ struct; it is empty.
50 // The S0 struct; no field is exported.
53 x, y, z int // 3 unexported fields
56 // The S1 struct; some fields are not exported.
59 A, B, C float // 3 exported fields
60 D, b, c int // 2 unexported fields
63 // The S2 struct; all fields are exported.
66 A, B, C float // 3 exported fields
69 // The IZ interface; it is empty.
72 // The I0 interface; no method is exported.
74 f(x int) int // unexported method
77 // The I1 interface; some methods are not exported.
80 F(x float) float // exported methods
81 g(x int) int // unexported method
84 // The I2 interface; all methods are exported.
87 F(x float) float // exported method
88 G(x float) float // exported method
91 // The S3 struct; all comments except for the last one must appear in the export.
93 // lead comment for F1
94 F1 int // line comment for F1
95 // lead comment for F2
96 F2 int // line comment for F2
97 f3 int // f3 is not exported
100 // This comment group should be separated
101 // with a newline from the next comment
104 // This comment should NOT be associated with the next declaration.
110 // This comment SHOULD be associated with the next declaration.
112 const pi = 3.14 // pi
113 var s1 struct{} /* an empty struct */ /* foo */
114 // a struct constructor
115 // --------------------
116 var s2 struct{} = struct{}{}
133 // this comment should be properly indented
138 if x < 0 { // the tab printed before this comment's // must not affect the remaining lines
139 return -x // this statement should be properly indented
141 if x < 0 { /* the tab printed before this comment's /* must not affect the remaining lines */
142 return -x // this statement should be properly indented
148 func typeswitch(x interface{}) {
149 switch v := x.(type) {
150 case bool, int, float:
158 switch v0, ok := x.(int); v := x.(type) {
161 switch v0, ok := x.(int); x.(type) {
162 case byte: // this comment should be on the same line as the keyword
163 // this comment should be normally indented
165 case bool, int, float:
166 // this comment should be indented
169 // this comment should be indented
171 // this comment should not be indented
175 /* freestanding comment
182 /* freestanding comment
189 /* freestanding comment
195 /* freestanding comment
202 /* freestanding comment
209 /* freestanding comment
262 /* freestanding comment
268 /* freestanding comment
274 /* freestanding comment
279 /* freestanding comment
285 /* freestanding comment
291 /* freestanding comment
353 /* and another line of
359 /* and another line of
365 /* and another line of
375 blank line in middle:
377 with no leading spaces on blank line.
387 blank line in middle:
389 with no leading spaces on blank line.
406 blank line in middle:
408 with no leading spaces on blank line.
413 // Some interesting interspersed comments
414 func _( /* this */ x /* is */ /* an */ int) {
417 func _( /* no params */ ) {}
423 func ( /* comment1 */ T /* comment2 */ ) _() {}
425 func _() { /* one-liner */
430 /* closing curly brace should be on new line */
434 // Comments immediately adjacent to punctuation (for which the go/printer
435 // may obly have estimated position information) must remain after the punctuation.
438 1, // comment after comma
439 2, /* comment after comma */
440 3, // comment after comma
443 1, // comment after comma
444 2, /* comment after comma */
445 3, // comment after comma
448 /* comment before literal */ 1,
449 2, /* comment before comma - ok to move after comma */
450 3, /* comment before comma - ok to move after comma */
453 for i = 0; // comment after semicolon
454 i < 9; /* comment after semicolon */
455 i++ { // comment after opening curly brace
458 // TODO(gri) the last comment in this example should be aligned */
459 for i = 0; // comment after semicolon
460 i < 9; /* comment before semicolon - ok to move after semicolon */
461 i++ /* comment before opening curly brace */ {
466 // Line comments with tabs
468 var finput *bufio.Reader // input file
469 var stderr *bufio.Writer
470 var ftable *bufio.Writer // y.go file
471 var foutput *bufio.Writer // y.output file
473 var oflag string // -o [y.go] - y.go file
474 var vflag string // -v [y.output] - y.output file
475 var lflag bool // -l - disable line directives
479 /* This comment is the last entry in this file. It must be printed and should be followed by a newline */