-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/instrumenter/test/unit/mutators/regex-mutator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
import { RegexMutator } from '../../../src/mutators/regex-mutator'; | ||
import { expectJSMutation } from '../../helpers/expect-mutation'; | ||
|
||
describe.only(RegexMutator.name, () => { | ||
let sut: RegexMutator; | ||
beforeEach(() => { | ||
sut = new RegexMutator(); | ||
}); | ||
|
||
it('should have name "Regex"', () => { | ||
expect(sut.name).eq('Regex'); | ||
}); | ||
|
||
it('should not mutate normal string literals', () => { | ||
expectJSMutation(sut, '""'); | ||
}); | ||
|
||
it('should mutate a regex literal', () => { | ||
expectJSMutation(sut, '/\\d{4}/', '/\\d/', '/\\D{4}/'); | ||
}); | ||
|
||
it("should not crash if a regex couldn't be parsed", () => { | ||
const errorStub = sinon.stub(console, 'error'); | ||
expectJSMutation(sut, '/[[]]/'); | ||
expect(errorStub).calledWith( | ||
'[RegexMutator]: The Regex parser of weapon-regex couldn\'t parse this regex pattern: "[[]]". Please report this issue at https://github.com/stryker-mutator/weapon-regex/issues. Inner error: [Error] Parser: Position 1:1, found "[[]]"' | ||
); | ||
}); | ||
|
||
// it('should mutate obvious Regex string literals', () => { | ||
// expectJSMutation(sut, 'new RegExp("\\d{4}", "i")', 'new RegExp("\\d", "i")', 'new RegExp("\\D{4}", "i")'); | ||
// }); | ||
}); |