use vyre::ops::string_matching::*;
#[test]
fn substring_contains_basic() {
assert!(substring_contains::substring_contains(b"hello world", b"world").unwrap());
assert!(!substring_contains::substring_contains(b"hello world", b"foo").unwrap());
}
#[test]
fn substring_contains_empty_needle() {
assert!(substring_contains::substring_contains(b"anything", b"").unwrap());
}
#[test]
fn substring_find_first_basic() {
assert_eq!(substring_find_first::substring_find_first(b"hello world", b"world").unwrap(), 6);
assert_eq!(
substring_find_first::substring_find_first(b"hello world", b"foo").unwrap(),
u32::MAX
);
}
#[test]
fn substring_find_all_basic() {
assert_eq!(substring_find_all::substring_find_all(b"ababab", b"ab").unwrap(), vec![0, 2, 4]);
assert!(substring_find_all::substring_find_all(b"abc", b"z").unwrap().is_empty());
}
#[test]
fn boyer_moore_find_basic() {
assert_eq!(boyer_moore_find::boyer_moore_find(b"hello world", b"world").unwrap(), 6);
assert_eq!(
boyer_moore_find::boyer_moore_find(b"hello world", b"foo").unwrap(),
search_contract::NOT_FOUND
);
}
#[test]
fn boyer_moore_find_empty_needle() {
assert_eq!(boyer_moore_find::boyer_moore_find(b"anything", b"").unwrap(), 0);
}
#[test]
fn kmp_find_basic() {
use kmp_find::kernel::kmp_find;
assert_eq!(kmp_find(b"hello world", b"world").unwrap(), 6);
assert_eq!(
kmp_find(b"hello world", b"foo").unwrap(),
search_contract::NOT_FOUND
);
}
#[test]
fn rabin_karp_find_basic() {
use rabin_karp_find::kernel::rabin_karp_find;
assert_eq!(rabin_karp_find(b"hello world", b"world").unwrap(), 6);
assert_eq!(
rabin_karp_find(b"hello world", b"foo").unwrap(),
search_contract::NOT_FOUND
);
}
#[test]
fn glob_match_basic() {
use glob_match::kernel::glob_match;
assert!(glob_match(b"hello.txt", b"*.txt").unwrap());
assert!(!glob_match(b"hello.txt", b"*.rs").unwrap());
assert!(glob_match(b"test", b"*").unwrap());
}
#[test]
fn wildcard_match_basic() {
use wildcard_match::kernel::wildcard_match;
assert!(wildcard_match(b"hello", b"h?llo").unwrap());
assert!(wildcard_match(b"hello world", b"h*o").unwrap());
assert!(!wildcard_match(b"hello", b"h?x").unwrap());
}