diff options
| author | phayes <[email protected]> | 2020-01-15 10:06:40 -0800 |
|---|---|---|
| committer | phayes <[email protected]> | 2020-01-15 10:06:40 -0800 |
| commit | c2f90dfdb0ce8b33626f4b3fd789188417c9eb7b (patch) | |
| tree | f7bbd2824caf03b4183a658214b6a1609ba40b67 /src | |
| parent | 3353f0e5a182e5d854fa7249fb711689fad29e68 (diff) | |
Adding tests for error conditions
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 2 | ||||
| -rw-r--r-- | src/test.rs | 9 |
2 files changed, 10 insertions, 1 deletions
@@ -114,7 +114,7 @@ const DERIVE_KEY_CONTEXT: u8 = 1 << 5; const DERIVE_KEY_MATERIAL: u8 = 1 << 6; /// Errors from parsing hex values -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ParseError { /// Hexadecimal str contains invalid character InvalidChar, diff --git a/src/test.rs b/src/test.rs index 6883c91..8c77c7f 100644 --- a/src/test.rs +++ b/src/test.rs @@ -465,4 +465,13 @@ fn test_hex_encoding_decoding() { // Test string parsing via FromStr let digest: crate::Hash = digest_str.parse().unwrap(); assert_eq!(digest.to_hex().as_str(), digest_str); + + // Test errors + let bad_len = "04e0bb39f30b1"; + let result = crate::Hash::from_hex(bad_len).unwrap_err(); + assert_eq!(result, crate::ParseError::InvalidLen); + + let bad_char = "Z4e0bb39f30b1a3feb89f536c93be15055482df748674b00d26e5a75777702e9"; + let result = crate::Hash::from_hex(bad_char).unwrap_err(); + assert_eq!(result, crate::ParseError::InvalidChar); } |
