Debian Codegraph @

test/instrumentation/test-locations.js

raw
1 /*jslint nomen: true */
2 var helper = require('../helper'),
3 verifier,
4 code;
5
6 /*jshint maxlen: 500 */
7 module.exports = {
8 "with a function and if branch all in one line": {
9 setUp: function (cb) {
10 code = [
11 'function foo() { if (true) { return "bar"; } else { return "baz"; } } output = foo();'
12 ];
13 verifier = helper.verifier(__filename, code);
14 cb();
15 },
16 "should report locations correctly": function (test) {
17 verifier.verify(test, [], 'bar', { lines: { '1': 1 }, branches: { 1: [ 1, 0 ] }, functions: { 1: 1 }, statements: { '1': 1, '2': 1, '3': 1, '4': 0, '5': 1 }});
18 var cov = verifier.getFileCoverage();
19 test.deepEqual({
20 "1": {
21 "name": "foo",
22 "line": 1,
23 "loc": {
24 "start": {
25 "line": 1,
26 "column": 0
27 },
28 "end": {
29 "line": 1,
30 "column": 15
31 }
32 }
33 }
34 }, cov.fnMap);
35 test.deepEqual({
36 "1": {
37 "line": 1,
38 "type": "if",
39 "locations": [
40 {
41 "start": {
42 "line": 1,
43 "column": 17
44 },
45 "end": {
46 "line": 1,
47 "column": 17
48 }
49 },
50 {
51 "start": {
52 "line": 1,
53 "column": 17
54 },
55 "end": {
56 "line": 1,
57 "column": 17
58 }
59 }
60 ]
61 }
62 }, cov.branchMap);
63 test.deepEqual({
64 "start": {
65 "line": 1,
66 "column": 0
67 },
68 "end": {
69 "line": 1,
70 "column": 69
71 }
72 }, cov.statementMap[1]);
73 test.done();
74 }
75 },
76 "with a switch statement all in one line": {
77 setUp: function (cb) {
78 code = [
79 [
80 'output = "unknown";',
81 'switch (args[0]) {',
82 ' case "1": output = "one"; break;',
83 ' case "2": output = "two"; break;',
84 '}'
85 ].join(' ')
86 ];
87 verifier = helper.verifier(__filename, code);
88 cb();
89 },
90 "should report locations correctly": function (test) {
91 verifier.verify(test, [ "1" ], "one", { lines: { 1: 1 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 0, 6: 0 } });
92 var cov = verifier.getFileCoverage();
93 test.deepEqual({
94 "1": {
95 "line": 1,
96 "type": "switch",
97 "locations": [
98 {
99 "start": {
100 "line": 1,
101 "column": 42
102 },
103 "end": {
104 "line": 1,
105 "column": 74
106 }
107 },
108 {
109 "start": {
110 "line": 1,
111 "column": 78
112 },
113 "end": {
114 "line": 1,
115 "column": 110
116 }
117 }
118 ]
119 }
120 }, cov.branchMap);
121 test.done();
122 }
123 }
124 };
125