Debian Codegraph @

test/instrumentation/test-do.js

raw
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 do-while": {
9 setUp: function (cb) {
10 code = [
11 'var x = args[0], i=0;',
12 'do { i++; } while (i < x);',
13 'output = i;'
14 ];
15 verifier = helper.verifier(__filename, code);
16 cb();
17 },
18
19 "should provide correct line coverage": function (test) {
20 verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 10, 3: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 10, '4': 1 } });
21 test.done();
22 },
23
24 "should cover single-entry into while": function (test) {
25 verifier.verify(test, [ -1 ], 1, { lines: { 1: 1, 2: 1, 3: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } });
26 test.done();
27 }
28 },
29 "with a block do-while on separate line": {
30 setUp: function (cb) {
31 code = [
32 'var x = args[0], i=0;',
33 'do { ',
34 ' i++; ',
35 '} while (i < x);',
36 'output = i;'
37 ];
38 verifier = helper.verifier(__filename, code);
39 cb();
40 },
41
42 "should provide correct line coverage": function (test) {
43 verifier.verify(test, [ 10 ], 10, { lines: { 1: 1, 2: 1, 3: 10, 5: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 10, '4': 1 } });
44 test.done();
45 },
46
47 "should cover single-entry into while": function (test) {
48 verifier.verify(test, [ -1 ], 1, { lines: { 1: 1, 2: 1, 3: 1, 5: 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1 } });
49 test.done();
50 }
51 },
52 "with an ignore inside a do-while": {
53 setUp: function (cb) {
54 code = [
55 'do { ',
56 ' /* istanbul ignore next */ ',
57 ' console.log("hi");',
58 '} while (false);',
59 'output = 10'
60 ];
61 verifier = helper.verifier(__filename, code);
62 cb();
63 },
64
65 "should mark statement as skipped": function (test) {
66 verifier.verify(test, [], 10, { lines: { '1': 1, '3': 1, '5': 1 }, branches: {}, functions: {}, statements: { '1': 1, '2': 1, '3': 1 } });
67 var cov = verifier.getFileCoverage();
68 test.equal(true, cov.statementMap[2].skip);
69 test.done();
70 }
71 }
72 };
73