diff options
| author | Ondřej Surý <ondrej@sury.org> | 2011-02-18 09:50:58 +0100 | 
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2011-02-18 09:50:58 +0100 | 
| commit | c072558b90f1bbedc2022b0f30c8b1ac4712538e (patch) | |
| tree | 67767591619e4bd8111fb05fac185cde94fb7378 /src/pkg/go/printer/printer_test.go | |
| parent | 5859517b767c99749a45651c15d4bae5520ebae8 (diff) | |
| download | golang-c072558b90f1bbedc2022b0f30c8b1ac4712538e.tar.gz | |
Imported Upstream version 2011.02.15upstream/2011.02.15
Diffstat (limited to 'src/pkg/go/printer/printer_test.go')
| -rw-r--r-- | src/pkg/go/printer/printer_test.go | 37 | 
1 files changed, 36 insertions, 1 deletions
| diff --git a/src/pkg/go/printer/printer_test.go b/src/pkg/go/printer/printer_test.go index c66471b92..565075aa2 100644 --- a/src/pkg/go/printer/printer_test.go +++ b/src/pkg/go/printer/printer_test.go @@ -127,7 +127,7 @@ var data = []entry{  } -func Test(t *testing.T) { +func TestFiles(t *testing.T) {  	for _, e := range data {  		source := path.Join(dataDir, e.source)  		golden := path.Join(dataDir, e.golden) @@ -136,3 +136,38 @@ func Test(t *testing.T) {  		//check(t, golden, golden, e.mode);  	}  } + + +// TestLineComments, using a simple test case, checks that consequtive line +// comments are properly terminated with a newline even if the AST position +// information is incorrect. +// +func TestLineComments(t *testing.T) { +	const src = `// comment 1 +	// comment 2 +	// comment 3 +	package main +	` + +	fset := token.NewFileSet() +	ast1, err1 := parser.ParseFile(fset, "", src, parser.ParseComments) +	if err1 != nil { +		panic(err1) +	} + +	var buf bytes.Buffer +	fset = token.NewFileSet() // use the wrong file set +	Fprint(&buf, fset, ast1) + +	nlines := 0 +	for _, ch := range buf.Bytes() { +		if ch == '\n' { +			nlines++ +		} +	} + +	const expected = 3 +	if nlines < expected { +		t.Errorf("got %d, expected %d\n", nlines, expected) +	} +} | 
