OSDN Git Service

libgo: Update to weekly.2011-12-22.
[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 f0.
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 //
120 // This comment should be associated with f1, with one blank line before the comment.
121 //
122 func f1() {
123         f0()
124         /* 1 */
125         // 2
126         /* 3 */
127         /* 4 */
128         f0()
129 }
130
131 func _() {
132         // this comment should be properly indented
133 }
134
135 func _(x int) int {
136         if x < 0 {      // the tab printed before this comment's // must not affect the remaining lines
137                 return -x       // this statement should be properly indented
138         }
139         if x < 0 {      /* the tab printed before this comment's /* must not affect the remaining lines */
140                 return -x       // this statement should be properly indented
141         }
142         return x
143 }
144
145 func typeswitch(x interface{}) {
146         switch v := x.(type) {
147         case bool, int, float:
148         case string:
149         default:
150         }
151
152         switch x.(type) {
153         }
154
155         switch v0, ok := x.(int); v := x.(type) {
156         }
157
158         switch v0, ok := x.(int); x.(type) {
159         case byte:      // this comment should be on the same line as the keyword
160                 // this comment should be normally indented
161                 _ = 0
162         case bool, int, float:
163                 // this comment should be indented
164         case string:
165         default:
166                 // this comment should be indented
167         }
168         // this comment should not be indented
169 }
170
171 func _() {
172         /* freestanding comment
173            aligned              line
174            aligned line
175         */
176 }
177
178 func _() {
179         /* freestanding comment
180            aligned              line
181            aligned line
182         */
183 }
184
185 func _() {
186         /* freestanding comment
187            aligned              line
188            aligned line */
189 }
190
191 func _() {
192         /*      freestanding comment
193                 aligned         line
194                 aligned line
195         */
196 }
197
198 func _() {
199         /*      freestanding comment
200                 aligned         line
201                 aligned line
202         */
203 }
204
205 func _() {
206         /*      freestanding comment
207                 aligned         line
208                 aligned line */
209 }
210
211 func _() {
212         /*
213            freestanding comment
214            aligned              line
215            aligned line
216         */
217 }
218
219 func _() {
220         /*
221            freestanding comment
222            aligned              line
223            aligned line
224         */
225 }
226
227 func _() {
228         /*
229            freestanding comment
230            aligned              line
231            aligned line */
232 }
233
234 func _() {
235         /*
236                 freestanding comment
237                 aligned         line
238                 aligned line
239         */
240 }
241
242 func _() {
243         /*
244                 freestanding comment
245                 aligned         line
246                 aligned line
247         */
248 }
249
250 func _() {
251         /*
252                 freestanding comment
253                 aligned         line
254                 aligned line */
255 }
256
257 func _() {
258         /* freestanding comment
259            aligned line
260         */
261 }
262
263 func _() {
264         /* freestanding comment
265            aligned line
266         */
267 }
268
269 func _() {
270         /* freestanding comment
271            aligned line */
272 }
273
274 func _() {
275         /*      freestanding comment
276                 aligned line
277         */
278 }
279
280 func _() {
281         /*      freestanding comment
282                 aligned line
283         */
284 }
285
286 func _() {
287         /*      freestanding comment
288                 aligned line */
289 }
290
291 func _() {
292         /*
293            freestanding comment
294            aligned line
295         */
296 }
297
298 func _() {
299         /*
300            freestanding comment
301            aligned line
302         */
303 }
304
305 func _() {
306         /*
307            freestanding comment
308            aligned line */
309 }
310
311 func _() {
312         /*
313                 freestanding comment
314                 aligned line
315         */
316 }
317
318 func _() {
319         /*
320                 freestanding comment
321                 aligned line
322         */
323 }
324
325 func _() {
326         /*
327                 freestanding comment
328                 aligned line */
329 }
330
331 /*
332  * line
333  * of
334  * stars
335  */
336
337 /* another line
338  * of
339  * stars */
340
341 /*      and another line
342  *      of
343  *      stars */
344
345 /* a line of
346  * stars */
347
348 /*      and another line of
349  *      stars */
350
351 /* a line of stars
352  */
353
354 /*      and another line of
355  */
356
357 /* a line of stars
358  */
359
360 /*      and another line of
361  */
362
363 /*
364 aligned in middle
365 here
366         not here
367 */
368
369 /*
370 blank line in middle:
371
372 with no leading spaces on blank line.
373 */
374
375 /*
376    aligned in middle
377    here
378            not here
379 */
380
381 /*
382         blank line in middle:
383
384         with no leading spaces on blank line.
385 */
386
387 func _() {
388         /*
389          * line
390          * of
391          * stars
392          */
393
394         /*
395                 aligned in middle
396                 here
397                         not here
398         */
399
400         /*
401                 blank line in middle:
402
403                 with no leading spaces on blank line.
404         */
405 }
406
407 // Some interesting interspersed comments
408 func _( /* this */ x /* is */ /* an */ int) {
409 }
410
411 func _( /* no params */ )       {}
412
413 func _() {
414         f( /* no args */ )
415 }
416
417 func ( /* comment1 */ T /* comment2 */ ) _()    {}
418
419 func _() { /* one-line functions with comments are formatted as multi-line functions */
420 }
421
422 func _() {
423         _ = 0
424         /* closing curly brace should be on new line */
425 }
426
427 func _() {
428         _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */ }
429 }
430
431 // Comments immediately adjacent to punctuation (for which the go/printer
432 // may only have estimated position information) must remain after the punctuation.
433 func _() {
434         _ = T{
435                 1,      // comment after comma
436                 2,      /* comment after comma */
437                 3,      // comment after comma
438         }
439         _ = T{
440                 1,      // comment after comma
441                 2,      /* comment after comma */
442                 3,      // comment after comma
443         }
444         _ = T{
445                 /* comment before literal */ 1,
446                 2,      /* comment before comma - ok to move after comma */
447                 3,      /* comment before comma - ok to move after comma */
448         }
449
450         for i = 0;      // comment after semicolon
451         i < 9;          /* comment after semicolon */
452         i++ {           // comment after opening curly brace
453         }
454
455         // TODO(gri) the last comment in this example should be aligned */
456         for i = 0;      // comment after semicolon
457         i < 9;          /* comment before semicolon - ok to move after semicolon */
458         i++ /* comment before opening curly brace */ {
459         }
460 }
461
462 // Line comments with tabs
463 func _() {
464         var finput *bufio.Reader        // input file
465         var stderr *bufio.Writer
466         var ftable *bufio.Writer        // y.go file
467         var foutput *bufio.Writer       // y.output file
468
469         var oflag string        // -o [y.go]            - y.go file
470         var vflag string        // -v [y.output]        - y.output file
471         var lflag bool          // -l                   - disable line directives
472 }
473
474 /* This comment is the last entry in this file. It must be printed and should be followed by a newline */