fn expected_diagnostics(path: &Path) -> eyre::Result<Vec<ExpectedDiagnostic>> {
    let file_contents = std::fs::read_to_string(path)?;

    let re = regex::Regex::new(
        r"^(?P<prefix>[^#]*)#!\s*(?P<highlight>\^+)?\s*(?P<severity>[^\s*]+)\s*(?P<msg>.*)",
    )
    .unwrap();

    let mut last_code_line = 1;
    let mut result = vec![];
    for (line, line_number) in file_contents.lines().zip(1..) {
        if let Some(c) = re.captures(line) {
            let start_line = if c["prefix"].chars().all(char::is_whitespace) {
                // A comment alone on a line, like `#! ERROR ...`, will apply to the
                // last code line.
                last_code_line
            } else {
                // A comment at the end of a line, like `foo() #! ERROR`, applies to
                // that line.
                line_number
            };

            let highlight = c.name("highlight");
            let start_column = highlight.map(|m| m.start() as u32 + 1);
            let end_line_column = highlight.map(|m| (start_line, m.end() as u32 + 1));

            result.push(ExpectedDiagnostic {
                start_line,
                start_column,
                end_line_column,
                severity: c["severity"].to_string(),
                message: Regex::new(&c["msg"])?,
            });
        } else {
            last_code_line = line_number;
        }
    }
    Ok(result)
}
/// Returns the diagnostics that we expect to see in the file, sorted by line number.
Returns the diagnostics that we expect to see in the file, sorted by line number.
Returns the diagnostics that we expect to see in the file sorted by line number .
fn expected_diagnostics(path: &Path) -> eyre::Result<Vec<ExpectedDiagnostic>> {
    let file_contents = std::fs::read_to_string(path)?;
    let re = regex::Regex::new(
        r"^(?P<prefix>[^#]*)#!\s*(?P<highlight>\^+)?\s*(?P<severity>[^\s*]+)\s*(?P<msg>.*)",
    )
    .unwrap();
    let mut last_code_line = 1;
    let mut result = vec![];
    for (line, line_number) in file_contents.lines().zip(1..) {
        if let Some(c) = re.captures(line) {
            let start_line = if c["prefix"].chars().all(char::is_whitespace) {
                // A comment alone on a line, like `#! ERROR ...`, will apply to the
                // last code line.
                last_code_line
            } else {
                // A comment at the end of a line, like `foo() #! ERROR`, applies to
                // that line.
                line_number
            };
            let highlight = c.name("highlight");
            let start_column = highlight.map(|m| m.start() as u32 + 1);
            let end_line_column = highlight.map(|m| (start_line, m.end() as u32 + 1));
            result.push(ExpectedDiagnostic {
                start_line,
                start_column,
                end_line_column,
                severity: c["severity"].to_string(),
                message: Regex::new(&c["msg"])?,
            });
        } else {
            last_code_line = line_number;
        }
    }
    Ok(result)
}
fn expected_diagnostics ( path : & Path ) -> eyre :: Result < Vec < ExpectedDiagnostic > > { let file_contents = std :: fs :: read_to_string ( path ) ? ; let re = regex :: Regex :: new ( r"^(?P<prefix>[^#]*)#!\s*(?P<highlight>\^+)?\s*(?P<severity>[^\s*]+)\s*(?P<msg>.*)" , ) . unwrap ( ) ; let mut last_code_line = 1 ; let mut result = vec ! [ ] ; for ( line , line_number ) in file_contents . lines ( ) . zip ( 1 .. ) { if let Some ( c ) = re . captures ( line ) { let start_line = if c [ " " ] . chars ( ) . all ( char :: is_whitespace ) { // A comment alone on a line, like `#! ERROR ...`, will apply to the // last code line. last_code_line } else { // A comment at the end of a line, like `foo() #! ERROR`, applies to // that line. line_number } ; let highlight = c . name ( " " ) ; let start_column = highlight . map ( | m | m . start ( ) as u32 + 1 ) ; let end_line_column = highlight . map ( | m | ( start_line , m . end ( ) as u32 + 1 ) ) ; result . push ( ExpectedDiagnostic { start_line , start_column , end_line_column , severity : c [ " " ] . to_string ( ) , message : Regex :: new ( & c [ " " ] ) ? , } ) ; } else { last_code_line = line_number ; } } Ok ( result ) }
Returns the diagnostics that we expect to see in the file, sorted by line number.
Returns the diagnostics that we expect to see in the file sorted by line number .
path
&Path
path
&Path