Skip to content

Commit bc32d39

Browse files
committed
convert blockhash doctest to api test
1 parent c278f3e commit bc32d39

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

src/blockhash.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,7 @@ use crate::*;
2828
/// The hash of a block of body data.
2929
///
3030
/// Stored in memory as compact bytes, but translatable to and from
31-
/// hex strings.o
32-
///
33-
/// ```
34-
/// use std::str::FromStr;
35-
/// use conserve::blockhash::BlockHash;
36-
///
37-
/// let hex_hash = concat!(
38-
/// "00000000000000000000000000000000",
39-
/// "00000000000000000000000000000000",
40-
/// "00000000000000000000000000000000",
41-
/// "00000000000000000000000000000000",);
42-
/// let hash = BlockHash::from_str(hex_hash)
43-
/// .unwrap();
44-
/// let hash2 = hash.clone();
45-
/// assert_eq!(hash2.to_string(), hex_hash);
46-
/// ```
31+
/// hex strings.
4732
#[derive(Clone, Deserialize, Serialize)]
4833
#[serde(into = "String")]
4934
#[serde(try_from = "&str")]

tests/api/blockhash.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Conserve backup system.
2+
// Copyright 2015, 2016, 2017, 2018, 2019, 2020 Martin Pool.
3+
4+
// This program is free software; you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation; either version 2 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
use conserve::blockhash::BlockHash;
15+
use std::str::FromStr;
16+
17+
#[test]
18+
fn to_from_string() {
19+
let hex_hash = concat!(
20+
"00000000000000000000000000000000",
21+
"00000000000000000000000000000000",
22+
"00000000000000000000000000000000",
23+
"00000000000000000000000000000000",
24+
);
25+
let hash = BlockHash::from_str(hex_hash).unwrap();
26+
let hash2 = hash.clone();
27+
assert_eq!(hash2.to_string(), hex_hash);
28+
}

tests/api/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
1515
mod apath;
1616
mod backup;
17+
mod blockhash;
1718
mod damaged;
1819
mod delete;
19-
mod restore;
20-
mod old_archives;
2120
mod gc;
21+
mod old_archives;
22+
mod restore;

0 commit comments

Comments
 (0)