Skip to content

Commit c999d51

Browse files
committed
_content: update for golang.org/x/example changes
golang.org/x/example/stringutil.Reverse moved to golang.org/x/example/hello/reverse.String. Update references accordingly. Fixes golang/go#61722. Change-Id: Ib041697bc1c5c40d2b6ccefc7550caaedf338b2d Reviewed-on: https://go-review.googlesource.com/c/website/+/515238 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Russ Cox <[email protected]>
1 parent d6ad5f4 commit c999d51

File tree

5 files changed

+69
-717
lines changed

5 files changed

+69
-717
lines changed

_content/blog/examples.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,44 @@ As with typical tests, examples are functions that reside in a package's
3636
Unlike normal test functions, though, example functions take no arguments
3737
and begin with the word `Example` instead of `Test`.
3838

39-
The [`stringutil` package](https://pkg.go.dev/golang.org/x/example/stringutil/)
39+
The [`reverse` package](https://pkg.go.dev/golang.org/x/example/hello/reverse/)
4040
is part of the [Go example repository](https://cs.opensource.google/go/x/example).
41-
Here's an example that demonstrates its `Reverse` function:
41+
Here's an example that demonstrates its `String` function:
4242

43-
package stringutil_test
43+
package reverse_test
4444

4545
import (
4646
"fmt"
4747

48-
"golang.org/x/example/stringutil"
48+
"golang.org/x/example/hello/reverse"
4949
)
5050

51-
func ExampleReverse() {
52-
fmt.Println(stringutil.Reverse("hello"))
51+
func ExampleString() {
52+
fmt.Println(reverse.String("hello"))
5353
// Output: olleh
5454
}
5555

56-
This code might live in `example_test.go` in the `stringutil` directory.
56+
This code might live in `example_test.go` in the `reverse` directory.
5757

58-
Godoc will present this example alongside the `Reverse` function's documentation:
58+
The Go package documentation server _pkg.go.dev_ presents this
59+
example alongside the [`String` function's documentation](https://pkg.go.dev/golang.org/x/example/hello/reverse/#String):
5960

60-
{{image "examples/reverse.png"}}
61+
{{image "examples/pkgdoc.png" 517}}
6162

6263
Running the package's test suite, we can see the example function is executed
6364
with no further arrangement from us:
6465

6566
$ go test -v
66-
=== RUN TestReverse
67-
--- PASS: TestReverse (0.00s)
68-
=== RUN: ExampleReverse
69-
--- PASS: ExampleReverse (0.00s)
67+
=== RUN TestString
68+
--- PASS: TestString (0.00s)
69+
=== RUN ExampleString
70+
--- PASS: ExampleString (0.00s)
7071
PASS
71-
ok golang.org/x/example/stringutil 0.009s
72+
ok golang.org/x/example/hello/reverse 0.209s
7273

7374
## Output comments
7475

75-
What does it mean that the `ExampleReverse` function "passes"?
76+
What does it mean that the `ExampleString` function "passes"?
7677

7778
As it executes the example,
7879
the testing framework captures data written to standard output
@@ -82,15 +83,15 @@ The test passes if the test's output matches its output comment.
8283
To see a failing example we can change the output comment text to something
8384
obviously incorrect
8485

85-
func ExampleReverse() {
86-
fmt.Println(stringutil.Reverse("hello"))
86+
func ExampleString() {
87+
fmt.Println(reverse.String("hello"))
8788
// Output: golly
8889
}
8990

9091
and run the tests again:
9192

9293
$ go test
93-
--- FAIL: ExampleReverse (0.00s)
94+
--- FAIL: ExampleString (0.00s)
9495
got:
9596
olleh
9697
want:
@@ -99,17 +100,17 @@ and run the tests again:
99100

100101
If we remove the output comment entirely
101102

102-
func ExampleReverse() {
103-
fmt.Println(stringutil.Reverse("hello"))
103+
func ExampleString() {
104+
fmt.Println(reverse.String("hello"))
104105
}
105106

106107
then the example function is compiled but not executed:
107108

108109
$ go test -v
109-
=== RUN TestReverse
110-
--- PASS: TestReverse (0.00s)
110+
=== RUN TestString
111+
--- PASS: TestString (0.00s)
111112
PASS
112-
ok golang.org/x/example/stringutil 0.009s
113+
ok golang.org/x/example/hello/reverse 0.110s
113114

114115
Examples without output comments are useful for demonstrating code that cannot
115116
run as unit tests, such as that which accesses the network,
@@ -124,16 +125,16 @@ package-level identifier.
124125
func ExampleBar_Qux() // documents the Qux method of type Bar
125126
func Example() // documents the package as a whole
126127

127-
Following this convention, godoc displays the `ExampleReverse` example
128-
alongside the documentation for the `Reverse` function.
128+
Following this convention, godoc displays the `ExampleString` example
129+
alongside the documentation for the `String` function.
129130

130131
Multiple examples can be provided for a given identifier by using a suffix
131132
beginning with an underscore followed by a lowercase letter.
132-
Each of these examples documents the `Reverse` function:
133+
Each of these examples documents the `String` function:
133134

134-
func ExampleReverse()
135-
func ExampleReverse_second()
136-
func ExampleReverse_third()
135+
func ExampleString()
136+
func ExampleString_second()
137+
func ExampleString_third()
137138

138139
## Larger examples
139140

_content/blog/examples/pkgdoc.png

106 KB
Loading

_content/doc/code.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ <h2 id="Introduction">Introduction</h2>
1212
fetch, build, and install Go modules, packages, and commands.
1313
</p>
1414

15-
<p>
16-
Note: This document assumes that you are using Go 1.13 or later and the
17-
<code>GO111MODULE</code> environment variable is not set. If you are looking for
18-
the older, pre-modules version of this document, it is archived
19-
<a href="gopath_code.html">here</a>.
20-
</p>
21-
2215
<h2 id="Organization">Code organization</h2>
2316

2417
<p>

0 commit comments

Comments
 (0)