Skip to content

Commit 203e567

Browse files
committed
fix(#1904): update doc tests to use playground as the crate name
This updates the Documentation Testing (21.2) chapter to assume a crate name of `playground` instead of `doccomments`. This allows for the code contained within to be copy-pasted directly into play.rust-lang.org to run; anyone who would want to reproduce this locally would want to create a `playground` library. Fixes #1904.
1 parent 21f4e32 commit 203e567

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

po/es.po

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14221,11 +14221,12 @@ msgid ""
1422114221
"///\n"
1422214222
"/// The next lines present detailed documentation. Code blocks start with\n"
1422314223
"/// triple backquotes and have implicit `fn main()` inside\n"
14224-
"/// and `extern crate <cratename>`. Assume we're testing `doccomments` "
14224+
"/// and `extern crate <cratename>`. Assume we're testing a `playground` library\n"
14225+
"/// crate or using the Playground's Test action:\n"
1422514226
"crate:\n"
1422614227
"///\n"
1422714228
"/// ```\n"
14228-
"/// let result = doccomments::add(2, 3);\n"
14229+
"/// let result = playground::add(2, 3);\n"
1422914230
"/// assert_eq!(result, 5);\n"
1423014231
"/// ```\n"
1423114232
msgstr ""
@@ -14240,7 +14241,7 @@ msgid ""
1424014241
"/// # Examples\n"
1424114242
"///\n"
1424214243
"/// ```\n"
14243-
"/// let result = doccomments::div(10, 2);\n"
14244+
"/// let result = playground::div(10, 2);\n"
1424414245
"/// assert_eq!(result, 5);\n"
1424514246
"/// ```\n"
1424614247
"///\n"
@@ -14250,7 +14251,7 @@ msgid ""
1425014251
"///\n"
1425114252
"/// ```rust,should_panic\n"
1425214253
"/// // panics on division by zero\n"
14253-
"/// doccomments::div(10, 0);\n"
14254+
"/// playground::div(10, 0);\n"
1425414255
"/// ```\n"
1425514256
msgstr ""
1425614257

@@ -14285,7 +14286,7 @@ msgid ""
1428514286
"/// # // hidden lines start with `#` symbol, but they're still compilable!\n"
1428614287
"/// # fn try_main() -> Result<(), String> { // line that wraps the body "
1428714288
"shown in doc\n"
14288-
"/// let res = doccomments::try_div(10, 2)?;\n"
14289+
"/// let res = playground::try_div(10, 2)?;\n"
1428914290
"/// # Ok(()) // returning from try_main\n"
1429014291
"/// # }\n"
1429114292
"/// # fn main() { // starting main that'll unwrap()\n"

po/ja.po

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16185,11 +16185,12 @@ msgid ""
1618516185
"///\n"
1618616186
"/// The next lines present detailed documentation. Code blocks start with\n"
1618716187
"/// triple backquotes and have implicit `fn main()` inside\n"
16188-
"/// and `extern crate <cratename>`. Assume we're testing `doccomments` "
16188+
"/// and `extern crate <cratename>`. Assume we're testing a `playground` library\n"
16189+
"/// crate or using the Playground's Test action:\n"
1618916190
"crate:\n"
1619016191
"///\n"
1619116192
"/// ```\n"
16192-
"/// let result = doccomments::add(2, 3);\n"
16193+
"/// let result = playground::add(2, 3);\n"
1619316194
"/// assert_eq!(result, 5);\n"
1619416195
"/// ```\n"
1619516196
msgstr ""
@@ -16198,10 +16199,10 @@ msgstr ""
1619816199
"/// 以降で詳細なドキュメンテーションを記述します。コードブロックは三重のバッ"
1619916200
"ククォートで始まり、\n"
1620016201
"/// 暗黙的に`fn main()`と`extern crate <クレート名>`で囲われます。\n"
16201-
"/// `doccomments`クレートをテストしたいときには、次のように記述します。\n"
16202+
"/// `playground`クレートをテストしたいときには、次のように記述します。\n"
1620216203
"///\n"
1620316204
"/// ```\n"
16204-
"/// let result = doccomments::add(2, 3);\n"
16205+
"/// let result = playground::add(2, 3);\n"
1620516206
"/// assert_eq!(result, 5);\n"
1620616207
"/// ```\n"
1620716208

@@ -16215,7 +16216,7 @@ msgid ""
1621516216
"/// # Examples\n"
1621616217
"///\n"
1621716218
"/// ```\n"
16218-
"/// let result = doccomments::div(10, 2);\n"
16219+
"/// let result = playground::div(10, 2);\n"
1621916220
"/// assert_eq!(result, 5);\n"
1622016221
"/// ```\n"
1622116222
"///\n"
@@ -16225,7 +16226,7 @@ msgid ""
1622516226
"///\n"
1622616227
"/// ```rust,should_panic\n"
1622716228
"/// // panics on division by zero\n"
16228-
"/// doccomments::div(10, 0);\n"
16229+
"/// playground::div(10, 0);\n"
1622916230
"/// ```\n"
1623016231
msgstr ""
1623116232
"/// 一般的に、ドキュメンテーションコメントは\n"
@@ -16236,7 +16237,7 @@ msgstr ""
1623616237
"/// # Examples\n"
1623716238
"///\n"
1623816239
"/// ```\n"
16239-
"/// let result = doccomments::div(10, 2);\n"
16240+
"/// let result = playground::div(10, 2);\n"
1624016241
"/// assert_eq!(result, 5);\n"
1624116242
"/// ```\n"
1624216243
"///\n"
@@ -16246,7 +16247,7 @@ msgstr ""
1624616247
"///\n"
1624716248
"/// ```rust,should_panic\n"
1624816249
"/// // ゼロで除算するとパニックします\n"
16249-
"/// doccomments::div(10, 0);\n"
16250+
"/// playground::div(10, 0);\n"
1625016251
"/// ```\n"
1625116252

1625216253
#: src/testing/doc_testing.md:52
@@ -16291,7 +16292,7 @@ msgid ""
1629116292
"/// # // hidden lines start with `#` symbol, but they're still compilable!\n"
1629216293
"/// # fn try_main() -> Result<(), String> { // line that wraps the body "
1629316294
"shown in doc\n"
16294-
"/// let res = doccomments::try_div(10, 2)?;\n"
16295+
"/// let res = playground::try_div(10, 2)?;\n"
1629516296
"/// # Ok(()) // returning from try_main\n"
1629616297
"/// # }\n"
1629716298
"/// # fn main() { // starting main that'll unwrap()\n"
@@ -16305,7 +16306,7 @@ msgstr ""
1630516306
"/// ```\n"
1630616307
"/// # // 行頭に `#` を置くと行が隠されるが、コンパイルには成功します。\n"
1630716308
"/// # fn try_main() -> Result<(), String> { // ドキュメントの本体を囲う行\n"
16308-
"/// let res = doccomments::try_div(10, 2)?;\n"
16309+
"/// let res = playground::try_div(10, 2)?;\n"
1630916310
"/// # Ok(()) // try_mainから値を返します\n"
1631016311
"/// # }\n"
1631116312
"/// # fn main() { // unwrap()を実行します。\n"

po/zh.po

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15454,22 +15454,23 @@ msgid ""
1545415454
"///\n"
1545515455
"/// The next lines present detailed documentation. Code blocks start with\n"
1545615456
"/// triple backquotes and have implicit `fn main()` inside\n"
15457-
"/// and `extern crate <cratename>`. Assume we're testing `doccomments` "
15457+
"/// and `extern crate <cratename>`. Assume we're testing a `playground` library\n"
15458+
"/// crate or using the Playground's Test action:\n"
1545815459
"crate:\n"
1545915460
"///\n"
1546015461
"/// ```\n"
15461-
"/// let result = doccomments::add(2, 3);\n"
15462+
"/// let result = playground::add(2, 3);\n"
1546215463
"/// assert_eq!(result, 5);\n"
1546315464
"/// ```\n"
1546415465
msgstr ""
1546515466
"/// 第一行是函数的简要描述。\n"
1546615467
"///\n"
1546715468
"/// 接下来的几行是详细文档。代码块以三个反引号开始,\n"
1546815469
"/// 并隐含了 `fn main()` 函数和 `extern crate <cratename>` 声明。\n"
15469-
"/// 假设我们正在测试 `doccomments` crate:\n"
15470+
"/// 假设我们正在测试 `playground` crate:\n"
1547015471
"///\n"
1547115472
"/// ```\n"
15472-
"/// let result = doccomments::add(2, 3);\n"
15473+
"/// let result = playground::add(2, 3);\n"
1547315474
"/// assert_eq!(result, 5);\n"
1547415475
"/// ```\n"
1547515476

@@ -15483,7 +15484,7 @@ msgid ""
1548315484
"/// # Examples\n"
1548415485
"///\n"
1548515486
"/// ```\n"
15486-
"/// let result = doccomments::div(10, 2);\n"
15487+
"/// let result = playground::div(10, 2);\n"
1548715488
"/// assert_eq!(result, 5);\n"
1548815489
"/// ```\n"
1548915490
"///\n"
@@ -15493,7 +15494,7 @@ msgid ""
1549315494
"///\n"
1549415495
"/// ```rust,should_panic\n"
1549515496
"/// // panics on division by zero\n"
15496-
"/// doccomments::div(10, 0);\n"
15497+
"/// playground::div(10, 0);\n"
1549715498
"/// ```\n"
1549815499
msgstr ""
1549915500
"/// 文档注释通常包含"示例"、"异常"和"错误"等部分。\n"
@@ -15503,7 +15504,7 @@ msgstr ""
1550315504
"/// # 示例\n"
1550415505
"///\n"
1550515506
"/// ```\n"
15506-
"/// let result = doccomments::div(10, 2);\n"
15507+
"/// let result = playground::div(10, 2);\n"
1550715508
"/// assert_eq!(result, 5);\n"
1550815509
"/// ```\n"
1550915510
"///\n"
@@ -15513,7 +15514,7 @@ msgstr ""
1551315514
"///\n"
1551415515
"/// ```rust,should_panic\n"
1551515516
"/// // 除以零会触发异常\n"
15516-
"/// doccomments::div(10, 0);\n"
15517+
"/// playground::div(10, 0);\n"
1551715518
"/// ```\n"
1551815519

1551915520
#: src/testing/doc_testing.md:52
@@ -15549,7 +15550,7 @@ msgid ""
1554915550
"/// # // hidden lines start with `#` symbol, but they're still compilable!\n"
1555015551
"/// # fn try_main() -> Result<(), String> { // line that wraps the body shown "
1555115552
"in doc\n"
15552-
"/// let res = doccomments::try_div(10, 2)?;\n"
15553+
"/// let res = playground::try_div(10, 2)?;\n"
1555315554
"/// # Ok(()) // returning from try_main\n"
1555415555
"/// # }\n"
1555515556
"/// # fn main() { // starting main that'll unwrap()\n"
@@ -15563,7 +15564,7 @@ msgstr ""
1556315564
"/// ```\n"
1556415565
"/// # // 以 `#` 开头的行在文档中是隐藏的,但它们仍然可以编译!\n"
1556515566
"/// # fn try_main() -> Result<(), String> { // 这行包装了文档中显示的函数体\n"
15566-
"/// let res = doccomments::try_div(10, 2)?;\n"
15567+
"/// let res = playground::try_div(10, 2)?;\n"
1556715568
"/// # Ok(()) // 从 try_main 返回\n"
1556815569
"/// # }\n"
1556915570
"/// # fn main() { // 开始会调用 unwrap() 的 main 函数\n"

src/testing/doc_testing.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ as documentation tests.
1111
///
1212
/// The next lines present detailed documentation. Code blocks start with
1313
/// triple backquotes and have implicit `fn main()` inside
14-
/// and `extern crate <cratename>`. Assume we're testing `doccomments` crate:
14+
/// and `extern crate <cratename>`. Assume we're testing a `playground` library
15+
/// crate or using the Playground's Test action:
1516
///
1617
/// ```
17-
/// let result = doccomments::add(2, 3);
18+
/// let result = playground::add(2, 3);
1819
/// assert_eq!(result, 5);
1920
/// ```
2021
pub fn add(a: i32, b: i32) -> i32 {
@@ -28,7 +29,7 @@ pub fn add(a: i32, b: i32) -> i32 {
2829
/// # Examples
2930
///
3031
/// ```
31-
/// let result = doccomments::div(10, 2);
32+
/// let result = playground::div(10, 2);
3233
/// assert_eq!(result, 5);
3334
/// ```
3435
///
@@ -38,7 +39,7 @@ pub fn add(a: i32, b: i32) -> i32 {
3839
///
3940
/// ```rust,should_panic
4041
/// // panics on division by zero
41-
/// doccomments::div(10, 0);
42+
/// playground::div(10, 0);
4243
/// ```
4344
pub fn div(a: i32, b: i32) -> i32 {
4445
if b == 0 {
@@ -58,7 +59,7 @@ running 0 tests
5859

5960
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
6061

61-
Doc-tests doccomments
62+
Doc-tests playground
6263

6364
running 3 tests
6465
test src/lib.rs - add (line 7) ... ok
@@ -84,7 +85,7 @@ and `unwrap` it in hidden `main`. Sounds complicated? Here's an example:
8485
/// ```
8586
/// # // hidden lines start with `#` symbol, but they're still compilable!
8687
/// # fn try_main() -> Result<(), String> { // line that wraps the body shown in doc
87-
/// let res = doccomments::try_div(10, 2)?;
88+
/// let res = playground::try_div(10, 2)?;
8889
/// # Ok(()) // returning from try_main
8990
/// # }
9091
/// # fn main() { // starting main that'll unwrap()

0 commit comments

Comments
 (0)