Skip to content

Commit

Permalink
Fixed error message for too long hrp.
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszDepta committed Mar 4, 2024
1 parent c2aac49 commit ef50d6d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/primitives/hrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl fmt::Display for Error {
use Error::*;

match *self {
TooLong(len) => write!(f, "hrp is too long, found {} characters, must be <= 126", len),
TooLong(len) => write!(f, "hrp is too long, found {} characters, must be <= {}", len, MAX_HRP_LEN),
Empty => write!(f, "hrp is empty, must have at least 1 character"),
NonAsciiChar(c) => write!(f, "found non-ASCII character: {}", c),
InvalidAsciiByte(b) => write!(f, "byte value is not valid US-ASCII: \'{:x}\'", b),
Expand Down Expand Up @@ -537,4 +537,13 @@ mod tests {
let hrp = Hrp::parse_unchecked(s);
assert_eq!(hrp.as_bytes(), s.as_bytes());
}

#[test]
fn error_messages() {
assert_eq!("hrp is too long, found 92 characters, must be <= 83", Error::TooLong(92).to_string());
assert_eq!("hrp is empty, must have at least 1 character", Error::Empty.to_string());
assert_eq!("found non-ASCII character: 😊", Error::NonAsciiChar('😊').to_string());
assert_eq!("byte value is not valid US-ASCII: 'ff'", Error::InvalidAsciiByte(255).to_string());
assert_eq!("hrp cannot mix upper and lower case", Error::MixedCase.to_string());
}
}

0 comments on commit ef50d6d

Please sign in to comment.