| 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 expression": { |
| 9 |
setUp: function (cb) { |
| 10 |
code = [ |
| 11 |
'var x = args[0] > 0 && args[0] < 5;', |
| 12 |
'output = x;' |
| 13 |
]; |
| 14 |
verifier = helper.verifier(__filename, code); |
| 15 |
cb(); |
| 16 |
}, |
| 17 |
|
| 18 |
"should cover line and one branch": function (test) { |
| 19 |
verifier.verify(test, [ -1 ], false, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 0 ]}, functions: {}, statements: { '1': 1, '2': 1 } }); |
| 20 |
test.done(); |
| 21 |
}, |
| 22 |
"should cover line, both branches but return false": function (test) { |
| 23 |
verifier.verify(test, [ 10 ], false, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 1 ]}, functions: {}, statements: { '1': 1, '2': 1 } }); |
| 24 |
test.done(); |
| 25 |
}, |
| 26 |
"should cover line, both branches and return true": function (test) { |
| 27 |
verifier.verify(test, [ 3 ], true, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 1 ]}, functions: {}, statements: { '1': 1, '2': 1 } }); |
| 28 |
test.done(); |
| 29 |
} |
| 30 |
}, |
| 31 |
"with a complex expression": { |
| 32 |
setUp: function (cb) { |
| 33 |
code = [ |
| 34 |
'var x = args[0] > 0 && (args[0] < 5 || args[0] > 10);', |
| 35 |
'output = x;' |
| 36 |
]; |
| 37 |
verifier = helper.verifier(__filename, code); |
| 38 |
cb(); |
| 39 |
}, |
| 40 |
|
| 41 |
"should cover line and one branch": function (test) { |
| 42 |
verifier.verify(test, [ -1 ], false, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 0, 0 ]}, functions: {}, statements: { '1': 1, '2': 1 } }); |
| 43 |
test.done(); |
| 44 |
}, |
| 45 |
"should cover line, both branches but return false": function (test) { |
| 46 |
verifier.verify(test, [ 9 ], false, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 1, 1 ]}, functions: {}, statements: { '1': 1, '2': 1 } }); |
| 47 |
test.done(); |
| 48 |
}, |
| 49 |
"should cover line, both branches and return true": function (test) { |
| 50 |
verifier.verify(test, [ 3 ], true, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 1, 0 ]}, functions: {}, statements: { '1': 1, '2': 1 } }); |
| 51 |
test.done(); |
| 52 |
} |
| 53 |
}, |
| 54 |
"with an array expression with empty positions": { |
| 55 |
setUp: function (cb) { |
| 56 |
code = [ |
| 57 |
'var x = [args[0], , args[1], ];', |
| 58 |
'output = x.indexOf(args[1]) === x.length - 1 && x[0] !== x[1];' |
| 59 |
]; |
| 60 |
verifier = helper.verifier(__filename, code); |
| 61 |
cb(); |
| 62 |
}, |
| 63 |
|
| 64 |
"should not barf in any way": function (test) { |
| 65 |
verifier.verify(test, [ 1, 5 ], true, { lines: { 1: 1, 2: 1 }, branches: { 1: [ 1, 1 ]}, functions: {}, statements: { '1': 1, '2': 1 } }); |
| 66 |
test.done(); |
| 67 |
} |
| 68 |
} |
| 69 |
}; |
| 70 |
|