From ab767903c47817b7496c719e089a9d497bf94a7c Mon Sep 17 00:00:00 2001 From: Taisia Pitko Date: Fri, 22 Mar 2024 14:26:18 +0100 Subject: [PATCH] [patch] Fix regexp when parenthesis in test title (#26) --- src/utils/regexp.ts | 9 ++++++++- tests/test-folder/regexp.test.ts | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/utils/regexp.ts b/src/utils/regexp.ts index f9b63db..48e70ba 100644 --- a/src/utils/regexp.ts +++ b/src/utils/regexp.ts @@ -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) })); @@ -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'); }; diff --git a/tests/test-folder/regexp.test.ts b/tests/test-folder/regexp.test.ts index 0e5b2b0..8e39dbd 100644 --- a/tests/test-folder/regexp.test.ts +++ b/tests/test-folder/regexp.test.ts @@ -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)', @@ -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);