Skip to content

Commit 19374b4

Browse files
committed
move normalizeLF(), normalizeCRLF() into util.ts
1 parent 88a9ea0 commit 19374b4

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/ctest.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ interface ProjectCoverageConfig {
134134
}
135135

136136
export function searchOutputForFailures(patterns: FailurePatternsConfig, output: string): vscode.TestMessage[] {
137-
output = normalizeLF(output);
137+
output = util.normalizeLF(output);
138138
const messages = [];
139139
patterns = Array.isArray(patterns) ? patterns : [patterns];
140140
for (let pattern of patterns) {
@@ -163,7 +163,7 @@ function matchToTestMessage(pat: FailurePattern, match: RegExpMatchArray): vscod
163163
const actual = pat.actual ? match[pat.actual] : undefined;
164164
const expected = pat.expected ? match[pat.expected] : undefined;
165165

166-
const testMessage = new vscode.TestMessage(normalizeCRLF(message));
166+
const testMessage = new vscode.TestMessage(util.normalizeCRLF(message));
167167
testMessage.location = new vscode.Location(
168168
vscode.Uri.file(file), new vscode.Position(line, 0)
169169
);
@@ -172,14 +172,6 @@ function matchToTestMessage(pat: FailurePattern, match: RegExpMatchArray): vscod
172172
return testMessage;
173173
}
174174

175-
function normalizeLF(s: string) {
176-
return s.replace(/\r\n?/g, '\n');
177-
}
178-
179-
function normalizeCRLF(s: string) {
180-
return s = s.replace(/\r?\n/g, '\r\n');
181-
}
182-
183175
function parseLineMatch(line: string | null) {
184176
const i = parseInt(line || '');
185177
if (i) {
@@ -661,7 +653,7 @@ export class CTestDriver implements vscode.Disposable {
661653

662654
let output = testResult.output;
663655
// https://code.visualstudio.com/api/extension-guides/testing#test-output
664-
output = output.replace(/\r?\n/g, '\r\n');
656+
output = util.normalizeCRLF(output);
665657
if (test.uri && test.range) {
666658
run.appendOutput(output, new vscode.Location(test.uri, test.range.end), test);
667659
} else {

src/util.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,3 +1378,21 @@ function globWrapper(globPattern: string, cwd: string): Promise<boolean> {
13781378
});
13791379
});
13801380
}
1381+
1382+
/**
1383+
* Convert all line endings in a string to '\n'
1384+
* @param s the string to normalize
1385+
* @returns @c s with all line endings converted to '\n'
1386+
*/
1387+
export function normalizeLF(s: string) {
1388+
return s.replace(/\r\n?/g, '\n');
1389+
}
1390+
1391+
/**
1392+
* Convert all line endings in a string to '\r\n'
1393+
* @param s the string to normalize
1394+
* @returns @c s with all line endings converted to '\r\n'
1395+
*/
1396+
export function normalizeCRLF(s: string) {
1397+
return s = s.replace(/\r?\n/g, '\r\n');
1398+
}

0 commit comments

Comments
 (0)