This commit is contained in:
Mateusz Gruszczyński committed 2026-10-12 11:22:42 +02:00
1 parent 68ada6680d
commit 180a0e4877
56 files changed
+9866 -205

No files matched your search

+18
View File
@@ -1,6 +1,24 @@
mod tests {
use super::*;
#[test]
fn compact_ipv6_ranges_preserve_numeric_order() {
assert_eq!(std::mem::size_of::<V6Range>(), 34);
assert_eq!(std::mem::size_of::<V4Range>(), 12);
let ranges = [
V6Range { start: 0u128.to_be_bytes(), end: 127u128.to_be_bytes(), country: *b"PL" },
V6Range { start: 256u128.to_be_bytes(), end: 65535u128.to_be_bytes(), country: *b"DE" },
V6Range { start: (1u128 << 120).to_be_bytes(), end: u128::MAX.to_be_bytes(), country: *b"US" },
];
for (address, expected) in [
(0, Some(*b"PL")), (127, Some(*b"PL")), (128, None),
(255, None), (256, Some(*b"DE")), (65535, Some(*b"DE")),
(65536, None), (1u128 << 120, Some(*b"US")), (u128::MAX, Some(*b"US")),
] {
assert_eq!(find_v6(&ranges, address.to_be_bytes()), expected);
}
}
#[test]
fn range_lookup_handles_gaps() {
let directory = tempfile::tempdir().unwrap();