Skip to content

Commit 013175e

Browse files
committed
Normalise lines
1 parent c0d412f commit 013175e

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

test-helpers-rs/src/lib.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,21 @@ impl TestCompileOutput {
4444
}
4545

4646
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}\").")
5662
})
5763
.replace(COMPILER_VERSION, "<gleam compiler version string>");
5864
buffer.push_str(&text)
@@ -95,6 +101,9 @@ pub fn to_in_memory_filesystem(path: &Utf8Path) -> InMemoryFileSystem {
95101
static FILE_LINE_REGEX: LazyLock<Regex> =
96102
LazyLock::new(|| Regex::new(r#"-file\("([^"]+)", (\d+)\)\."#).expect("Invalid regex"));
97103

104+
static FILEPATH_MACRO_REGEX: LazyLock<Regex> =
105+
LazyLock::new(|| Regex::new(r#"-define\(FILEPATH, "([^"]+)"\)\."#).expect("Invalid regex"));
106+
98107
pub fn normalise_diagnostic(text: &str) -> String {
99108
// There is an extra ^ on Windows in some error messages' code
100109
// snippets.

0 commit comments

Comments
 (0)