From 76a3eb4e4467a9d8346f1c89bcc61bd007d91bd0 Mon Sep 17 00:00:00 2001 From: juncheng Date: Sun, 25 Oct 2026 11:14:40 +0800 Subject: [PATCH] Test packed search across all widths --- tests/packed/tests_for_matching.rs | 6 ++++ .../tests_for_cross_word_boundaries.rs | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/packed/tests_for_matching.rs b/tests/packed/tests_for_matching.rs index ba84358..d8abc99 100644 --- a/tests/packed/tests_for_matching.rs +++ b/tests/packed/tests_for_matching.rs @@ -33,6 +33,12 @@ where assert_eq!(haystack_view.find(needle_view), expected_find); assert_eq!(haystack_view.rfind(needle_view), expected_rfind); assert_eq!(haystack_view.contains(needle_view), expected_find.is_some()); + assert_eq!(haystack_string.find(&needle_string), expected_find); + assert_eq!(haystack_string.rfind(&needle_string), expected_rfind); + assert_eq!( + haystack_string.contains(&needle_string), + expected_find.is_some() + ); } #[path = "tests_for_matching/tests_for_character_alignment.rs"] diff --git a/tests/packed/tests_for_matching/tests_for_cross_word_boundaries.rs b/tests/packed/tests_for_matching/tests_for_cross_word_boundaries.rs index 70b54b0..dcbf16d 100644 --- a/tests/packed/tests_for_matching/tests_for_cross_word_boundaries.rs +++ b/tests/packed/tests_for_matching/tests_for_cross_word_boundaries.rs @@ -1,6 +1,25 @@ use super::{Oct, WideCode, assert_matching, oct, wide}; +use bit_string::traits::PackedChar; use proptest::prelude::*; +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +struct TestCode(u8); + +impl PackedChar for TestCode { + fn code(self) -> u8 { + self.0 + } + + fn from_code(code: u8) -> Option { + ((1..=8).contains(&BITS) && u16::from(code) < (1_u16 << BITS)).then_some(Self(code)) + } +} + +fn test_code(code: u8) -> TestCode { + assert!(u16::from(code) < (1_u16 << BITS)); + TestCode(code) +} + proptest! { #[test] fn three_and_seven_bit_matching_crosses_word_boundaries( @@ -12,4 +31,18 @@ proptest! { assert_matching::(&haystack3, &needle3, oct); assert_matching::(&haystack7, &needle7, wide); } + + #[test] + fn four_five_and_six_bit_search_crosses_word_boundaries( + haystack4 in prop::collection::vec(0u8..=15, 16..=128), + needle4 in prop::collection::vec(0u8..=15, 0..=32), + haystack5 in prop::collection::vec(0u8..=31, 13..=128), + needle5 in prop::collection::vec(0u8..=31, 0..=32), + haystack6 in prop::collection::vec(0u8..=63, 11..=128), + needle6 in prop::collection::vec(0u8..=63, 0..=32), + ) { + assert_matching::, 4>(&haystack4, &needle4, test_code::<4>); + assert_matching::, 5>(&haystack5, &needle5, test_code::<5>); + assert_matching::, 6>(&haystack6, &needle6, test_code::<6>); + } }