Skip to content

Commit ef50d6d

Browse files
committed
Fixed error message for too long hrp.
1 parent c2aac49 commit ef50d6d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/primitives/hrp.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl fmt::Display for Error {
393393
use Error::*;
394394

395395
match *self {
396-
TooLong(len) => write!(f, "hrp is too long, found {} characters, must be <= 126", len),
396+
TooLong(len) => write!(f, "hrp is too long, found {} characters, must be <= {}", len, MAX_HRP_LEN),
397397
Empty => write!(f, "hrp is empty, must have at least 1 character"),
398398
NonAsciiChar(c) => write!(f, "found non-ASCII character: {}", c),
399399
InvalidAsciiByte(b) => write!(f, "byte value is not valid US-ASCII: \'{:x}\'", b),
@@ -537,4 +537,13 @@ mod tests {
537537
let hrp = Hrp::parse_unchecked(s);
538538
assert_eq!(hrp.as_bytes(), s.as_bytes());
539539
}
540+
541+
#[test]
542+
fn error_messages() {
543+
assert_eq!("hrp is too long, found 92 characters, must be <= 83", Error::TooLong(92).to_string());
544+
assert_eq!("hrp is empty, must have at least 1 character", Error::Empty.to_string());
545+
assert_eq!("found non-ASCII character: 😊", Error::NonAsciiChar('😊').to_string());
546+
assert_eq!("byte value is not valid US-ASCII: 'ff'", Error::InvalidAsciiByte(255).to_string());
547+
assert_eq!("hrp cannot mix upper and lower case", Error::MixedCase.to_string());
548+
}
540549
}

0 commit comments

Comments
 (0)