Skip to content

Commit

Permalink
Extend test_format_u8 to include u8::MAX
Browse files Browse the repository at this point in the history
This is equivalent to looping 0..=u8::MAX, except that `..=` syntax is
not supported on old rustc and `...` syntax is not supported on new
rustc, so loop it is.
  • Loading branch information
dtolnay committed Mar 22, 2021
1 parent 1bb23ad commit 72060b7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,17 @@ fn format_u8(mut n: u8, out: &mut [u8]) -> usize {
#[cfg(feature = "std")]
#[test]
fn test_format_u8() {
for i in 0..(u8::MAX as u16) {
let mut i = 0u8;

loop {
let mut buf = [0u8; 3];
let written = format_u8(i as u8, &mut buf);
let written = format_u8(i, &mut buf);
assert_eq!(i.to_string().as_bytes(), &buf[..written]);

match i.checked_add(1) {
Some(next) => i = next,
None => break,
}
}
}

Expand Down

0 comments on commit 72060b7

Please sign in to comment.