Skip to content

Commit 9dc70db

Browse files
committed
test: add unit test for problem matcher
1 parent 254c86c commit 9dc70db

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import dotnetFormat from '../.github/dotnet-format.json';
2+
3+
describe('/.github/dotnet-format.json tests', () => {
4+
const problemMatcher = dotnetFormat.problemMatcher[0].pattern[0];
5+
6+
it.each([
7+
[
8+
"/home/runner/work/repo/Test.cs(18,6): error WHITESPACE: Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'. [/home/runner/work/repo/Test.csproj]",
9+
'/home/runner/work/repo/Test.cs',
10+
'18',
11+
'6',
12+
'error',
13+
'WHITESPACE',
14+
"Fix whitespace formatting. Replace 12 characters with '\\n\\s\\s\\s\\s\\s\\s\\s\\s'.",
15+
'/home/runner/work/repo/Test.csproj'
16+
]
17+
])(
18+
'"%s" returns {file: "%s", line: "%s", column: "%s", severity: "%s", code: "%s", message: "%s", fromPath: "%s"}',
19+
(logOutput, file, line, column, severity, code, message, fromPath) => {
20+
const regexp = new RegExp(problemMatcher.regexp);
21+
const res = logOutput.match(regexp);
22+
23+
expect(res?.[problemMatcher.file]).toBe(file);
24+
expect(res?.[problemMatcher.line]).toBe(line);
25+
expect(res?.[problemMatcher.column]).toBe(column);
26+
expect(res?.[problemMatcher.severity]).toBe(severity);
27+
expect(res?.[problemMatcher.code]).toBe(code);
28+
expect(res?.[problemMatcher.message]).toBe(message);
29+
expect(res?.[problemMatcher.fromPath]).toBe(fromPath);
30+
}
31+
);
32+
});

0 commit comments

Comments
 (0)