1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:00:09 -07:00

go/printer: test that formatted code is parseable

- Added test case for issue 1542.

Fixes #1542.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5645080
This commit is contained in:
Robert Griesemer 2012-02-10 13:28:29 -08:00
parent f8cf82f6f2
commit a0acdd210b
3 changed files with 49 additions and 2 deletions

View File

@ -67,6 +67,13 @@ func runcheck(t *testing.T, source, golden string, mode checkMode) {
}
res := buf.Bytes()
// formatted source must be valid
if _, err := parser.ParseFile(fset, "", res, 0); err != nil {
t.Error(err)
t.Logf("\n%s", res)
return
}
// update golden files if necessary
if *update {
if err := ioutil.WriteFile(golden, res, 0644); err != nil {

View File

@ -404,7 +404,7 @@ func _() {
*/
}
// Some interesting interspersed comments
// Some interesting interspersed comments.
func _( /* this */ x /* is */ /* an */ int) {
}
@ -428,6 +428,26 @@ func _() {
_ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */ }
}
// 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 (for which the go/printer
// may only have estimated position information) must remain after the punctuation.
func _() {

View File

@ -410,7 +410,7 @@ func _() {
}
// Some interesting interspersed comments
// Some interesting interspersed comments.
func _(/* this */x/* is *//* an */ int) {
}
@ -432,6 +432,26 @@ func _() {
_ = []int{0, 1 /* don't introduce a newline after this comment - was issue 1365 */}
}
// 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 (for which the go/printer
// may only have estimated position information) must remain after the punctuation.