Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit bd726c6

Browse files
committed
改进翻译
1 parent 75eb2ad commit bd726c6

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

blog/zh_CN/content/examples.article

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ and clicking the associated "Run" button.
2929

3030
.html _tr/div_begin_zh_CN.html
3131

32-
Godoc的例子在包文档中显示为一个代码片段, 它们在运行包测试的时候被验证.
32+
Godoc的示例在包文档中显示为一个代码片段, 它们在运行包测试的时候被验证.
3333
用户也可以在 `godoc` 的网页上, 通过点击 "Run" 按钮来运行.
3434

3535
.html _tr/div_end.html
@@ -81,7 +81,7 @@ This article explains how to write your own example functions.
8181

8282
.html _tr/div_begin_zh_CN.html
8383

84-
* 示例也是测试
84+
* 示例也是一种测试
8585

8686
.html _tr/div_end.html
8787

@@ -94,7 +94,7 @@ suite.
9494

9595
.html _tr/div_begin_zh_CN.html
9696

97-
实例程序会作为包测试的一部分被编译(并被有选择地运行).
97+
示例会作为包测试的一部分被编译(并被有选择地运行).
9898

9999
.html _tr/div_end.html
100100

@@ -109,7 +109,7 @@ Unlike normal test functions, though, example functions begin with the word
109109

110110
.html _tr/div_begin_zh_CN.html
111111

112-
在典型的测试中, 示例函数在包的 `_test.go` 文件中.
112+
在典型的测试中, 示例在包的 `_test.go` 文件中.
113113
和一般测试函数的区别是示例函数名以 `Example` 开头, 而不是以 `Test` 开头.
114114

115115
.html _tr/div_end.html
@@ -126,12 +126,10 @@ Here's an example that demonstrates its `Reverse` function:
126126

