diff options
author | Eli Bendersky <eliben@google.com> | 2019-08-01 15:39:40 -0700 |
---|---|---|
committer | Emmanuel Odeke <emm.odeke@gmail.com> | 2019-09-24 16:36:56 +0000 |
commit | 47d27a87f962606230ef9b1a4d42253ceae95f94 (patch) | |
tree | ae16b88a97086ffbc7a2fb4066ea9856c940934a /src/strings/strings_test.go | |
parent | 904fdb37575e7ec5533652ac8da0218a34478958 (diff) | |
download | go-git-47d27a87f962606230ef9b1a4d42253ceae95f94.tar.gz |
cmd/gofmt: fix computation of function header size
Function sizes are computed to determine whether a function
can be kept on one line or should be split to several lines. Part of the
computation is the function header from the FUNC token and until the
opening { token.
Prior to this change, the function header size used distance from the
original source position of the current token, which led to issues when
the source between FUNC and the original source position was rewritten
(such as whitespace being collapsed). Now we take the current output
position into account, so that header size represents the reformatted
source rather than the original source.
The following files in the Go repository are reformatted with this
change:
* strings/strings_test.go
* cmd/compile/internal/gc/fmt.go
In both cases the reformatting is minor and seems to be correct given
the heuristic to single-line functions longer than 100 columns to
multiple lines.
Fixes #28082
Change-Id: Ib737f6933e09b79e83715211421d5262b366ec93
Reviewed-on: https://go-review.googlesource.com/c/go/+/188818
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/strings/strings_test.go')
-rw-r--r-- | src/strings/strings_test.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index fb736b29d3..ad14a0574a 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -194,10 +194,12 @@ func runIndexTests(t *testing.T, f func(s, sep string) int, funcName string, tes } } -func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) } -func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", lastIndexTests) } -func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", indexAnyTests) } -func TestLastIndexAny(t *testing.T) { runIndexTests(t, LastIndexAny, "LastIndexAny", lastIndexAnyTests) } +func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) } +func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", lastIndexTests) } +func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", indexAnyTests) } +func TestLastIndexAny(t *testing.T) { + runIndexTests(t, LastIndexAny, "LastIndexAny", lastIndexAnyTests) +} func TestIndexByte(t *testing.T) { for _, tt := range indexTests { |