mod common; use fancy_regex::Regex; #[test] fn find_wrap() { assert_eq!(find(r"(\w+)", "... test"), Some((4, 8))); assert_eq!(find(r"(?m)^yes$", "foo\nyes\n"), Some((4, 7))); } #[test] fn find_fancy_case_insensitive() { assert_eq!(find(r"(x|xy)\1", "XX"), None); assert_eq!(find(r"(x|xy)\1", "xx"), Some((0, 2))); assert_eq!(find(r"((?i:x|xy))\1", "XX"), Some((0, 2))); } #[test] fn lookahead_grouping_single_expression() { // These would fail if the delegate expression was `^x|a` (if we didn't // group as `^(?:x|a)`). assert_eq!(find(r"(?=x|a)", "a"), Some((0, 0))); assert_eq!(find(r"(?=x|a)", "bbba"), Some((3, 3))); } #[test] fn lookahead_grouping_multiple_expressions() { // These would fail if the delegate expression was `^ab|Bc` (if we didn't // preserve grouping of `(?:b|B)`). assert_eq!(find(r"(?=(?!x)a(?:b|B)c)", "aBc"), Some((0, 0))); assert_eq!(find(r"(?=(?!x)a(?:b|B)c)", "Bc"), None); } #[test] fn lookbehind_grouping_single_expression() { assert_eq!(find(r"(?<=x|a)", "a"), Some((1, 1))); assert_eq!(find(r"(?<=x|a)", "ba"), Some((2, 2))); assert_eq!(find(r"(?<=^a)", "a"), Some((1, 1))); assert_eq!(find(r"(?<=^a)", "ba"), None); } #[test] fn lookbehind_variable_sized_alt() { assert_eq!(find(r"(?<=a|bc)", "xxa"), Some((3, 3))); assert_eq!(find(r"(?<=a|bc)", "xxbc"), Some((4, 4))); assert_eq!(find(r"(?<=a|bc)", "xx"), None); assert_eq!(find(r"(?<=a|bc)", "xxb"), None); assert_eq!(find(r"(?<=a|bc)", "xxc"), None); assert!(Regex::new(r"(?<=a(?:b|cd))").is_err()); assert!(Regex::new(r"(?<=a+b+))").is_err()); } #[test] fn negative_lookbehind_variable_sized_alt() { assert_eq!(find(r"(? Option<(usize, usize)> { let regex = common::regex(re); let result = regex.find(text); assert!( result.is_ok(), "Expected find to succeed, but was {:?}", result ); result.unwrap().map(|m| (m.start(), m.end())) }