Skip to content

Commit

Permalink
59191 example works when flag is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghostjs123 authored and collinwright committed Apr 13, 2023
1 parent 1312d9e commit 1310721
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/go/ast/ast.go
Expand Up @@ -8,9 +8,12 @@ package ast

import (
"go/token"
"internal/godebug"
"strings"
)

var exampledontreduce = godebug.New("exampledontreduce")

// ----------------------------------------------------------------------------
// Interfaces
//
Expand Down Expand Up @@ -141,13 +144,17 @@ func (g *CommentGroup) Text() string {
// Remove leading blank lines; convert runs of
// interior blank lines to a single blank line.
n := 0
for _, line := range lines {
if line != "" || n > 0 && lines[n-1] != "" {
lines[n] = line
n++
if exampledontreduce.Value() != "1" {
for _, line := range lines {
if line != "" || n > 0 && lines[n-1] != "" {
lines[n] = line
n++
}
}
lines = lines[0:n]
} else {
n = len(lines)
}
lines = lines[0:n]

// Add final "" entry to get trailing newline from Join.
if n > 0 && lines[n-1] != "" {
Expand Down
1 change: 1 addition & 0 deletions src/go/doc/example_test.go
Expand Up @@ -21,6 +21,7 @@ import (
)

func TestExamples(t *testing.T) {
t.Setenv("GODEBUG", "exampledontreduce=1")
dir := filepath.Join("testdata", "examples")
filenames, err := filepath.Glob(filepath.Join(dir, "*.go"))
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions src/go/doc/testdata/examples/issue59191.go
@@ -0,0 +1,15 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package foo_test

func Example() {
//Output:
//Single newline:
//
//Double newline:
//
//
//Final text
}
14 changes: 14 additions & 0 deletions src/go/doc/testdata/examples/issue59191.golden
@@ -0,0 +1,14 @@
-- .Play --
package main

import ()

func main() {
}
-- .Output --
Single newline:

Double newline:


Final text

0 comments on commit 1310721

Please sign in to comment.