Skip to content

Commit

Permalink
#48 ensure code consistency between mutators tests (#75)
Browse files Browse the repository at this point in the history
* Made the arithmetic operator more consistent

* Made the array declaration more consistent

* Made the arrow function more consistent

* Made the assignment operator more consistent

* Made the block statement more consistent

* Made the boolean literal more consistent

* Made the conditional expression more consistent

* Made the equality operator more consistent

* Made the logical operator more consistent

* Made the method expression more consistent

* Made the object literal more consistent

* Made the optional chaining more consistent

* Made the regex more consistent

* Made the string literal more consistent

* Made the unary operator more consistent

* Made the update operator more consistent

* small modification in consistency

* Fix consistency in all unit test files

---------

Co-authored-by: Danut Copae <d.v.copae@gmail.com>
  • Loading branch information
Ja4pp and dvcopae authored Jan 11, 2024
1 parent a66eb01 commit c9a232f
Show file tree
Hide file tree
Showing 16 changed files with 418 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const arithmeticLevel: MutationLevel = {
name: 'ArithemticLevel',
ArithmeticOperator: ['AdditionOperatorNegation', 'SubtractionOperatorNegation', 'MultiplicationOperatorNegation'],
};
const arithmeticOperatorUndefinedLevel: MutationLevel = { name: 'ArithmeticOperatorLevel', ArithmeticOperator: [] };
const noLevel = undefined;

