OSDN Git Service

Update Go compiler, library, and testsuite on gcc 4.7 branch.
[pf3gnuchains/gcc-fork.git] / libgo / go / go / printer / testdata / comments.golden
index d2ad9e3..d9aa2d8 100644 (file)
@@ -168,6 +168,91 @@ func typeswitch(x interface{}) {
        // this comment should not be indented
 }
 
+//
+// Indentation of comments after possibly indented multi-line constructs
+// (test cases for issue 3147).
+//
+
+func _() {
+       s := 1 +
+               2
+       // should be indented like s
+}
+
+func _() {
+       s := 1 +
+               2       // comment
+       // should be indented like s
+}
+
+func _() {
+       s := 1 +
+               2       // comment
+       // should be indented like s
+       _ = 0
+}
+
+func _() {
+       s := 1 +
+               2
+       // should be indented like s
+       _ = 0
+}
+
+func _() {
+       s := 1 +
+               2
+
+       // should be indented like s
+}
+
+func _() {
+       s := 1 +
+               2       // comment
+
+       // should be indented like s
+}
+
+func _() {
+       s := 1 +
+               2       // comment
+
+       // should be indented like s
+       _ = 0
+}
+
+func _() {
+       s := 1 +
+               2
+
+       // should be indented like s
+       _ = 0
+}
+
+// Test case from issue 3147.
+func f() {
+       templateText := "a" +   // A
+               "b" +   // B
+               "c"     // C
+
+       // should be aligned with f()
+       f()
+}
+
+// Modified test case from issue 3147.
+func f() {
+       templateText := "a" +   // A
+               "b" +   // B
+               "c"     // C
+
+               // may not be aligned with f() (source is not aligned)
+       f()
+}
+
+//
+// Test cases for alignment of lines in general comments.
+//
+
 func _() {
        /* freestanding comment
           aligned              line
@@ -404,17 +489,18 @@ func _() {
        */
 }
 
-// Some interesting interspersed comments
+// Some interesting interspersed comments.
+// See below for more common cases.
 func _( /* this */ x /* is */ /* an */ int) {
 }
 
-func _( /* no params */ )      {}
+func _( /* no params */      {}
 
 func _() {
-       f( /* no args */ )
+       f( /* no args */)
 }
 
-func ( /* comment1 */ T /* comment2 */ ) _()   {}
+func ( /* comment1 */ T /* comment2 */) _()    {}
 
 func _() { /* one-line functions with comments are formatted as multi-line functions */
 }
@@ -425,11 +511,32 @@ func _() {
 }
 
 func _() {
-       _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */ }
+       _ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */}
 }
 
-// Comments immediately adjacent to punctuation (for which the go/printer
-// may only have estimated position information) must remain after the punctuation.
+// Test cases from issue 1542:
+// Comments must not be placed before commas and cause invalid programs.
+func _() {
+       var a = []int{1, 2      /*jasldf*/}
+       _ = a
+}
+
+func _() {
+       var a = []int{1, 2}/*jasldf
+        */
+
+       _ = a
+}
+
+func _() {
+       var a = []int{1, 2}// jasldf 
+
+       _ = a
+}
+
+// Comments immediately adjacent to punctuation followed by a newline
+// remain after the punctuation (looks better and permits alignment of
+// comments).
 func _() {
        _ = T{
                1,      // comment after comma
@@ -459,6 +566,54 @@ func _() {
        }
 }
 
+// If there is no newline following punctuation, commas move before the punctuation.
+// This way, commas interspersed in lists stay with the respective expression.
+func f(x /* comment */, y int, z int /* comment */, u, v, w int /* comment */) {
+       f(x /* comment */, y)
+       f(x,    /* comment */
+               y)
+       f(
+               x,      /* comment */
+       )
+}
+
+func g(
+       x int,  /* comment */
+) {
+}
+
+type _ struct {
+       a, b /* comment */, c int
+}
+
+type _ struct {
+       a, b /* comment */, c int
+}
+
+func _() {
+       for a /* comment */, b := range x {
+       }
+}
+
+// Print line directives correctly.
+
+// The following is a legal line directive.
+//line foo:1
+func _() {
+       _ = 0
+       // The following is a legal line directive. It must not be indented:
+//line foo:2
+       _ = 1
+
+       // The following is not a legal line directive (it doesn't start in column 1):
+       //line foo:2
+       _ = 2
+
+       // The following is not a legal line directive (negative line number):
+       //line foo:-3
+       _ = 3
+}
+
 // Line comments with tabs
 func _() {
        var finput *bufio.Reader        // input file