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-line functions with comments are formatted as multi-line functions */ }
429 /* closing curly brace should be on new line */ }
432 _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */}
436 // Comments immediately adjacent to punctuation (for which the go/printer
437 // may obly have estimated position information) must remain after the punctuation.
440 1, // comment after comma
441 2, /* comment after comma */
442 3 , // comment after comma
445 1 ,// comment after comma
446 2 ,/* comment after comma */
447 3,// comment after comma
450 /* comment before literal */1,
451 2/* comment before comma - ok to move after comma */,
452 3 /* comment before comma - ok to move after comma */ ,
456 i=0;// comment after semicolon
457 i<9;/* comment after semicolon */
458 i++{// comment after opening curly brace
461 // TODO(gri) the last comment in this example should be aligned */
463 i=0;// comment after semicolon
464 i<9/* comment before semicolon - ok to move after semicolon */;
465 i++ /* comment before opening curly brace */ {
470 // Line comments with tabs
472 var finput *bufio.Reader // input file
473 var stderr *bufio.Writer
474 var ftable *bufio.Writer // y.go file
475 var foutput *bufio.Writer // y.output file
477 var oflag string // -o [y.go] - y.go file
478 var vflag string // -v [y.output] - y.output file
479 var lflag bool // -l - disable line directives
483 /* This comment is the last entry in this file. It must be printed and should be followed by a newline */