Skip to content

Commit

Permalink
fix: fixed the unstuff length
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite committed Mar 25, 2021
1 parent a98c958 commit 6959b82
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub fn unstuff<const INPUT: usize, const OUTPUT: usize>(

// If we value is the marker, we know we have reached the end.
if value == marker {
break i;
break i - overhead_bytes - 1;
}

// If the current character is a marker or a overhead byte.
Expand Down Expand Up @@ -328,14 +328,14 @@ mod tests {
fn assert_unstuff(&self) {
assert_eq!(
unstuff::<M, N>(self.encoded_data, 0x00),
(self.unencoded_data, self.encoded_data.len())
(self.unencoded_data, self.unencoded_data.len())
);
}

fn assert_stuff_then_unstuff(&self) {
assert_eq!(
unstuff::<M, N>(stuff(self.unencoded_data, 0x00), 0x00),
(self.unencoded_data, self.encoded_data.len())
(self.unencoded_data, self.unencoded_data.len())
);
}

Expand Down Expand Up @@ -499,6 +499,15 @@ mod tests {
tv_8().assert_unstuff();
tv_9().assert_unstuff();
tv_10().assert_unstuff();

assert_eq!(
unstuff([0x01, 0x01, 0x00], 0x00),
([0x00, 0x00, 0x00, 0x00], 1)
);
assert_eq!(
unstuff([0x02, 0x01, 0x00], 0x00),
([0x01, 0x00, 0x00, 0x00], 1)
);
}

#[test]
Expand Down

0 comments on commit 6959b82

Please sign in to comment.