use {
lazy_regex::*,
};
#[test]
fn test_regex_remove() {
let input = "154681string63731";
let output = regex_remove!("[A-Z]+", input);
assert!(matches!(output, std::borrow::Cow::Borrowed("154681string63731")));
let output = regex_remove!("[a-z]+", input);
assert_eq!(output, "15468163731");
let output = regex_remove!(r"^\d+", input);
let output = regex_remove!(r"\d+$", &output);
assert_eq!(output, "string");
assert!(matches!(output, std::borrow::Cow::Borrowed("string")));
}
#[test]
#[cfg(not(feature = "lite"))]
fn test_bytes_regex_remove() {
let input = b"154681string63731";
let output = bytes_regex_remove!("^\\d+", input);
let output = bytes_regex_remove!("\\d+$", &output);
assert_eq!(&output[..], b"string");
assert!(matches!(output, std::borrow::Cow::Borrowed(b"string")));
}
#[test]
fn test_regex_remove_all() {
let input = "154681string63731";
let output = regex_remove_all!("[A-Z]+", input);
assert!(matches!(output, std::borrow::Cow::Borrowed("154681string63731")));
let output = regex_remove_all!("[a-z]+", input);
assert_eq!(output, "15468163731");
let output = regex_remove_all!("[a-z]{2}", input);
assert_eq!(output, "15468163731");
let output = regex_remove_all!(r"\d+", input);
assert_eq!(output, "string");
assert!(matches!(output, std::borrow::Cow::Borrowed("string")));
let output = regex_remove_all!(r"^\d+", input);
assert_eq!(output, "string63731");
assert!(matches!(output, std::borrow::Cow::Borrowed("string63731")));
let output = regex_remove_all!(r"\d+$", input);
assert_eq!(output, "154681string");
assert!(matches!(output, std::borrow::Cow::Borrowed("154681string")));
let output = regex_remove_all!(r"\d", input);
assert_eq!(output, "string");
assert!(matches!(output, std::borrow::Cow::Borrowed("string")));
assert_eq!(
regex_remove_all!(r"\d", "a1b2c3d4e5"),
"abcde"
);
assert_eq!(
regex_remove_all!(r"[a-z]", "a1b2c3d4e5"),
"12345"
);
assert_eq!(
regex_remove_all!(r"\d", "a11b22c33333d44e55"),
"abcde"
);
assert_eq!(
regex_remove_all!(r"\s+", " ab c d e "),
"abcde"
);
}
#[test]
#[cfg(not(feature = "lite"))]
fn test_bytes_regex_remove_all() {
let input = b"154681string63731";
let output = bytes_regex_remove_all!(r"\d", input);
assert_eq!(&output[..], b"string");
assert!(matches!(output, std::borrow::Cow::Borrowed(b"string")));
assert_eq!(
*bytes_regex_remove_all!(r"\s+", b" ab c d e "),
*b"abcde"
);
}