Skip to content

Commit

Permalink
Add unit test for overflow detection
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Jul 16, 2024
1 parent 9ee68c2 commit 7aa5658
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/turbo-tasks/src/id_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,21 @@ where
let _ = self.free_ids.push(id);
}
}

#[cfg(test)]
mod tests {
use std::num::NonZeroU8;

use super::*;

#[test]
#[should_panic(expected = "Overflow detected")]
fn test_overflow() {
let factory = IdFactory::<NonZeroU8>::new();
assert_eq!(factory.get(), NonZeroU8::new(1).unwrap());
assert_eq!(factory.get(), NonZeroU8::new(2).unwrap());
for _i in 2..256 {
factory.get();
}
}
}

0 comments on commit 7aa5658

Please sign in to comment.