mirror of
https://github.com/golang/go
synced 2024-11-25 09:47:57 -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:
parent
ba5175401e
commit
c4e27b7cfb
@ -209,6 +209,11 @@ func (p *printer) write(data []byte) {
|
|||||||
|
|
||||||
case tabwriter.Escape:
|
case tabwriter.Escape:
|
||||||
p.escape = !p.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--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
src/pkg/go/printer/testdata/comments.golden
vendored
32
src/pkg/go/printer/testdata/comments.golden
vendored
@ -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
|
// Line comments with tabs
|
||||||
func _() {
|
func _() {
|
||||||
var finput *bufio.Reader // input file
|
var finput *bufio.Reader // input file
|
||||||
|
34
src/pkg/go/printer/testdata/comments.input
vendored
34
src/pkg/go/printer/testdata/comments.input
vendored
@ -429,6 +429,40 @@ func _() {
|
|||||||
/* closing curly brace should be on new line */ }
|
/* 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
|
// Line comments with tabs
|
||||||
func _() {
|
func _() {
|
||||||
var finput *bufio.Reader // input file
|
var finput *bufio.Reader // input file
|
||||||
|
@ -335,7 +335,6 @@ func _() {
|
|||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
// TODO(gri) the cases below are not correct yet
|
|
||||||
f(1,
|
f(1,
|
||||||
2,
|
2,
|
||||||
3) // comment
|
3) // comment
|
||||||
@ -348,8 +347,7 @@ func _() {
|
|||||||
3) // comment
|
3) // comment
|
||||||
f(1,
|
f(1,
|
||||||
2,
|
2,
|
||||||
3 // comment
|
3, // comment
|
||||||
,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +328,6 @@ func _() {
|
|||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
// TODO(gri) the cases below are not correct yet
|
|
||||||
f(1,
|
f(1,
|
||||||
2,
|
2,
|
||||||
3) // comment
|
3) // comment
|
||||||
|
4
src/pkg/go/printer/testdata/expressions.raw
vendored
4
src/pkg/go/printer/testdata/expressions.raw
vendored
@ -335,7 +335,6 @@ func _() {
|
|||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
// TODO(gri) the cases below are not correct yet
|
|
||||||
f(1,
|
f(1,
|
||||||
2,
|
2,
|
||||||
3) // comment
|
3) // comment
|
||||||
@ -348,8 +347,7 @@ func _() {
|
|||||||
3) // comment
|
3) // comment
|
||||||
f(1,
|
f(1,
|
||||||
2,
|
2,
|
||||||
3 // comment
|
3, // comment
|
||||||
,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user