mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
add mock hashes
Summary: These get pretty annoying to construct in tests. `mercurial-types-mocks` seems like a great place to have them. I ended up using the `const_fn` feature for convenience. Reviewed By: StanislavGlebik Differential Revision: D5898773 fbshipit-source-id: f9ead4e7720ed8ffb0535826603656ff7115b6e4
This commit is contained in:
parent
5961c7558a
commit
286b04bbd6
100
mercurial-types/mocks/hash.rs
Normal file
100
mercurial-types/mocks/hash.rs
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright (c) 2017-present, Facebook, Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// This software may be used and distributed according to the terms of the
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
// NULL is exported for convenience.
|
||||
pub use mercurial_types::hash::NULL;
|
||||
use mercurial_types::hash::Sha1;
|
||||
|
||||
// Definitions for hashes 1111...1111 to ffff...ffff.
|
||||
|
||||
pub const ONES: Sha1 = Sha1::from_byte_array([0x11; 20]);
|
||||
pub const TWOS: Sha1 = Sha1::from_byte_array([0x22; 20]);
|
||||
pub const THREES: Sha1 = Sha1::from_byte_array([0x33; 20]);
|
||||
pub const FOURS: Sha1 = Sha1::from_byte_array([0x44; 20]);
|
||||
pub const FIVES: Sha1 = Sha1::from_byte_array([0x55; 20]);
|
||||
pub const SIXES: Sha1 = Sha1::from_byte_array([0x66; 20]);
|
||||
pub const SEVENS: Sha1 = Sha1::from_byte_array([0x77; 20]);
|
||||
pub const EIGHTS: Sha1 = Sha1::from_byte_array([0x88; 20]);
|
||||
pub const NINES: Sha1 = Sha1::from_byte_array([0x99; 20]);
|
||||
pub const AS: Sha1 = Sha1::from_byte_array([0xaa; 20]);
|
||||
pub const BS: Sha1 = Sha1::from_byte_array([0xbb; 20]);
|
||||
pub const CS: Sha1 = Sha1::from_byte_array([0xcc; 20]);
|
||||
pub const DS: Sha1 = Sha1::from_byte_array([0xdd; 20]);
|
||||
pub const ES: Sha1 = Sha1::from_byte_array([0xee; 20]);
|
||||
pub const FS: Sha1 = Sha1::from_byte_array([0xff; 20]);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn verify() {
|
||||
assert_eq!(
|
||||
format!("{}", NULL),
|
||||
"0000000000000000000000000000000000000000"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", ONES),
|
||||
"1111111111111111111111111111111111111111"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", TWOS),
|
||||
"2222222222222222222222222222222222222222"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", THREES),
|
||||
"3333333333333333333333333333333333333333"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", FOURS),
|
||||
"4444444444444444444444444444444444444444"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", FIVES),
|
||||
"5555555555555555555555555555555555555555"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", SIXES),
|
||||
"6666666666666666666666666666666666666666"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", SEVENS),
|
||||
"7777777777777777777777777777777777777777"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", EIGHTS),
|
||||
"8888888888888888888888888888888888888888"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", NINES),
|
||||
"9999999999999999999999999999999999999999"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", AS),
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", BS),
|
||||
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", CS),
|
||||
"cccccccccccccccccccccccccccccccccccccccc"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", DS),
|
||||
"dddddddddddddddddddddddddddddddddddddddd"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", ES),
|
||||
"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", FS),
|
||||
"ffffffffffffffffffffffffffffffffffffffff"
|
||||
);
|
||||
}
|
||||
}
|
@ -5,9 +5,12 @@
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
#![deny(warnings)]
|
||||
#![feature(const_fn)]
|
||||
|
||||
extern crate futures;
|
||||
extern crate futures_ext;
|
||||
extern crate mercurial_types;
|
||||
|
||||
pub mod hash;
|
||||
pub mod manifest;
|
||||
pub mod nodehash;
|
||||
|
28
mercurial-types/mocks/nodehash.rs
Normal file
28
mercurial-types/mocks/nodehash.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2017-present, Facebook, Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// This software may be used and distributed according to the terms of the
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
// NULL_HASH is exported for convenience.
|
||||
pub use mercurial_types::NULL_HASH;
|
||||
use mercurial_types::NodeHash;
|
||||
|
||||
use hash;
|
||||
|
||||
// Definitions for hashes 1111...ffff.
|
||||
pub const ONES_HASH: NodeHash = NodeHash::new(hash::ONES);
|
||||
pub const TWOS_HASH: NodeHash = NodeHash::new(hash::TWOS);
|
||||
pub const THREES_HASH: NodeHash = NodeHash::new(hash::THREES);
|
||||
pub const FOURS_HASH: NodeHash = NodeHash::new(hash::FOURS);
|
||||
pub const FIVES_HASH: NodeHash = NodeHash::new(hash::FIVES);
|
||||
pub const SIXES_HASH: NodeHash = NodeHash::new(hash::SIXES);
|
||||
pub const SEVENS_HASH: NodeHash = NodeHash::new(hash::SEVENS);
|
||||
pub const EIGHTS_HASH: NodeHash = NodeHash::new(hash::EIGHTS);
|
||||
pub const NINES_HASH: NodeHash = NodeHash::new(hash::NINES);
|
||||
pub const AS_HASH: NodeHash = NodeHash::new(hash::AS);
|
||||
pub const BS_HASH: NodeHash = NodeHash::new(hash::BS);
|
||||
pub const CS_HASH: NodeHash = NodeHash::new(hash::CS);
|
||||
pub const DS_HASH: NodeHash = NodeHash::new(hash::DS);
|
||||
pub const ES_HASH: NodeHash = NodeHash::new(hash::ES);
|
||||
pub const FS_HASH: NodeHash = NodeHash::new(hash::FS);
|
@ -40,6 +40,12 @@ impl Sha1 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a `Sha1` from an array of 20 bytes.
|
||||
#[inline]
|
||||
pub const fn from_byte_array(arr: [u8; 20]) -> Sha1 {
|
||||
Sha1(arr)
|
||||
}
|
||||
|
||||
/// Construct a `Sha1` from a hex-encoded `AsciiStr`.
|
||||
#[inline]
|
||||
pub fn from_ascii_str(s: &AsciiStr) -> Result<Sha1> {
|
||||
|
@ -5,6 +5,7 @@
|
||||
// GNU General Public License version 2 or any later version.
|
||||
|
||||
#![deny(warnings)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(never_type)]
|
||||
|
||||
extern crate ascii;
|
||||
|
@ -24,7 +24,7 @@ pub const NULL_HASH: NodeHash = NodeHash(hash::NULL);
|
||||
pub struct NodeHash(Sha1);
|
||||
|
||||
impl NodeHash {
|
||||
pub fn new(sha1: Sha1) -> NodeHash {
|
||||
pub const fn new(sha1: Sha1) -> NodeHash {
|
||||
NodeHash(sha1)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user