1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:40:21 -07:00

gofmt, go/printer: update internal estimated position correctly

Fixes #1089.

R=rsc
CC=golang-dev
https://golang.org/cl/2172043
This commit is contained in:
Robert Griesemer 2010-09-08 22:01:48 -07:00
parent ba5175401e
commit c4e27b7cfb
6 changed files with 73 additions and 7 deletions

View File

@ -209,6 +209,11 @@ func (p *printer) write(data []byte) {
case tabwriter.Escape:
p.escape = !p.escape
// ignore escape chars introduced by printer - they are
// invisible and must not affect p.pos (was issue #1089)
p.pos.Offset--
p.pos.Column--
}
}

View File

@ -431,6 +431,38 @@ func _() {
}
// Comments immediately adjacent to punctuation (for which the go/printer
// may obly have estimated position information) must remain after the punctuation.
func _() {
_ = T{
1, // comment after comma
2, /* comment after comma */
3, // comment after comma
}
_ = T{
1, // comment after comma
2, /* comment after comma */
3, // comment after comma
}
_ = T{
/* comment before literal */ 1,
2, /* comment before comma - ok to move after comma */
3, /* comment before comma - ok to move after comma */
}
for i = 0; // comment after semicolon
i < 9; /* comment after semicolon */
i++ { // comment after opening curly brace
}
// TODO(gri) the last comment in this example should be aligned */
for i = 0; // comment after semicolon
i < 9; /* comment before semicolon - ok to move after semicolon */
i++ /* comment before opening curly brace */ {
}
}
// Line comments with tabs
func _() {
var finput *bufio.Reader // input file

View File

@ -429,6 +429,40 @@ func _() {
/* closing curly brace should be on new line */ }
// Comments immediately adjacent to punctuation (for which the go/printer
// may obly have estimated position information) must remain after the punctuation.
func _() {
_ = T{
1, // comment after comma
2, /* comment after comma */
3 , // comment after comma
}
_ = T{
1 ,// comment after comma
2 ,/* comment after comma */
3,// comment after comma
}
_ = T{
/* comment before literal */1,
2/* comment before comma - ok to move after comma */,
3 /* comment before comma - ok to move after comma */ ,
}
for
i=0;// comment after semicolon
i<9;/* comment after semicolon */
i++{// comment after opening curly brace
}
// TODO(gri) the last comment in this example should be aligned */
for
i=0;// comment after semicolon
i<9/* comment before semicolon - ok to move after semicolon */;
i++ /* comment before opening curly brace */ {
}
}
// Line comments with tabs
func _() {
var finput *bufio.Reader // input file

View File

@ -335,7 +335,6 @@ func _() {
2,
3,
)
// TODO(gri) the cases below are not correct yet
f(1,
2,
3) // comment
@ -348,8 +347,7 @@ func _() {
3) // comment
f(1,
2,
3 // comment
,
3, // comment
)
}

View File

@ -328,7 +328,6 @@ func _() {
2,
3,
)
// TODO(gri) the cases below are not correct yet
f(1,
2,
3) // comment

View File

@ -335,7 +335,6 @@ func _() {
2,
3,
)
// TODO(gri) the cases below are not correct yet
f(1,
2,
3) // comment
@ -348,8 +347,7 @@ func _() {
3) // comment
f(1,
2,
3 // comment
,
3, // comment
)
}