-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmutators_switchCasesMutator.js.html
More file actions
119 lines (95 loc) · 6.03 KB
/
Copy pathmutators_switchCasesMutator.js.html
File metadata and controls
119 lines (95 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>mutators/switchCasesMutator.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Mutode.html">Mutode</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Mutode.html#run">run</a></span></li><li class="nav-heading">Modules</li><li class="nav-heading"><span class="nav-item-type type-module">M</span><span class="nav-item-name"><a href="module-MutantRunner.html">MutantRunner</a></span></li><li class="nav-heading"><span class="nav-item-type type-module">M</span><span class="nav-item-name"><a href="module-Mutators.html">Mutators</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.conditionalsBoundaryMutator">conditionalsBoundaryMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.deletionMutator">deletionMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.incrementsMutator">incrementsMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.invertNegativesMutator">invertNegativesMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.mathMutator">mathMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.negateConditionalsMutator">negateConditionalsMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.removeConditionalsMutator">removeConditionalsMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.returnValuesMutator">returnValuesMutator</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="module-Mutators.html#.switchCasesMutator">switchCasesMutator</a></span></li>
</nav>
<div id="main">
<h1 class="page-title">mutators/switchCasesMutator.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const walk = require('babylon-walk')
const debug = require('debug')('mutode:incrementsMutator')
const mutantRunner = require('../mutantRunner')
const lineDiff = require('../util/lineDiff')
/**
* @description Mutates switch cases test values.
* Negates booleans.
* Numbers > 0 are mutated to 0, 0 is mutated to 1.
* String are mutated to a random string.
* @function switchCasesMutator
* @memberOf module:Mutators
*/
module.exports = async function switchCasesMutator ({mutodeInstance, filePath, lines, queue, ast}) {
debug('Running switch cases mutator on %s', filePath)
walk.simple(ast, {
SwitchCase (node) {
const line = node.loc.start.line
const lineContent = lines[line - 1]
let mutantLineContent = lineContent
if (!node.test) return
switch (node.test.type) {
case 'BooleanLiteral': {
const newCaseValue = !node.test.value
mutantLineContent = lineContent.substr(0, node.test.loc.start.column) +
newCaseValue +
lineContent.substr(node.test.loc.end.column)
break
}
case 'NumericLiteral': {
const newCaseValue = node.test.value === 0 ? 1 : 0
mutantLineContent = lineContent.substr(0, node.test.loc.start.column) +
newCaseValue +
lineContent.substr(node.test.loc.end.column)
break
}
case 'StringLiteral': {
const newCaseValue = `'${Math.random().toString(36).replace(/[^a-z]+/g, '')}'`
mutantLineContent = lineContent.substr(0, node.test.loc.start.column) +
newCaseValue +
lineContent.substr(node.test.loc.end.column)
break
}
}
const mutantId = ++mutodeInstance.mutants
const diff = lineDiff(lineContent, mutantLineContent)
const log = `MUTANT ${mutantId}:\tSCM Line ${line}:\t${diff}...`
debug(log)
mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tSCM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
const linesCopy = lines.slice()
linesCopy[line - 1] = mutantLineContent
const contentToWrite = linesCopy.join('\n')
queue.push(mutantRunner({mutodeInstance, filePath, contentToWrite, log}))
}
})
}
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Apr 05 2018 21:59:37 GMT-0500 (-05) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>