Add logicalOR coverage for "if" conditions

logical-or-coverage
cgewecke 5 years ago
parent 5566d6da2e
commit 9844e674f5
  1. 4
      lib/parse.js
  2. 18
      test/units/or.js

@ -142,6 +142,10 @@ parse.FunctionDefinition = function(contract, expression) {
parse.IfStatement = function(contract, expression) { parse.IfStatement = function(contract, expression) {
register.statement(contract, expression); register.statement(contract, expression);
register.ifStatement(contract, expression); register.ifStatement(contract, expression);
parse[expression.condition.type] &&
parse[expression.condition.type](contract, expression.condition, true);
parse[expression.trueBody.type] && parse[expression.trueBody.type] &&
parse[expression.trueBody.type](contract, expression.trueBody); parse[expression.trueBody.type](contract, expression.trueBody);

@ -24,7 +24,7 @@ describe('logical OR branches', () => {
5: 1, 8: 0 5: 1, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [1, 0], 1: [1, 0], 2: [1, 0]
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 0, 1: 1, 2: 0,
@ -47,7 +47,7 @@ describe('logical OR branches', () => {
5: 2, 8: 0 5: 2, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [2, 0], 1: [2, 0], 2: [1, 1]
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 2, 2: 0, 1: 2, 2: 0,
@ -204,7 +204,7 @@ describe('logical OR branches', () => {
5: 1, 8: 0 5: 1, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [1, 0], 1: [1, 0], 2: [1, 0]
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 0, 1: 1, 2: 0,
@ -227,7 +227,7 @@ describe('logical OR branches', () => {
5: 2, 8: 0 5: 2, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [2, 0], 1: [2, 0], 2: [1, 1]
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 2, 2: 0, 1: 2, 2: 0,
@ -238,7 +238,7 @@ describe('logical OR branches', () => {
}); });
// if ((x == 1) && (x == 2 || true)) { // if ((x == 1) && (x == 2 || true)) {
it('should cover an if statement with bracked ANDED OR and AND conditions (both branches)', async function() { it('should cover an if statement with bracked ANDED OR conditions (rightmost sub-branch)', async function() {
const contract = await util.bootstrapCoverage('or/and-or-brackets', provider, collector); const contract = await util.bootstrapCoverage('or/and-or-brackets', provider, collector);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
@ -249,7 +249,7 @@ describe('logical OR branches', () => {
5: 1, 8: 0 5: 1, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [1, 0], 1: [1, 0], 2: [0, 1]
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 0, 1: 1, 2: 0,
@ -271,7 +271,7 @@ describe('logical OR branches', () => {
5: 1, 8: 0 5: 1, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [1, 0], 1: [1, 0], 2: [0, 0], 3: [1, 0] // Item 3 is the "outer" (left) OR clause
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 0, 1: 1, 2: 0,
@ -293,7 +293,7 @@ describe('logical OR branches', () => {
5: 1, 8: 0 5: 1, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [1, 0], 1: [1, 0], 2: [1, 0], 3: [0, 1] // Item 3 is the "outer" (left) OR clause
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 0, 1: 1, 2: 0,
@ -315,7 +315,7 @@ describe('logical OR branches', () => {
5: 1, 8: 0 5: 1, 8: 0
}); });
assert.deepEqual(mapping[util.filePath].b, { assert.deepEqual(mapping[util.filePath].b, {
1: [1, 0], 1: [1, 0], 2: [0, 1], 3: [0, 1]
}); });
assert.deepEqual(mapping[util.filePath].s, { assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 0, 1: 1, 2: 0,

Loading…
Cancel
Save