127127
[[https://godoc.org/github.com/golang/example/stringutil/][`stringutil` 包]] 是
128128
[[https://github.com/golang/example][Go 例子库]] 的一部分.
129-
这里演示了 `Reverse` 函数的用法:
129+
这里演示了 `Reverse` 示例函数的用法:
130130

131131
.html _tr/div_end.html
132132

133-
.html _tr/div_begin_en.html
134-
135133
package stringutil_test
136134

137135
import (
@@ -145,8 +143,6 @@ Here's an example that demonstrates its `Reverse` function:
145143
// Output: olleh
146144
}
147145

148-
.html _tr/div_end.html
149-
150146
.html _tr/div_begin_en.html
151147

152148
This code might live in `example_test.go` in the `stringutil` directory.
@@ -167,7 +163,7 @@ Godoc will present this example alongside the `Reverse` function's documentation
167163

168164
.html _tr/div_begin_zh_CN.html
169165

170-
Godoc 会在 `Reverse` 函数的文档部分显示这个例子.
166+
Godoc 会在 `Reverse` 函数的文档部分显示这个示例.
171167

172168
.html _tr/div_end.html
173169

@@ -186,8 +182,6 @@ with no further arrangement from us:
186182

187183
.html _tr/div_end.html
188184

189-
.html _tr/div_begin_en.html
190-
191185
$ go test -v
192186
=== RUN TestReverse
193187
--- PASS: TestReverse (0.00s)
@@ -197,8 +191,6 @@ with no further arrangement from us:
197191
ok github.com/golang/example/stringutil 0.009s
198192

199193

200-
.html _tr/div_end.html
201-
202194
.html _tr/div_begin_en.html
203195

204196
* Output comments
@@ -219,7 +211,7 @@ What does it mean that the `ExampleReverse` function "passes"?
219211

220212
.html _tr/div_begin_zh_CN.html
221213

222-
`ExampleReverse` 函数 "passes" 是什么意思呢?
214+
`ExampleReverse` 示例函数 "passes" 是什么意思呢?
223215

224216
.html _tr/div_end.html
225217

@@ -234,7 +226,7 @@ The test passes if the test's output matches its output comment.
234226

235227
.html _tr/div_begin_zh_CN.html
236228

237-
在执行实例函数时, 测试框架会捕获写到标准输出的数据, 然后和 "Output:" 输出注释比较 (译注: "Output:" 开头的注释为输出注释).
229+
在执行示例函数时, 测试框架会捕获写到标准输出的数据, 然后和 "Output:" 输出注释比较 (译注: "Output:" 开头的注释为输出注释).
238230
测试通过表示示例函数的输出和 "Output:" 输出注释一致.
239231

240232
.html _tr/div_end.html
@@ -252,13 +244,13 @@ obviously incorrect
252244

253245
.html _tr/div_end.html
254246

255-
.html _tr/div_begin_en.html
256-
257247
func ExampleReverse() {
258248
fmt.Println(stringutil.Reverse("hello"))
259249
// Output: golly
260250
}
261251

252+
.html _tr/div_begin_en.html
253+
262254
and run the tests again:
263255

264256
.html _tr/div_end.html
@@ -289,14 +281,10 @@ If we remove the output comment entirely
289281

290282
.html _tr/div_end.html
291283

292-
.html _tr/div_begin_en.html
293-
294284
func ExampleReverse() {
295285
fmt.Println(stringutil.Reverse("hello"))
296286
}
297287

298-
.html _tr/div_end.html
299-
300288
.html _tr/div_begin_en.html
301289

302290
then the example function is compiled but not executed:
@@ -318,14 +306,14 @@ then the example function is compiled but not executed:
318306
.html _tr/div_begin_en.html
319307

320308
Examples without output comments are useful for demonstrating code that cannot
321-
run as unit tests, such as that which accesses the network,
309+
run as unit tests, such as that which accesses the network,
322310
while guaranteeing the example at least compiles.
323311

324312
.html _tr/div_end.html
325313

326314
.html _tr/div_begin_zh_CN.html
327315

328-
不带输出注释的示例函数适合用来写不需要运行的演示代码, 比如需要访问网络情况,
316+
不带输出注释的示例函数适合用来写不方便运行的演示代码, 比如需要访问网络情况,
329317
但是它至少可以保证示例代码是可以被编译的.
330318

331319
.html _tr/div_end.html
@@ -366,7 +354,7 @@ Godoc的示例函数的命名有一个约定.
366354
.html _tr/div_begin_zh_CN.html
367355

368356
func ExampleFoo() // Foo 函数 或 类型
369-
func ExampleBar_Qux() // Qux 类型的 Bar 方法x
357+
func ExampleBar_Qux() // 返回 Qux 类型的 Bar 方法
370358
func Example() // 整个包
371359

372360
.html _tr/div_end.html
@@ -399,14 +387,10 @@ Each of these examples documents the `Reverse` function:
399387

400388
.html _tr/div_end.html
401389

402-
.html _tr/div_begin_en.html
403-
404390
func ExampleReverse()
405391
func ExampleReverse_second()
406392
func ExampleReverse_third()
407393

408-
.html _tr/div_end.html
409-
410394
.html _tr/div_begin_en.html
411395

412396
* Larger examples
@@ -434,7 +418,7 @@ Sometimes we need more than just a function to write a good example.
434418
.html _tr/div_begin_en.html
435419

436420
For instance, to demonstrate the [[https://golang.org/pkg/sort/][`sort` package]]
437-
we should show an implementation of `sort.Interface`.
421+
we should show an implementation of `sort.Interface`.
438422
Since methods cannot be declared inside a function body, the example must
439423
include some context in addition to the example function.
440424

@@ -444,7 +428,7 @@ include some context in addition to the example function.
444428

445429
例如, 要演示 [[https://golang.org/pkg/sort/][`sort` 包]], 我们需要同时展示
446430
`sort.Interface` 接口的实现.
447-
但是在函数中我们无法定义方法, 这个例子必须依赖一些函数外部的相关代码.
431+
但是在函数中我们无法定义方法, 因此这个例子必须依赖一些函数外部的相关代码.
448432

449433
.html _tr/div_end.html
450434

@@ -478,8 +462,6 @@ Here is a whole file example from the `sort` package:
478462

479463
.html _tr/div_end.html
480464

481-
.html _tr/div_begin_en.html
482-
483465
package sort_test
484466

485467
import (
@@ -522,8 +504,6 @@ Here is a whole file example from the `sort` package:
522504
}
523505

524506

525-
.html _tr/div_end.html
526-
527507
.html _tr/div_begin_en.html
528508

529509
A package can contain multiple whole file examples; one example per file.
@@ -562,9 +542,7 @@ Use them!
562542
.html _tr/div_begin_zh_CN.html
563543

564544
Godoc 示例功能的一个伟大之处是以文档的方式来编写和维护代码.
565-
他们给用户展示了可编辑/可工作/可运行的示例.
566-
使用他们吧!
545+
它们给用户展示了可编辑/可工作/可运行的示例.
546+
使用它们吧!
567547

568548
.html _tr/div_end.html
569-
570-

0 commit comments

Comments
 (0)