diff --git a/src/parsers/mod.rs b/src/parsers/mod.rs index 3e46529..4c39b88 100644 --- a/src/parsers/mod.rs +++ b/src/parsers/mod.rs @@ -235,6 +235,8 @@ impl BencodeParser { #[cfg(test)] mod tests { + use crate::parsers::error::Error; + use super::{error, BencodeParser}; #[test] @@ -297,7 +299,10 @@ mod tests { let result = parse(invalid_bencoded_value); - assert!(result.is_err()); + assert!(matches!( + result, + Err(Error::UnrecognizedFirstBencodeValueByte(97, 'a')) + )); } #[test] @@ -307,11 +312,17 @@ mod tests { let result = parse(integer_with_missing_end_byte); - assert!(result.is_err()); + assert!(matches!( + result, + Err(Error::UnexpectedEndOfInputParsingInteger) + )); } mod integers { - use crate::parsers::tests::{parse, to_json}; + use crate::parsers::{ + error::Error, + tests::{parse, to_json}, + }; #[test] fn zero() { @@ -342,7 +353,10 @@ mod tests { let result = parse(int_with_invalid_byte); - assert!(result.is_err()); + assert!(matches!( + result, + Err(Error::UnexpectedByteParsingInteger(97, 'a')) + )); } } @@ -402,7 +416,10 @@ mod tests { } mod lists { - use crate::parsers::tests::{parse, to_json}; + use crate::parsers::{ + error::Error, + tests::{parse, to_json}, + }; #[test] fn empty_list() { @@ -415,7 +432,10 @@ mod tests { let result = parse(end_list_byte_without_start); - assert!(result.is_err()); + assert!(matches!( + result, + Err(Error::NoMatchingStartForListOrDictEnd) + )); } mod with_one_item { @@ -559,7 +579,10 @@ mod tests { } mod dictionary { - use crate::parsers::tests::{parse, to_json}; + use crate::parsers::{ + error::Error, + tests::{parse, to_json}, + }; // Note: Keys must be bencoded strings. @@ -582,7 +605,10 @@ mod tests { let result = parse(end_dict_byte_without_start); - assert!(result.is_err()); + assert!(matches!( + result, + Err(Error::NoMatchingStartForListOrDictEnd) + )); } #[test] @@ -591,7 +617,7 @@ mod tests { let result = parse(dict_with_missing_key_value); - assert!(result.is_err()); + assert!(matches!(result, Err(Error::PrematureEndOfDict))); } mod with_one_key {