OSDN Git Service

7b332252c4ec0ad26ca17930c92d6fc0f5ab19f3
[pf3gnuchains/gcc-fork.git] / libgo / go / go / printer / testdata / comments.golden
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.
4
5 // This is a package for testing comment placement by go/printer.
6 //
7 package main
8
9 import "fmt"    // fmt
10
11 const c0 = 0    // zero
12 const (
13         c1      = iota  // c1
14         c2              // c2
15 )
16
17 // Alignment of comments in declarations>
18 const (
19         _       T       = iota  // comment
20         _                       // comment
21         _                       // comment
22         _       = iota + 10
23         _       // comments
24
25         _               = 10    // comment
26         _       T       = 20    // comment
27 )
28
29 const (
30         _____   = iota  // foo
31         _               // bar
32         _       = 0     // bal
33         _               // bat
34 )
35
36 const (
37         _       T       = iota  // comment
38         _                       // comment
39         _                       // comment
40         _       = iota + 10
41         _               // comment
42         _               = 10
43         _               = 20    // comment
44         _       T       = 0     // comment
45 )
46
47 // The SZ struct; it is empty.
48 type SZ struct{}
49
50 // The S0 struct; no field is exported.
51 type S0 struct {
52         int
53         x, y, z int     // 3 unexported fields
54 }
55
56 // The S1 struct; some fields are not exported.
57 type S1 struct {
58         S0
59         A, B, C float   // 3 exported fields
60         D, b, c int     // 2 unexported fields
61 }
62
63 // The S2 struct; all fields are exported.
64 type S2 struct {
65         S1
66         A, B, C float   // 3 exported fields
67 }
68
69 // The IZ interface; it is empty.
70 type SZ interface{}
71
72 // The I0 interface; no method is exported.
73 type I0 interface {
74         f(x int) int    // unexported method
75 }
76
77 // The I1 interface; some methods are not exported.
78 type I1 interface {
79         I0
80         F(x float) float        // exported methods
81         g(x int) int            // unexported method
82 }
83
84 // The I2 interface; all methods are exported.
85 type I2 interface {
86         I0
87         F(x float) float        // exported method
88         G(x float) float        // exported method
89 }
90
91 // The S3 struct; all comments except for the last one must appear in the export.
92 type S3 struct {
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
98 }
99
100 // This comment group should be separated
101 // with a newline from the next comment
102 // group.
103
104 // This comment should NOT be associated with the next declaration.
105
106 var x int       // x
107 var ()
108
109 // This comment SHOULD be associated with the next declaration.
110 func f0() {
111         const pi = 3.14 // pi
112         var s1 struct{} /* an empty struct */   /* foo */
113         // a struct constructor
114         // --------------------
115         var s2 struct{} = struct{}{}
116         x := pi
117 }
118 //
119 // NO SPACE HERE
120 //
121 func f1() {
122         f0()
123         /* 1 */
124         // 2
125         /* 3 */
126         /* 4 */
127         f0()
128 }
129
130 func _() {
131         // this comment should be properly indented
132 }
133
134 func _(x int) int {
135         if x < 0 {      // the tab printed before this comment's // must not affect the remaining lines
136                 return -x       // this statement should be properly indented
137         }
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
140         }
141         return x
142 }
143
144 func typeswitch(x interface{}) {
145         switch v := x.(type) {
146         case bool, int, float:
147         case string:
148         default:
149         }
150
151         switch x.(type) {
152         }
153
154         switch v0, ok := x.(int); v := x.(type) {
155         }
156
157         switch v0, ok := x.(int); x.(type) {
158         case byte:      // this comment should be on the same line as the keyword
159                 // this comment should be normally indented
160                 _ = 0
161         case bool, int, float:
162                 // this comment should be indented
163         case string:
164         default:
165                 // this comment should be indented
166         }
167         // this comment should not be indented
168 }
169
170 func _() {
171         /* freestanding comment
172            aligned              line
173            aligned line
174         */
175 }
176
177 func _() {
178         /* freestanding comment
179            aligned              line
180            aligned line
181         */
182 }
183
184 func _() {
185         /* freestanding comment
186            aligned              line
187            aligned line */
188 }
189
190 func _() {
191         /*      freestanding comment
192                 aligned         line
193                 aligned line
194         */
195 }
196
197 func _() {
198         /*      freestanding comment
199                 aligned         line
200                 aligned line
201         */
202 }
203
204 func _() {
205         /*      freestanding comment
206                 aligned         line
207                 aligned line */
208 }
209
210 func _() {
211         /*
212            freestanding comment
213            aligned              line
214            aligned line
215         */
216 }
217
218 func _() {
219         /*
220            freestanding comment
221            aligned              line
222            aligned line
223         */
224 }
225
226 func _() {
227         /*
228            freestanding comment
229            aligned              line
230            aligned line */
231 }
232
233 func _() {
234         /*
235                 freestanding comment
236                 aligned         line
237                 aligned line
238         */
239 }
240
241 func _() {
242         /*
243                 freestanding comment
244                 aligned         line
245                 aligned line
246         */
247 }
248
249 func _() {
250         /*
251                 freestanding comment
252                 aligned         line
253                 aligned line */
254 }
255
256 func _() {
257         /* freestanding comment
258            aligned line
259         */
260 }
261
262 func _() {
263         /* freestanding comment
264            aligned line
265         */
266 }
267
268 func _() {
269         /* freestanding comment
270            aligned line */
271 }
272
273 func _() {
274         /*      freestanding comment
275                 aligned line
276         */
277 }
278
279 func _() {
280         /*      freestanding comment
281                 aligned line
282         */
283 }
284
285 func _() {
286         /*      freestanding comment
287                 aligned line */
288 }
289
290 func _() {
291         /*
292            freestanding comment
293            aligned line
294         */
295 }
296
297 func _() {
298         /*
299            freestanding comment
300            aligned line
301         */
302 }
303
304 func _() {
305         /*
306            freestanding comment
307            aligned line */
308 }
309
310 func _() {
311         /*
312                 freestanding comment
313                 aligned line
314         */
315 }
316
317 func _() {
318         /*
319                 freestanding comment
320                 aligned line
321         */
322 }
323
324 func _() {
325         /*
326                 freestanding comment
327                 aligned line */
328 }
329
330 /*
331  * line
332  * of
333  * stars
334  */
335
336 /* another line
337  * of
338  * stars */
339
340 /*      and another line
341  *      of
342  *      stars */
343
344 /* a line of
345  * stars */
346
347 /*      and another line of
348  *      stars */
349
350 /* a line of stars
351  */
352
353 /*      and another line of
354  */
355
356 /* a line of stars
357  */
358
359 /*      and another line of
360  */
361
362 /*
363 aligned in middle
364 here
365         not here
366 */
367
368 /*
369 blank line in middle:
370
371 with no leading spaces on blank line.
372 */
373
374 /*
375    aligned in middle
376    here
377            not here
378 */
379
380 /*
381         blank line in middle:
382
383         with no leading spaces on blank line.
384 */
385
386 func _() {
387         /*
388          * line
389          * of
390          * stars
391          */
392
393         /*
394                 aligned in middle
395                 here
396                         not here
397         */
398
399         /*
400                 blank line in middle:
401
402                 with no leading spaces on blank line.
403         */
404 }
405
406 // Some interesting interspersed comments
407 func _( /* this */ x /* is */ /* an */ int) {
408 }
409
410 func _( /* no params */ )       {}
411
412 func _() {
413         f( /* no args */ )
414 }
415
416 func ( /* comment1 */ T /* comment2 */ ) _()    {}
417
418 func _() { /* one-line functions with comments are formatted as multi-line functions */
419 }
420
421 func _() {
422         _ = 0
423         /* closing curly brace should be on new line */
424 }
425
426 func _() {
427         _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */ }
428 }
429
430 // Comments immediately adjacent to punctuation (for which the go/printer
431 // may only have estimated position information) must remain after the punctuation.
432 func _() {
433         _ = T{
434                 1,      // comment after comma
435                 2,      /* comment after comma */
436                 3,      // comment after comma
437         }
438         _ = T{
439                 1,      // comment after comma
440                 2,      /* comment after comma */
441                 3,      // comment after comma
442         }
443         _ = T{
444                 /* comment before literal */ 1,
445                 2,      /* comment before comma - ok to move after comma */
446                 3,      /* comment before comma - ok to move after comma */
447         }
448
449         for i = 0;      // comment after semicolon
450         i < 9;          /* comment after semicolon */
451         i++ {           // comment after opening curly brace
452         }
453
454         // TODO(gri) the last comment in this example should be aligned */
455         for i = 0;      // comment after semicolon
456         i < 9;          /* comment before semicolon - ok to move after semicolon */
457         i++ /* comment before opening curly brace */ {
458         }
459 }
460
461 // Line comments with tabs
462 func _() {
463         var finput *bufio.Reader        // input file
464         var stderr *bufio.Writer
465         var ftable *bufio.Writer        // y.go file
466         var foutput *bufio.Writer       // y.output file
467
468         var oflag string        // -o [y.go]            - y.go file
469         var vflag string        // -v [y.output]        - y.output file
470         var lflag bool          // -l                   - disable line directives
471 }
472
473 /* This comment is the last entry in this file. It must be printed and should be followed by a newline */