Skip to content

Commit

Permalink
feat(instrumenter): add more expression mutator for Date (stryker-mut…
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed Aug 2, 2024
1 parent e627f6c commit 51907fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
20 changes: 17 additions & 3 deletions packages/instrumenter/src/mutators/method-expression-mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,28 @@ const replacements = new Map([
['trim', null],
['trimEnd', 'trimStart'],
['min', 'max'],
['getDate', 'getMonth'],
['setDate', 'setMonth'],
['getDate', 'getTime'],
['setDate', 'setTime'],
['getFullYear', 'getMonth'],
['setFullYear', 'setMonth'],
['getHours', 'getMinutes'],
['setHours', 'setMinutes'],
['getSeconds', 'getMilliseconds'],
['setSeconds', 'setMilliseconds'],
['getUTCDate', 'getTime'],
['setUTCDate', 'setTime'],
['getUTCFullYear', 'getUTCMonth'],
['setUTCFullYear', 'setUTCMonth'],
['getUTCHours', 'getUTCMinutes'],
['setUTCHours', 'setUTCMinutes'],
['getUTCSeconds', 'getUTCMilliseconds'],
['setUTCSeconds', 'setUTCMilliseconds'],
]);

const noReverseRemplacements = ['getUTCDate', 'setUTCDate'];

for (const [key, value] of Array.from(replacements)) {
if (value) {
if (value && !noReverseRemplacements.includes(key)) {
replacements.set(value, key);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,39 @@ describe(sut.name, () => {
});
}

for (const [key, value] of [
for (const [key, value, noReverse] of [
['endsWith', 'startsWith'],
['every', 'some'],
['toLocaleLowerCase', 'toLocaleUpperCase'],
['toLowerCase', 'toUpperCase'],
['trimEnd', 'trimStart'],
['min', 'max'],
['getDate', 'getMonth'],
['setDate', 'setMonth'],
['getDate', 'getTime'],
['setDate', 'setTime'],
['getFullYear', 'getMonth'],
['setFullYear', 'setMonth'],
['getHours', 'getMinutes'],
['setHours', 'setMinutes'],
['getSeconds', 'getMilliseconds'],
['setSeconds', 'setMilliseconds'],
['getUTCDate', 'getTime', true],
['setUTCDate', 'setTime', true],
['getUTCFullYear', 'getUTCMonth'],
['setUTCFullYear', 'setUTCMonth'],
['getUTCHours', 'getUTCMinutes'],
['setUTCHours', 'setUTCMinutes'],
['getUTCSeconds', 'getUTCMilliseconds'],
['setUTCSeconds', 'setUTCMilliseconds'],
]) {
it(`should replace ${key} with ${value}`, () => {
expectJSMutation(sut, `text.${key}();`, `text.${value}();`);
});

it(`should replace ${value} with ${key}`, () => {
expectJSMutation(sut, `text.${value}();`, `text.${key}();`);
});
if (!noReverse) {
it(`should replace ${value} with ${key}`, () => {
expectJSMutation(sut, `text.${value}();`, `text.${key}();`);
});
}
}

for (const method of ['charAt', 'filter', 'reverse', 'slice', 'sort', 'substr', 'substring', 'trim']) {
Expand Down

0 comments on commit 51907fa

Please sign in to comment.