Skip to content

Commit

Permalink
Adapt invalid_string tests to chars instead of bytes
Browse files Browse the repository at this point in the history
Formerly input strings were processed byte-wise, since it happens now character-wise the tests which result in Error::InvalidChar(c)'s had to be changed.
  • Loading branch information
sgeisler committed Jun 22, 2018
1 parent d9016f5 commit 866e15f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
#![deny(unused_mut)]

use std::{error, fmt};
use std::str::FromStr;
use std::ascii::AsciiExt;
use std::fmt::{Display, Formatter};
use std::str::FromStr;

/// Integer in the range `0..32`
#[derive(PartialEq, Eq, Debug, Copy, Clone, Default, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -249,9 +250,9 @@ impl Bech32 {
return Err(Error::InvalidChar(c))
}

if c.is_ascii_lowercase() {
if c.is_lowercase() {
has_lower = true;
} else if c.is_ascii_uppercase() {
} else if c.is_uppercase() {
has_upper = true;
}

Expand Down Expand Up @@ -540,8 +541,8 @@ mod tests {
let pairs: Vec<(&str, Error)> = vec!(
(" 1nwldj5",
Error::InvalidChar(' ')),
("\x7f1axkwrx",
Error::InvalidChar(0x7f as char)),
("abc1\u{2192}axkwrx",
Error::InvalidChar('\u{2192}')),
("an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx",
Error::InvalidLength),
("pzry9x0s0muk",
Expand All @@ -553,7 +554,7 @@ mod tests {
("li1dgmt3",
Error::InvalidLength),
("de1lg7wt\u{ff}",
Error::InvalidChar(0xc3 as char)), // ASCII 0xff -> \uC3BF in UTF-8
Error::InvalidChar('\u{ff}')),
);
for p in pairs {
let (s, expected_error) = p;
Expand All @@ -562,7 +563,7 @@ mod tests {
println!("{:?}", dec_result.unwrap());
panic!("Should be invalid: {:?}", s);
}
assert_eq!(dec_result.unwrap_err(), expected_error);
assert_eq!(dec_result.unwrap_err(), expected_error, "testing input '{}'", s);
}
}

Expand Down

0 comments on commit 866e15f

Please sign in to comment.