MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / makeRegexForTests

Function makeRegexForTests

src/shared/utils/test.ts:74–98  ·  view source on GitHub ↗
(names: TestSelection[])

Source from the content-addressed store, hash-verified

72
73const regexEscapedInterpolationExpressionPattern = /\\\$(?:(?:\w+)|(?:\\\{.*\\\}))/g;
74export function makeRegexForTests(names: TestSelection[]) {
75 const regexSegments: string[] = [];
76 for (const name of names) {
77 const prefix = name.isOutlineNodeNotFromMainFunction ? "" : "^";
78 // We can't anchor to the end for groups, as we want them to run all children.
79 const suffix = name.isGroup ? "" : "( \\(variant: .*\\))?$";
80 let escapedName = escapeRegExp(name.name);
81
82 // Replace any literal newlines with \n because literals can cause
83 // issues in the shell.
84 // https://github.com/Dart-Code/Dart-Code/issues/4007
85 escapedName = escapedName
86 .replace(/\n/g, "\\n")
87 .replace(/\r/g, "\\r");
88
89 // If a test name contains interpolated expressions, passing the exact
90 // name won't match. So we just replace them out with wildcards. We'll need
91 // to do this after escaping for regex, to ensure the original expression
92 // is escaped but our wildcard is not.
93 const substitutedName = escapedName.replace(regexEscapedInterpolationExpressionPattern, ".*");
94 regexSegments.push(`${prefix}${substitutedName}${suffix}`);
95 }
96
97 return regexSegments.join("|");
98}
99
100export function getTestExecutionInfo(programPath: string, tests: TestSelection[], shouldRunTestByLine: boolean): { programUri: URI, args: string[] } {
101 if (shouldRunTestByLine && tests.length && tests.every((test) => test.position)) {

Callers 2

getTestExecutionInfoFunction · 0.85

Calls 1

escapeRegExpFunction · 0.90

Tested by

no test coverage detected