Skip to content

Commit 76427c1

Browse files
author
wayslog
committed
bug fixed for gitbook
1 parent fd37d36 commit 76427c1

3 files changed

Lines changed: 38 additions & 41 deletions

File tree

06-flow/06-01-comment.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn add_one(x: i32) -> i32 {
4545

4646
模块注释使用 ```//!```,用于说明本模块的功能。一般置于模块文件的头部。
4747

48-
```
48+
```rust
4949
//! # The Rust Standard Library
5050
//!
5151
//! The Rust Standard Library provides the essential runtime
@@ -59,12 +59,10 @@ PS: 相对于 `///`, `//!` 用来注释包含它的项(也就是说,crate,
5959

6060
Rust 也支持兼容 C 的块注释写法:`/* */`。但是不推荐使用,请尽量不要使用这种注释风格(会被鄙视的)。
6161

62-
```
62+
```rust
6363
/*
6464
let x = 42;
6565
println!("{}", x);
6666
6767
*/
68-
69-
7068
```

28-cargo-detailed-cfg/28-01-cargo-detailed-cfg.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,3 @@ plugin = false
275275
# 如果设置为false,`cargo test`将会忽略传递给rustc的--test参数。
276276
harness = true
277277
```
278-
##

29-testing/29-01-threearchtest.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $ cd adder
2626
### `#[test]` 标识
2727
打开 `src/lib,rs` 文件,可以看到如下代码
2828

29-
```
29+
```rust
3030
#[test]
3131
fn it_works() {
3232
// do test work
@@ -56,13 +56,13 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
5656

5757
Rust 提供了两个宏来执行测试断言:
5858

59-
```
59+
```rust
6060
assert!(expr) 测试表达式是否为 truefalse
6161
assert_eq!(expr, expr) 测试两个表达式的结果是否相等
6262
```
6363
比如
6464

65-
```
65+
```rust
6666
#[test]
6767
fn it_works() {
6868
assert!(false);
@@ -98,7 +98,7 @@ thread '<main>' panicked at 'Some tests failed', /home/steve/src/rust/src/libtes
9898
如果你的测试函数没完成,或没有更新,或是故意让它崩溃,但为了让测试能够顺利完成,我们主动可以给测试函数加上 `#[should_panic]` 标识,就不会让 `cargo test` 报错了。
9999

100100
101-
```
101+
```rust
102102
#[test]
103103
#[should_panic]
104104
fn it_works() {
@@ -129,7 +129,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
129129

130130
有时候,某个测试函数非常耗时,或暂时没更新,我们想不让它参与测试,但是又不想删除它,这时, `#[ignore]` 就派上用场了。
131131

132-
```
132+
```rust
133133
#[test]
134134
#[ignore]
135135
fn expensive_test() {
@@ -142,7 +142,7 @@ fn expensive_test() {
142142
## 模块级
143143

144144
有时,我们会组织一批测试用例,这时,模块化的组织结构就有助于建立结构性的测试体系。Rust 中,可以类似如下写法:
145-
```
145+
```rust
146146
pub fn add_two(a: i32) -> i32 {
147147
a + 2
148148
}
@@ -178,7 +178,7 @@ tests
178178

179179
我们在 tests 目录下,建立一个文件 `testit.rs` ,名字随便取皆可。内容为:
180180

181-
```
181+
```rust
182182
extern crate adder;
183183

184184
#[test]
@@ -221,38 +221,38 @@ Rust 对文档的哲学,是不要单独写文档,一是代码本身是文档
221221

222222
比如,我们给上面库加点文档:
223223

224-
```
225-
//! The `adder` crate provides functions that add numbers to other numbers.
226-
//!
227-
//! # Examples
228-
//!
229-
//! ```
230-
//! assert_eq!(4, adder::add_two(2));
231-
//! ```
232-
233-
/// This function adds two to its argument.
234-
///
235-
/// # Examples
236-
///
237-
/// ```
238-
/// use adder::add_two;
239-
///
240-
/// assert_eq!(4, add_two(2));
241-
/// ```
242-
pub fn add_two(a: i32) -> i32 {
243-
a + 2
244-
}
224+
//! The `adder` crate provides functions that add numbers to other numbers.
225+
//!
226+
//! # Examples
227+
//!
228+
//! ```
229+
//! assert_eq!(4, adder::add_two(2));
230+
//! ```
231+
232+
/// This function adds two to its argument.
233+
///
234+
/// # Examples
235+
///
236+
/// ```
237+
/// use adder::add_two;
238+
///
239+
/// assert_eq!(4, add_two(2));
240+
/// ```
241+
242+
pub fn add_two(a: i32) -> i32 {
243+
a + 2
244+
}
245245

246-
#[cfg(test)]
247-
mod tests {
248-
use super::*;
246+
#[cfg(test)]
247+
mod tests {
248+
use super::*;
249249

250-
#[test]
251-
fn it_works() {
252-
assert_eq!(4, add_two(2));
250+
#[test]
251+
fn it_works() {
252+
assert_eq!(4, add_two(2));
253+
}
253254
}
254-
}
255-
```
255+
256256

257257
运行 `cargo test`,结果如下:
258258

0 commit comments

Comments
 (0)