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.
9 func use(x interface{}) {}
11 // Formatting of multi-line return statements.
99 // Formatting of multi-line returns: test cases from issue 1207.
100 func F() (*T, os.Error) {
108 func G() (*T, *T, os.Error) {
120 func _() interface{} {
122 name: basename(file.name),
123 size: mkSize(d.FileSizeHigh, d.FileSizeLow),
124 modTime: mkModTime(d.LastWriteTime),
125 mode: mkMode(d.FileAttributes),
126 sys: mkSysFromFI(&d),
130 // Formatting of if-statement headers.
135 } // no semicolon printed
139 } // no semicolon printed
141 } // no parens printed
143 } // no semicolon and parens printed
152 // Formatting of switch-statement headers.
157 } // no semicolon printed
161 } // no semicolon printed
163 } // no parens printed
165 } // no semicolon and parens printed
171 switch x := expr; expr {
177 // Formatting of switch statement bodies.
185 use(x) // followed by an empty line
187 case 2: // followed by an empty line
189 use(x) // followed by an empty line
191 case 3: // no empty lines
199 case 1: // this comment should have no effect on the previous or next line
206 // this comment should be indented
209 // this comment should not be indented, it is aligned with the next case
220 /* not indented comment
230 // Formatting of selected select statements.
233 select { /* this comment should not be tab-aligned because the closing } is on the same line */
235 select { /* this comment should be tab-aligned */
237 select { // this comment should be tab-aligned
244 // Formatting of for-statement headers for single-line for-loops.
251 } // no parens printed
253 } // no semicolons printed
258 } // no semicolons printed
260 } // no semicolons and parens printed
261 for ; ; expr = false {
263 for x := expr; expr; {
266 for x := expr; ; expr = false {
269 for ; expr; expr = false {
271 for x := expr; expr; expr = false {
274 for x := range []int{} {
277 for x := range []int{} {
279 } // no parens printed
282 // Formatting of for-statement headers for multi-line for-loops.
289 } // no parens printed
291 } // no semicolons printed
296 } // no semicolons printed
298 } // no semicolons and parens printed
299 for ; ; expr = false {
301 for x := expr; expr; {
304 for x := expr; ; expr = false {
307 for ; expr; expr = false {
309 for x := expr; expr; expr = false {
312 for x := range []int{} {
315 for x := range []int{} {
317 } // no parens printed
320 // Formatting of selected short single- and multi-line statements.
328 } // else clause always requires multiple lines
332 for i := 0; i < len(a); 1++ {
334 for i := 0; i < len(a); 1++ {
337 for i := 0; i < len(a); 1++ {
356 if x := recover(); x != nil {
357 err = fmt.Sprintf("error: %s", x.msg)
362 // Don't remove mandatory parentheses around composite literals in control clauses.
364 // strip parentheses - no composite literals or composite literals don't start with a type name
396 for _ = range []T{T{42}} {
399 // leave parentheses - composite literals start with a type name
419 for _ = range (T1{T{42}}) {
432 if x == a+b*(T{42}[0]) {
434 if (x == a+b*T{42}[0]) {
436 if x == a+b*(T{42}[0]) {
438 if x == a+(b * (T{42}[0])) {
440 if x == a+b*(T{42}[0]) {
442 if (a + b*(T{42}[0])) == x {
444 if (a + b*(T{42}[0])) == x {
447 if struct{ x bool }{false}.x {
449 if (struct{ x bool }{false}.x) == false {
451 if struct{ x bool }{false}.x == false {
455 // Extra empty lines inside functions. Do respect source code line
456 // breaks between statement boundaries but print at most one empty
469 // Each use(x) call below should have at most one empty line before and after.
470 // Known bug: The first use call may have more than one empty line before
471 // (see go/printer/nodes.go, func linebreak).
486 // Formatting around labels.
492 // this comment should be indented
493 L: // no semicolon needed
500 ; // semicolon required
503 ; // semicolon required
505 L2: // no semicolon needed
519 // this comment should be indented
529 // this comment should be indented
544 // this comment should be indented
557 _ = 0 // the indentation here should not be affected by the long label name
583 L: // A comment on the same line as the label, followed by a single empty line.
584 // Known bug: There may be more than one empty line before MoreCode()
585 // (see go/printer/nodes.go, func linebreak).
596 // There should be a single empty line before this comment.
602 goto AVeryLongLabelThatShouldNotAffectFormatting
604 AVeryLongLabelThatShouldNotAffectFormatting:
605 // There should be a single empty line after this comment.
607 // There should be a single empty line before this comment.
611 // Formatting of empty statements.