+18
-9
test-helpers-rs/src/lib.rs
+18
-9
test-helpers-rs/src/lib.rs
···
44
}
45
46
Content::Text(text) => {
47
-
let text = FILE_LINE_REGEX
48
-
.replace_all(text, |caps: ®ex::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}).")
56
})
57
.replace(COMPILER_VERSION, "<gleam compiler version string>");
58
buffer.push_str(&text)
···
94
95
static FILE_LINE_REGEX: LazyLock<Regex> =
96
LazyLock::new(|| Regex::new(r#"-file\("([^"]+)", (\d+)\)\."#).expect("Invalid regex"));
97
98
pub fn normalise_diagnostic(text: &str) -> String {
99
// There is an extra ^ on Windows in some error messages' code
···
44
}
45
46
Content::Text(text) => {
47
+
let format_path = |caps: ®ex::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: ®ex::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: ®ex::Captures| {
60
+
let path = format_path(caps);
61
+
format!("-define(FILEPATH, \"{path}\").")
62
})
63
.replace(COMPILER_VERSION, "<gleam compiler version string>");
64
buffer.push_str(&text)
···
100
101
static FILE_LINE_REGEX: LazyLock<Regex> =
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"));
106
107
pub fn normalise_diagnostic(text: &str) -> String {
108
// There is an extra ^ on Windows in some error messages' code