commit bf9dc697fa39b2a3fea8bd57ba16797144ec47c5
Merge: d8280216c 574d59c64
Author: cypherpunks <cypherpunks(a)torproject.org>
Date: Fri Sep 14 02:33:59 2018 +0000
Merge branch 'rust-protokeyword1-034' into rust-protokeyword1-035
changes/bug27687 | 4 ++++
src/rust/protover/errors.rs | 4 ++++
src/rust/protover/protover.rs | 34 +++++++++++++++++++++++++++++++++-
3 files changed, 41 insertions(+), 1 deletion(-)
diff --cc src/rust/protover/errors.rs
index 71fbc53e1,d9dc73381..f26a48b01
--- a/src/rust/protover/errors.rs
+++ b/src/rust/protover/errors.rs
@@@ -24,30 -25,22 +25,33 @@@ pub enum ProtoverError
impl Display for ProtoverError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
- ProtoverError::Overlap
- => write!(f, "Two or more (low, high) protover ranges would overlap once expanded."),
- ProtoverError::LowGreaterThanHigh
- => write!(f, "The low in a (low, high) protover range was greater than high."),
- ProtoverError::Unparseable
- => write!(f, "The protover string was unparseable."),
- ProtoverError::ExceedsMax
- => write!(f, "The high in a (low, high) protover range exceeds u32::MAX."),
- ProtoverError::ExceedsExpansionLimit
- => write!(f, "The protover string would exceed the maximum expansion limit."),
- ProtoverError::UnknownProtocol
- => write!(f, "A protocol in the protover string we attempted to parse is unknown."),
- ProtoverError::ExceedsNameLimit
- => write!(f, "An unrecognised protocol name was too long."),
- ProtoverError::InvalidProtocol
- => write!(f, "A protocol name includes invalid characters."),
+ ProtoverError::Overlap => write!(
+ f,
+ "Two or more (low, high) protover ranges would overlap once expanded."
+ ),
+ ProtoverError::LowGreaterThanHigh => write!(
+ f,
+ "The low in a (low, high) protover range was greater than high."
+ ),
+ ProtoverError::Unparseable => write!(f, "The protover string was unparseable."),
+ ProtoverError::ExceedsMax => write!(
+ f,
+ "The high in a (low, high) protover range exceeds u32::MAX."
+ ),
+ ProtoverError::ExceedsExpansionLimit => write!(
+ f,
+ "The protover string would exceed the maximum expansion limit."
+ ),
+ ProtoverError::UnknownProtocol => write!(
+ f,
+ "A protocol in the protover string we attempted to parse is unknown."
+ ),
+ ProtoverError::ExceedsNameLimit => {
+ write!(f, "An unrecognised protocol name was too long.")
+ }
++ ProtoverError::InvalidProtocol => {
++ write!(f, "A protocol name includes invalid characters.")
++ }
}
}
}
diff --cc src/rust/protover/protover.rs
index 8f99a8a8e,0c23a8379..6fbe7c5dc
--- a/src/rust/protover/protover.rs
+++ b/src/rust/protover/protover.rs
@@@ -772,8 -771,31 +781,31 @@@ mod test
use super::*;
+ macro_rules! parse_proto {
+ ($e:expr) => {{
+ let proto: Result<UnknownProtocol, _> = $e.parse();
+ let proto2 = UnknownProtocol::from_str_any_len($e);
+ assert_eq!(proto, proto2);
+ proto
+ }};
+ }
+
+ #[test]
+ fn test_protocol_from_str() {
+ assert!(parse_proto!("Cons").is_ok());
+ assert!(parse_proto!("123").is_ok());
+ assert!(parse_proto!("1-2-3").is_ok());
+
+ let err = Err(ProtoverError::InvalidProtocol);
+ assert_eq!(err, parse_proto!("a_b_c"));
+ assert_eq!(err, parse_proto!("a b"));
+ assert_eq!(err, parse_proto!("a,"));
+ assert_eq!(err, parse_proto!("b."));
+ assert_eq!(err, parse_proto!("é"));
+ }
+
macro_rules! assert_protoentry_is_parseable {
- ($e:expr) => (
+ ($e:expr) => {
let protoentry: Result<ProtoEntry, ProtoverError> = $e.parse();
assert!(protoentry.is_ok(), format!("{:?}", protoentry.err()));