/// Validate a regex capture, and optional follow-up capture.
/// If a test fails, the details of the tests are printed.
///
/// To view the details of a successful tests (such as to validate your proptest patterns are
/// generating anticipated sample values), run with the following options:
///
///   $ out/${OUT_SUBDIR}/host_x64/exe.unstripped/json5format_lib_test --show-output <test_name>
Validate a regex capture, and optional follow-up capture.
If a test fails, the details of the tests are printed.

To view the details of a successful tests (such as to validate your proptest patterns are
generating anticipated sample values), run with the following options.


Validate a regex capture and optional follow - up capture . If a test fails the details of the tests are printed . To view the details of a successful tests ( such as to validate your proptest patterns are generating anticipated sample values ) run with the following options .
fn try_capture(
        regex: &Regex,
        group_id: Option<usize>,
        test: RegexTest<'_>,
    ) -> Result<String, Error> {
        println!();
        println!("pattern: '{}'", regex.as_str());
        let trailing = test.next_suffix.to_owned() + test.trailing;
        let test_string =
            test.prefix.to_owned() + test.matches + test.suffix + test.next_matches + &trailing;
        println!("capturing from: '{}'", test_string.escape_debug());
        println!(
            "                 {}{}{}{}",
            " ".repeat(test.prefix.len()),
            "^".repeat(test.matches.len()),
            " ".repeat(test.suffix.len()),
            "^".repeat(test.next_matches.len())
        );
        let group_id = group_id.unwrap_or(1);
        println!("expected capture id: '{}'", group_id);
        let capture = regex.captures(&test_string).ok_or_else(|| test_error!("capture failed"))?;
        let overall_match = capture.get(0).ok_or_else(|| test_error!("regex did not match"))?;
        println!(
            "overall match: '{}', length = {}",
            overall_match.as_str().escape_debug(),
            overall_match.end()
        );
        let remaining = &test_string[overall_match.end()..];
        println!("remaining: '{}'", remaining.escape_debug());
        const OVERALL_MATCH: usize = 0;
        let mut capture_ids = vec![];
        for (index, subcapture) in capture.iter().enumerate() {
            if index != OVERALL_MATCH {
                if subcapture.is_some() {
                    capture_ids.push(index);
                }
            }
        }
        println!("capture ids = {:?}", capture_ids);
        let captured_text = capture
            .get(group_id)
            .ok_or_else(|| test_error!(format!("capture group {} did not match", group_id)))?
            .as_str();
        println!("captured: '{}'", captured_text.escape_debug());
        assert_eq!(captured_text, test.matches);
        assert_eq!(capture_ids.len(), 1);
        assert_eq!(remaining, test.next_matches.to_owned() + &trailing);
        match test.next_regex {
            Some(next_regex) => test_capture(
                &*next_regex,
                None,
                RegexTest {
                    prefix: test.next_prefix,
                    matches: test.next_matches,
                    suffix: test.next_suffix,
                    trailing: test.trailing,
                    ..Default::default()
                },
            ),
            None => Ok(captured_text.to_string()),
        }
    }
fn try_capture ( regex : & Regex , group_id : Option < usize > , test : RegexTest < ' _ > , ) -> Result < String , Error > { println ! ( ) ; println ! ( " " regex as_str ( ) ) ; let trailing = test . next_suffix . to_owned ( ) + test . trailing ; let test_string = test . prefix . to_owned ( ) + test . matches + test . suffix + test . next_matches + & trailing ; println ! ( " " test_string escape_debug ( ) ) ; println ! ( " " " " repeat ( test prefix len ( ) ) " " repeat ( test matches len ( ) ) " " repeat ( test suffix len ( ) ) " " repeat ( test next_matches len ( ) ) ) ; let group_id = group_id . unwrap_or ( 1 ) ; println ! ( " " group_id ) ; let capture = regex . captures ( & test_string ) . ok_or_else ( | | test_error ! ( " " ) ) ? ; let overall_match = capture . get ( 0 ) . ok_or_else ( | | test_error ! ( " " ) ) ? ; println ! ( " " overall_match as_str ( ) escape_debug ( ) overall_match end ( ) ) ; let remaining = & test_string [ overall_match . end ( ) .. ] ; println ! ( " " remaining escape_debug ( ) ) ; const OVERALL_MATCH : usize = 0 ; let mut capture_ids = vec ! [ ] ; for ( index , subcapture ) in capture . iter ( ) . enumerate ( ) { if index != OVERALL_MATCH { if subcapture . is_some ( ) { capture_ids . push ( index ) ; } } } println ! ( " " capture_ids ) ; let captured_text = capture . get ( group_id ) . ok_or_else ( | | test_error ! ( format ( " " group_id ) ) ) ? . as_str ( ) ; println ! ( " " captured_text escape_debug ( ) ) ; assert_eq ! ( captured_text test matches ) ; assert_eq ! ( capture_ids len ( ) 1 ) ; assert_eq ! ( remaining test next_matches to_owned ( ) trailing ) ; match test . next_regex { Some ( next_regex ) => test_capture ( & * next_regex , None , RegexTest { prefix : test . next_prefix , matches : test . next_matches , suffix : test . next_suffix , trailing : test . trailing , .. Default :: default ( ) } , ) , None => Ok ( captured_text . to_string ( ) ) , } }
Validate a regex capture, and optional follow-up capture.
Validate a regex capture and optional follow - up capture .
regex
&Regex
group_id
Option<usize>
test
RegexTest<'_>