Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit aae136f

Browse files
luanraithzLuan Raithz Machado
andauthored
Fixed TODO for multiple negations combined with normal grep conditions (#89)
* Fixed TODO for multiple negations plus some normal conditions * simplified logic * added another test scenario Co-authored-by: Luan Raithz Machado <luan.machado@hbsis.com.br>
1 parent 3d22715 commit aae136f

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

cypress/integration/unit.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,24 @@ describe('utils', () => {
318318
]),
319319
).to.be.true
320320
})
321+
322+
it("Multiple invert strings and a simple one", () => {
323+
const t = checkName("-name;-hey;number")
324+
expect(t("number should only be matches without a n-a-m-e")).to.be.true
325+
expect(t("number can't be name")).to.be.false
326+
expect(t("The man needs a name")).to.be.false
327+
expect(t("number hey name")).to.be.false
328+
expect(t("numbers hey name")).to.be.false
329+
expect(t("number hsey nsame")).to.be.true
330+
expect(t("This wont match")).to.be.false
331+
})
332+
333+
it("Only inverted strings", () => {
334+
const t = checkName("-name;-hey")
335+
expect(t("I'm matched")).to.be.true
336+
expect(t("hey! I'm not")).to.be.false
337+
expect(t("My name is weird")).to.be.false
338+
})
321339
})
322340

323341
context('parseFullTitleGrep', () => {

src/utils.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,12 @@ function shouldTestRunTitle(parsedGrep, testName) {
111111
return true
112112
}
113113

114-
// TODO if some titles greps are "invert: true" we should
115-
// use AND instead of OR, otherwise it does the
116-
// opposite of what we probably want to do
114+
const inverted = parsedGrep.filter(g => g.invert)
115+
const straight = parsedGrep.filter(g => !g.invert)
117116

118-
return parsedGrep.some((titleGrep) => {
119-
if (titleGrep.invert) {
120-
return !testName.includes(titleGrep.title)
121-
}
122-
123-
return testName.includes(titleGrep.title)
124-
})
117+
return inverted.every(titleGrep => !testName.includes(titleGrep.title))
118+
&& (!straight.length || straight
119+
.some(titleGrep => testName.includes(titleGrep.title)))
125120
}
126121

127122
// note: tags take precedence over the test name

0 commit comments

Comments
 (0)