describe(sut.name, () => {
it('should have name "ArithmeticOperator"', () => {
Expand Down Expand Up @@ -37,14 +39,34 @@ describe(sut.name, () => {
expectJSMutation(sut, '"a" + b + "c" + d + "e"');
});

it('should only mutate +, - and * from all possible mutators', () => {
expectJSMutationWithLevel(
sut,
arithmeticLevel.ArithmeticOperator,
'a + b; a - b; a * b; a % b; a / b; a % b',
'a - b; a - b; a * b; a % b; a / b; a % b', // mutates +
'a + b; a + b; a * b; a % b; a / b; a % b', // mutates -
'a + b; a - b; a / b; a % b; a / b; a % b', // mutates *
);
describe('mutation level', () => {
it('should only mutate +, - and *', () => {
expectJSMutationWithLevel(
sut,
arithmeticLevel.ArithmeticOperator,
'a + b; a - b; a * b; a % b; a / b; a % b',
'a - b; a - b; a * b; a % b; a / b; a % b', // mutates +
'a + b; a + b; a * b; a % b; a / b; a % b', // mutates -
'a + b; a - b; a / b; a % b; a / b; a % b', // mutates *
);
});

it('should not perform any ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(sut, arithmeticOperatorUndefinedLevel.ArithmeticOperator, 'a + b; a - b; a * b; a % b; a / b; a % b');
});

it('should perform all ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(
sut,
noLevel,
'a + b; a - b; a * b; a % b; a / b; a % b',
'a + b; a - b; a * b; a % b; a * b; a % b', // mutates /
'a + b; a - b; a * b; a % b; a / b; a * b', // mutates %
'a + b; a - b; a * b; a * b; a / b; a % b', // mutates %
'a - b; a - b; a * b; a % b; a / b; a % b', // mutates +
'a + b; a + b; a * b; a % b; a / b; a % b', // mutates -
'a + b; a - b; a / b; a % b; a / b; a % b', // mutates *
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { MutationLevel } from '../../../src/mutation-level/mutation-level.js';

const arrayDeclarationLevel: MutationLevel = {
name: 'ArrayDeclarationLevel',
ArrayDeclaration: ['ArrayLiteralItemsFill', 'ArrayConstructorItemsRemoval', 'ArrayLiteralItemsRemoval', 'ArrayConstructorItemsFill'],
ArrayDeclaration: ['ArrayLiteralItemsFill', 'ArrayLiteralItemsRemoval'],
};
const arrayDeclarationOperatorUndefinedLevel: MutationLevel = { name: 'ArrayDeclarationcOperatorOperatorLevel', ArrayDeclaration: [] };
const noLevel = undefined;

describe(sut.name, () => {
it('should have name "ArrayDeclaration"', () => {
Expand Down Expand Up @@ -45,15 +47,35 @@ describe(sut.name, () => {
expectJSMutation(sut, 'window["Array"](21, 2)');
});

it('should only mutate [], new Array(), new Array(x,y) and [x,y] from all possible mutators', () => {
expectJSMutationWithLevel(
sut,
arrayDeclarationLevel.ArrayDeclaration,
'[]; new Array(); new Array({x:"", y:""}); [{x:"", y:""}]',
'["Stryker was here"]; new Array(); new Array({x:"", y:""}); [{x:"", y:""}]', // mutates []
'[]; new Array("Stryker was here"); new Array({x:"", y:""}); [{x:"", y:""}]', // mutates new Array()
'[]; new Array(); new Array(); [{x:"", y:""}]', // mutates new Array(x,y)
'[]; new Array(); new Array({x:"", y:""}); []', // mutates [x,y]
);
describe('mutation level', () => {
it('should only mutate [], new Array(x,y)', () => {
expectJSMutationWithLevel(
sut,
arrayDeclarationLevel.ArrayDeclaration,
'[]; new Array(); new Array({x:"", y:""}); [{x:"", y:""}]',
'["Stryker was here"]; new Array(); new Array({x:"", y:""}); [{x:"", y:""}]', // mutates []
'[]; new Array(); new Array({x:"", y:""}); []', // mutates [x,y]
);
});

it('should not perform any ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(
sut,
arrayDeclarationOperatorUndefinedLevel.ArrayDeclaration,
'[]; new Array(); new Array({x:"", y:""}); [{x:"", y:""}]',
);
});

it('should perform all ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(
sut,
noLevel,
'[]; new Array(); new Array({x:"", y:""}); [{x:"", y:""}]',
'["Stryker was here"]; new Array(); new Array({x:"", y:""}); [{x:"", y:""}]', // mutates []
'[]; new Array("Stryker was here"); new Array({x:"", y:""}); [{x:"", y:""}]', // mutates new Array()
'[]; new Array(); new Array(); [{x:"", y:""}]', // mutates new Array(x,y)
'[]; new Array(); new Array({x:"", y:""}); []', // mutates [x,y]
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { expectJSMutation, expectJSMutationWithLevel } from '../../helpers/expec
import { MutationLevel } from '../../../src/mutation-level/mutation-level.js';

const arrowFunctionLevel: MutationLevel = { name: 'ArrowFunctionLevel', ArrowFunction: ['ArrowFunctionRemoval'] };
const arrowFunctionUndefinedLevel: MutationLevel = { name: 'ArrowFunctionLevel' };
const arrowFunctionOperatorUndefinedLevel: MutationLevel = { name: 'ArrowFunctionLevel', ArrowFunction: [] };
const noLevel = undefined;

describe(sut.name, () => {
it('should have name "ArrowFunction"', () => {
Expand All @@ -24,15 +25,17 @@ describe(sut.name, () => {
expectJSMutation(sut, 'const b = () => undefined');
});

it('should only mutate what is defined in the mutator level', () => {
expectJSMutationWithLevel(sut, arrowFunctionLevel.ArrowFunction, 'const b = () => 4;', 'const b = () => undefined;');
});
describe('mutation level', () => {
it('should remove ArrowFunction', () => {
expectJSMutationWithLevel(sut, arrowFunctionLevel.ArrowFunction, 'const b = () => 4;', 'const b = () => undefined;'); // ArrowFunctionRemoval
});

it('should not mutate anything if there are no values in the mutation level', () => {
expectJSMutationWithLevel(sut, [], 'const b = () => 4;');
});
it('should not perform any ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(sut, arrowFunctionOperatorUndefinedLevel.ArrowFunction, 'const b = () => 4;');
});

it('should mutate everything if the mutation level is undefined', () => {
expectJSMutationWithLevel(sut, arrowFunctionUndefinedLevel.ArrowFunction, 'const b = () => 4;', 'const b = () => undefined;');
it('should perform all ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(sut, noLevel, 'const b = () => 4;', 'const b = () => undefined;');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,8 @@ const assignmentOperatorLevel: MutationLevel = {
name: 'AssignmentOperatorLevel',
AssignmentOperator: ['SubtractionAssignmentNegation', 'LeftShiftAssignmentNegation', 'LogicalAndAssignmentNegation'],
};
const assignmentOperatorAllLevel: MutationLevel = {
name: 'AssignmentOperatorLevel',
AssignmentOperator: [
'AdditionAssignmentNegation',
'SubtractionAssignmentNegation',
'MultiplicationAssignmentNegation',
'DivisionAssignmentNegation',
'RemainderAssignmentToMultiplicationReplacement',
'LeftShiftAssignmentNegation',
'RightShiftAssignmentNegation',
'BitwiseAndAssignmentNegation',
'BitwiseOrAssignmentNegation',
'LogicalAndAssignmentNegation',
'LogicalOrAssignmentNegation',
'NullishCoalescingAssignmentToLogicalAndReplacement',
],
};
const assignmentOperatorUndefinedLevel: MutationLevel = { name: 'AssignmentOperatorLevel' };
const assignmentOperatorUndefinedLevel: MutationLevel = { name: 'AssignmentOperatorLevel', AssignmentOperator: [] };
const noLevel = undefined;

describe(sut.name, () => {
it('should have name "AssignmentOperator"', () => {
Expand Down Expand Up @@ -97,46 +81,34 @@ describe(sut.name, () => {
expectJSMutation(sut, 'a ??= `b`', 'a &&= `b`');
});

it('should only mutate what is defined in the mutator level', () => {
expectJSMutationWithLevel(
sut,
assignmentOperatorLevel.AssignmentOperator,
'a += b; a -= b; a *= b; a /= b; a <<= b; a &&= b;',
'a += b; a += b; a *= b; a /= b; a <<= b; a &&= b;', // mutated -= to +=
'a += b; a -= b; a *= b; a /= b; a >>= b; a &&= b;', // mutated <<= to >>=
'a += b; a -= b; a *= b; a /= b; a <<= b; a ||= b;', // mutated &&= to ||=
);
});

it('should not mutate anything if there are no values in the mutation level', () => {
expectJSMutationWithLevel(sut, [], 'a += b; a -= b; a *= b; a /= b; a <<= b; a &&= b;');
});

it('should mutate everything if everything is in the mutation level', () => {
expectJSMutationWithLevel(
sut,
assignmentOperatorAllLevel.BooleanLiteral,
'a += b; a -= b; a *= b; a /= b; a <<= b; a &&= b;',
'a -= b; a -= b; a *= b; a /= b; a <<= b; a &&= b;', // mutated += to -=
'a += b; a += b; a *= b; a /= b; a <<= b; a &&= b;', // mutated -= to +=
'a += b; a -= b; a /= b; a /= b; a <<= b; a &&= b;', // mutated *= to /=
'a += b; a -= b; a *= b; a *= b; a <<= b; a &&= b;', // mutated /= to *=
'a += b; a -= b; a *= b; a /= b; a >>= b; a &&= b;', // mutated <<= to >>=
'a += b; a -= b; a *= b; a /= b; a <<= b; a ||= b;', // mutated &&= to ||=
);
});

it('should mutate everything if the mutation level is undefined', () => {
expectJSMutationWithLevel(
sut,
assignmentOperatorUndefinedLevel.BooleanLiteral,
'a += b; a -= b; a *= b; a /= b; a <<= b; a &&= b;',
'a -= b; a -= b; a *= b; a /= b; a <<= b; a &&= b;', // mutated += to -=
'a += b; a += b; a *= b; a /= b; a <<= b; a &&= b;', // mutated -= to +=
'a += b; a -= b; a /= b; a /= b; a <<= b; a &&= b;', // mutated *= to /=
'a += b; a -= b; a *= b; a *= b; a <<= b; a &&= b;', // mutated /= to *=
'a += b; a -= b; a *= b; a /= b; a >>= b; a &&= b;', // mutated <<= to >>=
'a += b; a -= b; a *= b; a /= b; a <<= b; a ||= b;', // mutated &&= to ||=
);
describe('mutation level', () => {
it('should only mutate -=, <<, &&=', () => {
expectJSMutationWithLevel(
sut,
assignmentOperatorLevel.AssignmentOperator,
'a += b; a -= b; a *= b; a /= b; a <<= b; a &&= b;',
'a += b; a += b; a *= b; a /= b; a <<= b; a &&= b;', // mutates -= to +=
'a += b; a -= b; a *= b; a /= b; a >>= b; a &&= b;', // mutates <<= to >>=
'a += b; a -= b; a *= b; a /= b; a <<= b; a ||= b;', // mutates &&= to ||=
);
});

it('should not perform any ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(sut, assignmentOperatorUndefinedLevel.AssignmentOperator, 'a += b; a -= b; a *= b; a /= b; a <<= b; a &&= b;');
});

it('should perform all ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(
sut,
noLevel,
'a += b; a -= b; a *= b; a /= b; a <<= b; a &&= b;',
'a -= b; a -= b; a *= b; a /= b; a <<= b; a &&= b;', // mutates += to -=
'a += b; a += b; a *= b; a /= b; a <<= b; a &&= b;', // mutates -= to +=
'a += b; a -= b; a /= b; a /= b; a <<= b; a &&= b;', // mutates *= to /=
'a += b; a -= b; a *= b; a *= b; a <<= b; a &&= b;', // mutates /= to *=
'a += b; a -= b; a *= b; a /= b; a >>= b; a &&= b;', // mutates <<= to >>=
'a += b; a -= b; a *= b; a /= b; a <<= b; a ||= b;', // mutates &&= to ||=
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { expectJSMutation, expectJSMutationWithLevel } from '../../helpers/expec
import { MutationLevel } from '../../../src/mutation-level/mutation-level.js';

const blockStatementLevel: MutationLevel = { name: 'BlockStatementLevel', BlockStatement: ['BlockStatementRemoval'] };
const blockStatementUndefinedLevel: MutationLevel = { name: 'BlockStatementLevel' };
const blockStatementUndefinedLevel: MutationLevel = { name: 'BlockStatementLevel', BlockStatement: [] };
const noLevel = undefined;

describe(sut.name, () => {
it('should have name "BlockStatement"', () => {
Expand Down Expand Up @@ -74,22 +75,19 @@ describe(sut.name, () => {
it('should not mutate a constructor containing a super call and contains initialized properties', () => {
expectJSMutation(sut, 'class Foo extends Bar { private baz = "qux"; constructor() { super(); } }');
});
});

it('should only mutate what is defined in the mutator level', () => {
expectJSMutationWithLevel(sut, blockStatementLevel.BlockStatement, 'class Foo { constructor() { bar(); } }', 'class Foo { constructor() {} }');
describe('mutation level', () => {
it('should remove BlockStatement', () => {
expectJSMutationWithLevel(sut, blockStatementLevel.BlockStatement, 'class Foo { constructor() { bar(); } }', 'class Foo { constructor() {} }'); // BlockStatementRemoval
});

it('should not mutate anything if there are no values in the mutation level', () => {
expectJSMutationWithLevel(sut, [], 'class Foo { constructor() { bar(); } }');
it('should not perform any ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(sut, blockStatementUndefinedLevel.BlockStatement, 'class Foo { constructor() { bar(); } }');
});

it('should mutate everything if the mutation level is undefined', () => {
expectJSMutationWithLevel(
sut,
blockStatementUndefinedLevel.BlockStatement,
'class Foo { constructor() { bar(); } }',
'class Foo { constructor() {} }',
);
it('should perform all ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(sut, noLevel, 'class Foo { constructor() { bar(); } }', 'class Foo { constructor() {} }');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ const booleanLiteralLevel: MutationLevel = {
BooleanLiteral: ['TrueLiteralNegation', 'LogicalNotRemoval'],
};

const booleanLiteralAllLevel: MutationLevel = {
name: 'BooleanLiteralLevel',
BooleanLiteral: ['TrueLiteralNegation', 'FalseLiteralNegation', 'LogicalNotRemoval'],
};

const booleanLiteralUndefinedLevel: MutationLevel = {
name: 'BooleanLiteralLevel',
BooleanLiteral: [],
};

const noLevel = undefined;

describe(sut.name, () => {
it('should have name "BooleanLiteral"', () => {
expect(sut.name).eq('BooleanLiteral');
Expand All @@ -35,39 +33,30 @@ describe(sut.name, () => {
expectJSMutation(sut, '!a', 'a');
});

it('should only mutate what is defined in the mutation level', () => {
expectJSMutationWithLevel(
sut,
booleanLiteralLevel.BooleanLiteral,
'if (true) {}; if (false) {}; if (!value) {}',
'if (false) {}; if (false) {}; if (!value) {}',
'if (true) {}; if (false) {}; if (value) {}',
);
});

it('should not mutate anything if there are no values in the mutation level', () => {
expectJSMutationWithLevel(sut, [], 'if (true) {}; if (false) {}; if (!value) {}');
});

it('should mutate everything if everything is in the mutation level', () => {
expectJSMutationWithLevel(
sut,
booleanLiteralAllLevel.BooleanLiteral,
'if (true) {}; if (false) {}; if (!value) {}',
'if (false) {}; if (false) {}; if (!value) {}',
'if (true) {}; if (false) {}; if (value) {}',
'if (true) {}; if (true) {}; if (!value) {}',
);
});

it('should mutate everything if the mutation level is undefined', () => {
expectJSMutationWithLevel(
sut,
booleanLiteralUndefinedLevel.BooleanLiteral,
'if (true) {}; if (false) {}; if (!value) {}',
'if (false) {}; if (false) {}; if (!value) {}',
'if (true) {}; if (false) {}; if (value) {}',
'if (true) {}; if (true) {}; if (!value) {}',
);
describe('mutation level', () => {
it('should only mutate TrueLiteralNegation, LogicalNotRemoval', () => {
expectJSMutationWithLevel(
sut,
booleanLiteralLevel.BooleanLiteral,
'if (true) {}; if (false) {}; if (!value) {}',
'if (false) {}; if (false) {}; if (!value) {}', // TrueLiteralNegation
'if (true) {}; if (false) {}; if (value) {}', // LogicalNotRemoval
);
});

it('should not perform any ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(sut, booleanLiteralUndefinedLevel.BooleanLiteral, 'if (true) {}; if (false) {}; if (!value) {}');
});

it('should perform all ' + sut.name + ' mutations', () => {
expectJSMutationWithLevel(
sut,
noLevel,
'if (true) {}; if (false) {}; if (!value) {}',
'if (false) {}; if (false) {}; if (!value) {}', // TrueLiteralNegation
'if (true) {}; if (false) {}; if (value) {}', // LogicalNotRemoval
'if (true) {}; if (true) {}; if (!value) {}', // FalseLiteralNegation
);
});
});
});
Loading

0 comments on commit c9a232f

Please sign in to comment.