Debian Codegraph @

test/instrumentation/test-forin.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 for-in": {
9 setUp: function (cb) {
10 code = [
11 'var x = { a: args[0], b: args[1] }, k;',
12 'output = 0;',
13 'for (k in x) {',
14 ' if (x.hasOwnProperty(k) && x[k]) {',
15 ' output += x[k];',
16 ' }',
17 '}'
18 ];
19 verifier = helper.verifier(__filename, code);
20 cb();
21 },
22
23 "should cover loop exactly once": function (test) {
24 verifier.verify(test, [ 10, 0 ], 10, { lines: { 1: 1, 2: 1, 3: 1, 4: 2, 5: 1 }, branches: { 1: [1, 1], 2: [ 2, 2 ] }, functions: {}, statements: { 1: 1, 2: 1, 3: 1, 4: 2, 5: 1 } });
25 test.done();
26 }
27 },
28
29 "with a simple for-in declaring the loop initializer": {
30 setUp: function (cb) {
31 code = [
32 'var x = { a: args[0], b: args[1] };',
33 'output = 0;',
34 'for (var k in x) {',
35 ' if (x.hasOwnProperty(k) && x[k]) {',
36 ' output += x[k];',
37 ' }',
38 '}'
39 ];
40 verifier = helper.verifier(__filename, code);
41 cb();
42 },
43
44 "should cover loop exactly once": function (test) {
45 verifier.verify(test, [ 10, 0 ], 10, { lines: { 1: 1, 2: 1, 3: 1, 4: 2, 5: 1 }, branches: { 1: [1, 1], 2: [ 2, 2 ] }, functions: {}, statements: { 1: 1, 2: 1, 3: 1, 4: 2, 5: 1 } });
46 test.done();
47 }
48 }
49 };
50