Debian Codegraph @

test/instrumentation/test-switch.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 an empty switch": {
9 setUp: function (cb) {
10 code = [
11 'output = "unknown";',
12 'switch (args[0]) {',
13 '}'
14 ];
15 verifier = helper.verifier(__filename, code);
16 cb(null);
17 },
18 "should not barf in any way": function (test) {
19 verifier.verify(test, [ "1" ], "unknown", { lines: { 1: 1, 2: 1 }, branches: {}, functions: {}, statements: { 1: 1, 2: 1 } });
20 test.done();
21 }
22 },
23 "with a simple switch": {
24 "and 2 cases without a default": {
25 setUp: function (cb) {
26 code = [
27 'output = "unknown";',
28 'switch (args[0]) {',
29 ' case "1": output = "one"; break;',
30 ' case "2": output = "two"; break;',
31 '}'
32 ];
33 verifier = helper.verifier(__filename, code);
34 cb(null);
35 },
36 "should cover one path": function (test) {
37 verifier.verify(test, [ "1" ], "one", { lines: { 1: 1, 2: 1, 3: 1, 4: 0 }, branches: { '1': [ 1, 0 ] }, functions: {}, statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 0, 6: 0 } });
38 test.done();
39 },
40 "should cover two path": function (test) {
41 verifier.verify(test, [ "2" ], "two", { lines: { 1: 1, 2: 1, 3: 0, 4: 1 }, branches: { '1': [ 0, 1 ] }, functions: {}, statements: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 1, 6: 1 } });
42 test.done();
43 },
44 "should cover unknown path": function (test) {
45 verifier.verify(test, [ "3" ], "unknown", { lines: { 1: 1, 2: 1, 3: 0, 4: 0 }, branches: { '1': [ 0, 0 ] }, functions: {}, statements: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 0, 6: 0 } });
46 test.done();
47 }
48 },
49 "and 2 cases with a default": {
50 setUp: function (cb) {
51 code = [
52 'output = "unknown";',
53 'switch (args[0]) {',
54 ' case "1": output = "one"; break;',
55 ' case "2": output = "two"; break;',
56 ' default: output = "three";',
57 '}'
58 ];
59 verifier = helper.verifier(__filename, code);
60 cb(null);
61 },
62 "should cover one path": function (test) {
63 verifier.verify(test, [ "1" ], "one", { lines: { 1: 1, 2: 1, 3: 1, 4: 0, 5: 0 }, branches: { '1': [ 1, 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });
64 test.done();
65 },
66 "should cover two path": function (test) {
67 verifier.verify(test, [ "2" ], "two", { lines: { 1: 1, 2: 1, 3: 0, 4: 1, 5: 0 }, branches: { '1': [ 0, 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 1, '6': 1, '7': 0 } });
68 test.done();
69 },
70 "should cover unknown path": function (test) {
71 verifier.verify(test, [ "4" ], "three", { lines: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 1 }, branches: { '1': [ 0, 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 1 } });
72 test.done();
73 }
74 },
75 "and 2 cases with a default everything squeezed on one line": {
76 setUp: function (cb) {
77 code = [
78 'output = "unknown";',
79 'switch (args[0]) {' +
80 ' case "1": output = "one"; break;' +
81 ' case "2": output = "two"; break;' +
82 ' default: output = "three";' +
83 '}'
84 ];
85 verifier = helper.verifier(__filename, code);
86 cb(null);
87 },
88 "should cover one path": function (test) {
89 verifier.verify(test, [ "1" ], "one", { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 0, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1, '5': 0, '6': 0, '7': 0 } });
90 test.done();
91 },
92 "should cover two path": function (test) {
93 verifier.verify(test, [ "2" ], "two", { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1, 0 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 1, '6': 1, '7': 0 } });
94 test.done();
95 },
96 "should cover unknown path": function (test) {
97 verifier.verify(test, [ "4" ], "three", { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 0, '6': 0, '7': 1 } });
98 test.done();
99 }
100 },
101 "and 2 cases with a default and fall-thru": {
102 setUp: function (cb) {
103 code = [
104 'output = "";',
105 'switch (args[0]) {',
106 ' case "1": output += "one";',
107 ' case "2": output += "two";',
108 ' default: output += "three";',
109 '}'
110 ];
111 verifier = helper.verifier(__filename, code);
112 cb(null);
113 },
114 "should cover one path": function (test) {
115 verifier.verify(test, [ "1" ], "onetwothree", { lines: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1 }, branches: { '1': [ 1, 1, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1 } });
116 test.done();
117 },
118 "should cover two path": function (test) {
119 verifier.verify(test, [ "2" ], "twothree", { lines: { 1: 1, 2: 1, 3: 0, 4: 1, 5: 1 }, branches: { '1': [ 0, 1, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 1 } });
120 test.done();
121 },
122 "should cover unknown path": function (test) {
123 verifier.verify(test, [ "4" ], "three", { lines: { 1: 1, 2: 1, 3: 0, 4: 0, 5: 1 }, branches: { '1': [ 0, 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 1 } });
124 test.done();
125 }
126 },
127 "and 2 cases with a default and fall-thru all on one line": {
128 setUp: function (cb) {
129 code = [
130 'output = "";',
131 'switch (args[0]) {' +
132 ' case "1": output += "one";' +
133 ' case "2": output += "two";' +
134 ' default: output += "three";' +
135 '}'
136 ];
137 verifier = helper.verifier(__filename, code);
138 cb(null);
139 },
140 "should cover one path": function (test) {
141 verifier.verify(test, [ "1" ], "onetwothree", { lines: { 1: 1, 2: 1 }, branches: { '1': [ 1, 1, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1 } });
142 test.done();
143 },
144 "should cover two path": function (test) {
145 verifier.verify(test, [ "2" ], "twothree", { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 1, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 1, '5': 1 } });
146 test.done();
147 },
148 "should cover unknown path": function (test) {
149 verifier.verify(test, [ "4" ], "three", { lines: { 1: 1, 2: 1 }, branches: { '1': [ 0, 0, 1 ] }, functions: {}, statements: { '1': 1, '2': 1, '3': 0, '4': 0, '5': 1 } });
150 test.done();
151 }
152 }
153 }
154 };
155