1
0
mirror of https://github.com/golang/go synced 2024-10-04 08:31:22 -06:00
go/src/pkg/strings
Robert Griesemer f26d61731d go/parser: fix comment grouping (day 1 bug)
Comment groups must end at the end of a line (or the
next non-comment token) if the group started on a line
with non-comment tokens.

This is important for correct computation of "lead"
and "line" comments (Doc and Comment fields in AST nodes).

Without this fix, the "line" comment for F1 in the
following example:

type T struct {
     F1 int // comment1
     // comment2
     F2 int
}

is "// comment1// comment2" rather than just "// comment1".

This bug was present from Day 1 but only visible when
looking at export-filtered ASTs where only comments
associated with AST nodes are printed, and only in rare
cases (e.g, in the case above, if F2 where not exported,
godoc would show "// comment2" anyway because it was
considered part of the "line" comment for F1).

The bug fix is very small (parser.go). The bulk of the
changes are additional test cases (parser_test.go).

The fix exposed a caching bug in go/printer via one of the
existing tests, hence the changes to printer.go.

As an aside, the fix removes the the need for empty lines
before an "// Output" comment for some special cases of
code examples (e.g.: src/pkg/strings/example_test.go, Count
example).

No impact on gofmt formatting of src, misc.

Fixes #3139.

R=rsc
CC=golang-dev
https://golang.org/cl/6209080
2012-05-22 10:04:34 -07:00
..
example_test.go go/parser: fix comment grouping (day 1 bug) 2012-05-22 10:04:34 -07:00
export_test.go strings: implement a faster byte->byte Replacer 2011-10-03 13:12:01 -07:00
reader_test.go bytes,strings: make *Reader implement io.ReaderAt 2012-02-15 12:58:00 +11:00
reader.go bytes,strings: make *Reader implement io.ReaderAt 2012-02-15 12:58:00 +11:00
replace_test.go bytes, strings: use rune 2011-10-25 22:22:09 -07:00
replace.go src/pkg/[n-z]*: gofix -r error -force=error 2011-11-01 22:05:34 -04:00
strings_test.go panics: use the new facilities of testing.B instead 2011-12-20 10:36:25 -08:00
strings.go update tree for new default type rule 2011-12-08 22:08:03 -05:00