| 1 |
/*jslint nomen: true */ |
| 2 |
var helper = require('../helper'), |
| 3 |
code, |
| 4 |
verifier; |
| 5 |
|
| 6 |
/*jshint maxlen: 500 */ |
| 7 |
module.exports = { |
| 8 |
"with a simple while": { |
| 9 |
setUp: function (cb) { |
| 10 |
code = [ |
| 11 |
'var x = args[0], i=0;', |
| 12 |
'while (i < x) i++;', |
| 13 |
'output = i;' |
| 14 |
]; |
| 15 |
verifier = helper.verifier(__filename, code); |
| 16 |
cb(); |
| 17 |
}, |
| 18 |
|
| 19 |
"should cover loop exactly once": function (test) { |
| 20 |
verifier.verify(test, [ 1 ], 1, { lines: { 1: 1, 2: 1, 3: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } }); |
| 21 |
test.done(); |
| 22 |
}, |
| 23 |
"should cover loop multiple times": function (test) { |
| 24 |
verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 10, 3: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 10, '4': 1 } }); |
| 25 |
test.done(); |
| 26 |
} |
| 27 |
}, |
| 28 |
"with a simple while - statement on a different line": { |
| 29 |
setUp: function (cb) { |
| 30 |
code = [ |
| 31 |
'var x = args[0], i=0;', |
| 32 |
'while (i < x)', |
| 33 |
' i++;', |
| 34 |
'output = i;' |
| 35 |
]; |
| 36 |
verifier = helper.verifier(__filename, code); |
| 37 |
cb(); |
| 38 |
}, |
| 39 |
|
| 40 |
"should cover loop one time": function (test) { |
| 41 |
verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 1, 3: 10, 4: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 10, '4': 1 } }); |
| 42 |
test.done(); |
| 43 |
}, |
| 44 |
|
| 45 |
"should not cover loop at all": function (test) { |
| 46 |
verifier.verify(test, [ -1 ], 0, { lines: { 1: 1, 2: 1, 3: 0, 4: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1 } }); |
| 47 |
test.done(); |
| 48 |
} |
| 49 |
}, |
| 50 |
"with a simple while in block": { |
| 51 |
setUp: function (cb) { |
| 52 |
code = [ |
| 53 |
'var x = args[0], i=0;', |
| 54 |
'while (i < x) { i++; }', |
| 55 |
'output = i;' |
| 56 |
]; |
| 57 |
verifier = helper.verifier(__filename, code); |
| 58 |
cb(); |
| 59 |
}, |
| 60 |
|
| 61 |
"should cover multi-loop exactly once": function (test) { |
| 62 |
verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 10, 3: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 10, '4': 1 } }); |
| 63 |
test.done(); |
| 64 |
} |
| 65 |
}, |
| 66 |
"with a labeled while": { |
| 67 |
setUp: function (cb) { |
| 68 |
code = [ |
| 69 |
'var x = args[0], i=0, j=0, output = 0;', |
| 70 |
'outer:', |
| 71 |
' while (i++ < x) {', |
| 72 |
' j =0;', |
| 73 |
' while (j++ < i) {', |
| 74 |
' output++;', |
| 75 |
' if (j === 2) continue outer;', |
| 76 |
' }', |
| 77 |
' }' |
| 78 |
]; |
| 79 |
verifier = helper.verifier(__filename, code); |
| 80 |
cb(); |
| 81 |
}, |
| 82 |
|
| 83 |
"should provide line/branch coverage when all branches exercised": function (test) { |
| 84 |
verifier.verify(test, [ 10 ], 19, { |
| 85 |
lines: { '1': 1, '2': 1, '3': 1, '4': 10, '5': 10, '6': 19, '7': 19 }, |
| 86 |
branches: { '1': [ 9, 10 ] }, |
| 87 |
functions: {}, |
| 88 |
statements: { '1': 1, '2': 1, '3': 1, '4': 10, '5': 10, '6': 19, '7': 19, '8': 9 } |
| 89 |
}); |
| 90 |
test.done(); |
| 91 |
}, |
| 92 |
|
| 93 |
"should provide line/branch coverage when nothing exercised": function (test) { |
| 94 |
verifier.verify(test, [ -1 ], 0, { |
| 95 |
lines: { '1': 1, '2': 1, '3': 1, '4': 0, '5': 0, '6': 0, '7': 0 }, |
| 96 |
branches: { '1': [ 0, 0 ] }, |
| 97 |
functions: {}, |
| 98 |
statements: { '1': 1, '2': 1, '3': 1, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0 } |
| 99 |
}); |
| 100 |
test.done(); |
| 101 |
} |
| 102 |
} |
| 103 |
}; |
| 104 |
|