Add tests

Fix tests
This commit is contained in:
Terry Raimondo 2018-05-28 14:12:20 +02:00
parent 2033a1eb0e
commit b81fd202a0
No known key found for this signature in database
GPG key ID: 28F210B495D27D90
2 changed files with 10 additions and 5 deletions

View file

@ -204,10 +204,9 @@ impl<'a> DigitInfo<'a> {
.collect::<Vec<String>>()
.join("_");
// Forces hexadecimal values to be grouped by 4 being filled with zeroes (e.g 0x00ab_cdef)
let nb_digits_to_fill = self.digits.len() % 4;
let nb_digits_to_fill = self.digits.chars().filter(|&c| c != '_').collect::<Vec<_>>().len() % 4;
if self.radix == Radix::Hexadecimal && nb_digits_to_fill != 0 {
let filled_digits = format!("{:0>1$}", &hint[..nb_digits_to_fill], 4);
hint = format!("{}{}", filled_digits, &hint[nb_digits_to_fill..]);
hint = format!("{:0>4}{}", &hint[..nb_digits_to_fill], &hint[nb_digits_to_fill..]);
}
format!(
"{}{}{}",

View file

@ -30,9 +30,15 @@ fn main() {
let ok11 = 0o123;
let ok12 = 0b10_1010;
let ok6 = 0xab_abcd;
let ok7 = 0xBAFE_BAFE;
let ok13 = 0xab_abcd;
let ok14 = 0xBAFE_BAFE;
let ok15 = 0xab_cabc_abca_bcab_cabc;
let ok16 = 0xFE_BAFE_ABAB_ABCD;
let ok17 = 0x123_4567_8901_usize;
let fail9 = 0xabcdef;
let fail10 = 0xBAFEBAFE;
let fail11 = 0xabcdeff;
let fail12 = 0xabcabcabcabcabcabc;
let fail13 = 0x1_23456_78901_usize;
}