mutode icon indicating copy to clipboard operation
mutode copied to clipboard

Math mutator: Don't mutate string concatenation '+'

Open DiegoRBaquero opened this issue 7 years ago • 7 comments

DiegoRBaquero avatar Apr 25 '18 17:04 DiegoRBaquero

Why not? It's valid JavaScript.

simondel avatar Apr 25 '18 17:04 simondel

Valid JavaScript but results in NaN. Easily caught while coding, when failing to see the expected text or by a linter. Saves many mutators when there are many concatenations -> saves time.

DiegoRBaquero avatar Apr 25 '18 18:04 DiegoRBaquero

True, but how big of an issue is this in modern JavaScript code? Since you won't have this issue with template strings.

simondel avatar Apr 25 '18 19:04 simondel

Small, even more reason to not mutate it as template strings take over.

DiegoRBaquero avatar Apr 25 '18 19:04 DiegoRBaquero

:thumbsup: your call. You could also keep it in to encourage devs to switch to template strings.

In the case of Stryker, the only complaints we got from mutating string concatenation was from TypeScript users and we fixed that by using the TypeScript compiler together with the projects tsconfig.json to determine which code would cause a transpiler error.

simondel avatar Apr 25 '18 19:04 simondel

This I like

You could also keep it in to encourage devs to switch to template strings.

How did you mutate string concat? + to - too?

DiegoRBaquero avatar Apr 25 '18 22:04 DiegoRBaquero

Yes. We don't look at the types of the left or right operand in binary expressions. We simply change the plus token into a minus token.

With JavaScript code, the mutant will actually get tested. With TypeScript it will first be ran though the TypeScript compiler which will (in most cases) cause an error. Mutants that cause a transpilation error are not tested and not counted in the score.

simondel avatar Apr 26 '18 08:04 simondel