You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
testing: example output whitespace trimming can be confusing #23542
Given that there are three fmt.Println calls, it seems to me that there really ought to be three lines of output.
(And if we decide that we don't want to or can't change example output whitespace trimming, we should at least tweak this example so that the last line of output contains non-whitespace, e.g. by prefixing each output line with an asterisk or number.)
Perhaps another solution would be to not leave the empty line print at either end, so that it could not be trimmed. Leaving it in the middle, for example.
This simple change exposed a limitation in example output testing. The example works if the fmt.Println(path.Split("")) line is either the first or last line in the example, but not the middle line. Its single whitespace character and new line are stripped before comparison if it's on either end of the output, but not if it's in the middle (see the example output below).
Adding a whitespace character in the example output doesn't help either because each line is trimmed before being joined with a new line character as best I can tell.
Hey folks, I just did a Go contributors' workshop at London GopherCon and was looking at this as potentially my first issue to try to contribute.
Has there been any further decision about this issue?
Activity
mvdan commentedon Jan 25, 2018
Perhaps another solution would be to not leave the empty line print at either end, so that it could not be trimmed. Leaving it in the middle, for example.
awoodbeck commentedon Jan 29, 2018
I could take this one. I prefer mvdan's suggestion unless we'd like to be more explicit with the whitespace.
Output would of course look like this:
Edit: Here's another proposal with explicit treatment of whitespace:
The code:
The output:
rsc commentedon Jan 29, 2018
It seems like the simplest fix is to swap the second and third line.
awoodbeck commentedon Jan 30, 2018
This simple change exposed a limitation in example output testing. The example works if the
fmt.Println(path.Split(""))line is either the first or last line in the example, but not the middle line. Its single whitespace character and new line are stripped before comparison if it's on either end of the output, but not if it's in the middle (see the example output below).Adding a whitespace character in the example output doesn't help either because each line is trimmed before being joined with a new line character as best I can tell.
josharian commentedon Jan 30, 2018
Possibly related: #6416
1 remaining item
awoodbeck commentedon Jan 30, 2018
Here's a proposed compromise:
Code:
Output:
This passes but it may convolute the last example.
josharian commentedon Feb 1, 2018
I dunno. It'd be nice for all three to be constructed similarly. I tried this, but it's even worse:
I can't say I have any better ideas at this point.
awoodbeck commentedon Feb 5, 2018
Here's another suggestion that similarly constructs all 3 examples and passes.
Output:
awoodbeck commentedon Feb 12, 2018
Any opinion on my last example? I will submit it as a CL if it's received better than the current example.
josharian commentedon Feb 12, 2018
On m phone, but: it is nice for examples to be copy-paste friendly. In particular, having a line that reads:
file, sir := path.Split(x)
with useful mnemonic variable names seems valuable. And then we could avoid nested fmt calls and a code golf flavor.
irbekrm commentedon Aug 22, 2019
Hey folks, I just did a Go contributors' workshop at London GopherCon and was looking at this as potentially my first issue to try to contribute.
Has there been any further decision about this issue?
mvdan commentedon Aug 22, 2019
@irbekrm I don't think there was a consensus so far; I'd say pick a solution you like (or your own solution), and we can always discuss it on the CL.
irbekrm commentedon Aug 22, 2019
Thanks @mvdan
gopherbot commentedon Aug 22, 2019
Change https://golang.org/cl/191397 mentions this issue:
path: change the output format of ExampleSplit functionpath: change the output format of ExampleSplit function