⭐️ A friendly language for building type-safe, scalable systems!

Normalise lines

Changed files
+18 -9
test-helpers-rs
src
+18 -9
test-helpers-rs/src/lib.rs
··· 44 44 } 45 45 46 46 Content::Text(text) => { 47 - let text = FILE_LINE_REGEX 48 - .replace_all(text, |caps: &regex::Captures| { 49 - let path = caps 50 - .get(1) 51 - .expect("file path") 52 - .as_str() 53 - .replace("\\\\", "/"); 54 - let line_number = caps.get(2).expect("line number").as_str(); 55 - format!("-file(\"{path}\", {line_number}).") 47 + let format_path = |caps: &regex::Captures| { 48 + caps.get(1) 49 + .expect("file path") 50 + .as_str() 51 + .replace("\\\\", "/") 52 + }; 53 + let text = FILE_LINE_REGEX.replace_all(text, |caps: &regex::Captures| { 54 + let path = format_path(caps); 55 + let line_number = caps.get(2).expect("line number").as_str(); 56 + format!("-file(\"{path}\", {line_number}).") 57 + }); 58 + let text = FILEPATH_MACRO_REGEX 59 + .replace_all(text.to_string().as_str(), |caps: &regex::Captures| { 60 + let path = format_path(caps); 61 + format!("-define(FILEPATH, \"{path}\").") 56 62 }) 57 63 .replace(COMPILER_VERSION, "<gleam compiler version string>"); 58 64 buffer.push_str(&text) ··· 94 100 95 101 static FILE_LINE_REGEX: LazyLock<Regex> = 96 102 LazyLock::new(|| Regex::new(r#"-file\("([^"]+)", (\d+)\)\."#).expect("Invalid regex")); 103 + 104 + static FILEPATH_MACRO_REGEX: LazyLock<Regex> = 105 + LazyLock::new(|| Regex::new(r#"-define\(FILEPATH, "([^"]+)"\)\."#).expect("Invalid regex")); 97 106 98 107 pub fn normalise_diagnostic(text: &str) -> String { 99 108 // There is an extra ^ on Windows in some error messages' code