| 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 function": { |
| 9 |
setUp: function (cb) { |
| 10 |
code = [ |
| 11 |
'var x = args[0];', |
| 12 |
'function foo() {', |
| 13 |
' return 42;', |
| 14 |
'}', |
| 15 |
'output = x < 5 ? foo() : 15;' |
| 16 |
]; |
| 17 |
verifier = helper.verifier(__filename, code); |
| 18 |
cb(); |
| 19 |
}, |
| 20 |
|
| 21 |
"should cover line and function": function (test) { |
| 22 |
verifier.verify(test, [ 2 ], 42, { lines: { 1: 1, 2: 1, 3: 1, 5: 1 }, branches: { 1: [1, 0 ] }, functions: { 1: 1 }, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } }); |
| 23 |
test.done(); |
| 24 |
}, |
| 25 |
|
| 26 |
"should not cover function": function (test) { |
| 27 |
verifier.verify(test, [ 10 ], 15, { lines: { 1: 1, 2: 1, 3: 0, 5: 1 }, branches: { 1: [ 0, 1 ]}, functions: { 1: 0 }, statements: { '1': 1, '2': 1, '3': 0, '4': 1 } }); |
| 28 |
test.done(); |
| 29 |
} |
| 30 |
}, |
| 31 |
|
| 32 |
"with an anonymous function": { |
| 33 |
setUp: function (cb) { |
| 34 |
code = [ |
| 35 |
'var x = args[0];', |
| 36 |
'output = x < 5 ? (function() { return 42; }()) : 15;' |
| 37 |
]; |
| 38 |
verifier = helper.verifier(__filename, code); |
| 39 |
cb(); |
| 40 |
}, |
| 41 |
|
| 42 |
"should cover line and function": function (test) { |
| 43 |
verifier.verify(test, [ 2 ], 42, { lines: { 1: 1, 2: 1 }, branches: { 1: [1, 0 ] }, functions: { 1: 1 }, statements: { '1': 1, '2': 1, '3': 1 } }); |
| 44 |
test.done(); |
| 45 |
}, |
| 46 |
|
| 47 |
"should not cover function": function (test) { |
| 48 |
verifier.verify(test, [ 10 ], 15, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 0, 1 ]}, functions: { 1: 0 }, statements: { '1': 1, '2': 1, '3': 0 } }); |
| 49 |
test.done(); |
| 50 |
} |
| 51 |
}, |
| 52 |
|
| 53 |
"with an anonymous function on newline": { |
| 54 |
setUp: function (cb) { |
| 55 |
code = [ |
| 56 |
'var x = args[0];', |
| 57 |
'output = x < 5 ? ', |
| 58 |
' (function() { ', |
| 59 |
' return 42; ', |
| 60 |
'}())', |
| 61 |
' : 15;' |
| 62 |
]; |
| 63 |
verifier = helper.verifier(__filename, code); |
| 64 |
cb(); |
| 65 |
}, |
| 66 |
|
| 67 |
"should cover line and function": function (test) { |
| 68 |
verifier.verify(test, [ 2 ], 42, { lines: { 1: 1, 2: 1, 4: 1 }, branches: { 1: [1, 0 ] }, functions: { 1: 1 }, statements: { 1: 1, 2: 1, 3: 1} }); |
| 69 |
test.done(); |
| 70 |
}, |
| 71 |
|
| 72 |
"should not cover function": function (test) { |
| 73 |
verifier.verify(test, [ 10 ], 15, { lines: { 1: 1, 2: 1, 4: 0 }, branches: { 1: [ 0, 1 ]}, functions: { 1: 0 }, statements: { 1: 1, 2: 1, 3: 0 } }); |
| 74 |
test.done(); |
| 75 |
} |
| 76 |
}, |
| 77 |
|
| 78 |
"with a function declared in an 'unreachable' place": { |
| 79 |
setUp: function (cb) { |
| 80 |
code = [ |
| 81 |
'function foo(x) {', |
| 82 |
' return bar(x);', |
| 83 |
' function bar(y) { return y * 2 }', |
| 84 |
'}', |
| 85 |
'output = args[0] < 2 ? 2: foo(args[0]);' |
| 86 |
]; |
| 87 |
verifier = helper.verifier(__filename, code); |
| 88 |
cb(); |
| 89 |
}, |
| 90 |
|
| 91 |
"should not cover functions but should cover declarations": function (test) { |
| 92 |
verifier.verify(test, [ 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 5: 1 }, branches: { 1: [1, 0 ] }, functions: { 1: 0, 2: 0 }, statements: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1} }); |
| 93 |
test.done(); |
| 94 |
}, |
| 95 |
|
| 96 |
"should cover functions and declarations": function (test) { |
| 97 |
verifier.verify(test, [ 10 ], 20, { lines: { 1: 1, 2: 1, 3: 1, 5: 1 }, branches: { 1: [ 0, 1 ]}, functions: { 1: 1, 2: 1 }, statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1 } }); |
| 98 |
test.done(); |
| 99 |
} |
| 100 |
} |
| 101 |
}; |
| 102 |
|