Skip to content

Commit

Permalink
[patch] Fix regexp when parenthesis in test title (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmisty authored Mar 22, 2024
1 parent 9246e0c commit ab76790
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/utils/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export const selectionTestGrep = (str: string): RegExp => {

return new RegExp(expr, flags);
}

const leftParenth = '##LP##';
const rightParenth = '##RP##';
const replacements: Replacement[] = [];

str = str.replace(/\\\(/g, leftParenth).replace(/\\\)/g, rightParenth);
const replacedString = replaceParenthesisGroups(str, replacements);
let convertedString = convertOneGroup(replacedString, false);
const groups = replacements.map(t => ({ ...t, reg: convertOneGroup(t.exp, t.inverse) }));
Expand All @@ -79,5 +82,9 @@ export const selectionTestGrep = (str: string): RegExp => {
convertedString = convertedString.replace(r.mapName, r.reg);
});

convertedString = convertedString
.replace(new RegExp(leftParenth, 'g'), '\\(')
.replace(new RegExp(rightParenth, 'g'), '\\)');

return new RegExp(`${convertedString}.*`, 'i');
};
22 changes: 21 additions & 1 deletion tests/test-folder/regexp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,26 @@ describe('suite', () => {
{ expectMatch: true, testLine: '@suite @test' },
],
},
{
desc: 'parenthesis in title',
GREP: 'should stay enabled \\(not disabled\\)',
regExpected: /should stay enabled \(not disabled\).*/i,
cases: [
{ expectMatch: true, testLine: 'should stay enabled (not disabled)' },
{ expectMatch: false, testLine: 'should stay enabled not disabled ' },
],
},
{
desc: 'parenthesis in title several with not',
GREP: '!(suite test 1 \\(addition\\)|suite test 2 \\(addition\\)|suite test 3 \\(addition\\))',
regExpected: /^(?!.*(suite test 1 \(addition\)|suite test 2 \(addition\)|suite test 3 \(addition\)).*).*/i,
cases: [
{ expectMatch: false, testLine: 'suite test 1 (addition)' },
{ expectMatch: false, testLine: 'suite test 2 (addition)' },
{ expectMatch: false, testLine: 'suite test 3 (addition)' },
{ expectMatch: true, testLine: 'suite test 3 addition' },
],
},
{
desc: 'and with parenthesis and or combination (diff writing)',
GREP: '(@test|@tag)&(@suite|@tag)',
Expand Down Expand Up @@ -286,7 +306,7 @@ describe('suite', () => {
])
.each(t => [{ desc: `: '${t.GREP}'` }])
.each(t => t.cases)
// .only(t => t.id === '1')
//.only(t => t.id === '1')
.run(t => {
const regActual = selectionTestGrep(t.GREP);

Expand Down

0 comments on commit ab76790

Please sign in to comment.