Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/packed/tests_for_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
33 changes: 33 additions & 0 deletions tests/packed/tests_for_matching/tests_for_cross_word_boundaries.rs
Original file line number Diff line number Diff line change
@@ -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<const BITS: u8>(u8);

impl<const BITS: u8> PackedChar<BITS> for TestCode<BITS> {
fn code(self) -> u8 {
self.0
}

fn from_code(code: u8) -> Option<Self> {
((1..=8).contains(&BITS) && u16::from(code) < (1_u16 << BITS)).then_some(Self(code))
}
}

fn test_code<const BITS: u8>(code: u8) -> TestCode<BITS> {
assert!(u16::from(code) < (1_u16 << BITS));
TestCode(code)
}

proptest! {
#[test]
fn three_and_seven_bit_matching_crosses_word_boundaries(
Expand All @@ -12,4 +31,18 @@ proptest! {
assert_matching::<Oct, 3>(&haystack3, &needle3, oct);
assert_matching::<WideCode, 7>(&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::<TestCode<4>, 4>(&haystack4, &needle4, test_code::<4>);
assert_matching::<TestCode<5>, 5>(&haystack5, &needle5, test_code::<5>);
assert_matching::<TestCode<6>, 6>(&haystack6, &needle6, test_code::<6>);
}
}
Loading