diff --git a/lib/parse.js b/lib/parse.js index 2e45cde..4765637 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -142,6 +142,10 @@ parse.FunctionDefinition = function(contract, expression) { parse.IfStatement = function(contract, expression) { register.statement(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](contract, expression.trueBody); diff --git a/test/units/or.js b/test/units/or.js index 4b59246..74a9a22 100644 --- a/test/units/or.js +++ b/test/units/or.js @@ -24,7 +24,7 @@ describe('logical OR branches', () => { 5: 1, 8: 0 }); assert.deepEqual(mapping[util.filePath].b, { - 1: [1, 0], + 1: [1, 0], 2: [1, 0] }); assert.deepEqual(mapping[util.filePath].s, { 1: 1, 2: 0, @@ -47,7 +47,7 @@ describe('logical OR branches', () => { 5: 2, 8: 0 }); assert.deepEqual(mapping[util.filePath].b, { - 1: [2, 0], + 1: [2, 0], 2: [1, 1] }); assert.deepEqual(mapping[util.filePath].s, { 1: 2, 2: 0, @@ -204,7 +204,7 @@ describe('logical OR branches', () => { 5: 1, 8: 0 }); assert.deepEqual(mapping[util.filePath].b, { - 1: [1, 0], + 1: [1, 0], 2: [1, 0] }); assert.deepEqual(mapping[util.filePath].s, { 1: 1, 2: 0, @@ -227,7 +227,7 @@ describe('logical OR branches', () => { 5: 2, 8: 0 }); assert.deepEqual(mapping[util.filePath].b, { - 1: [2, 0], + 1: [2, 0], 2: [1, 1] }); assert.deepEqual(mapping[util.filePath].s, { 1: 2, 2: 0, @@ -238,7 +238,7 @@ describe('logical OR branches', () => { }); // 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); coverage.addContract(contract.instrumented, util.filePath); await contract.instance.a(1); @@ -249,7 +249,7 @@ describe('logical OR branches', () => { 5: 1, 8: 0 }); assert.deepEqual(mapping[util.filePath].b, { - 1: [1, 0], + 1: [1, 0], 2: [0, 1] }); assert.deepEqual(mapping[util.filePath].s, { 1: 1, 2: 0, @@ -271,7 +271,7 @@ describe('logical OR branches', () => { 5: 1, 8: 0 }); 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, { 1: 1, 2: 0, @@ -293,7 +293,7 @@ describe('logical OR branches', () => { 5: 1, 8: 0 }); 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, { 1: 1, 2: 0, @@ -315,7 +315,7 @@ describe('logical OR branches', () => { 5: 1, 8: 0 }); assert.deepEqual(mapping[util.filePath].b, { - 1: [1, 0], + 1: [1, 0], 2: [0, 1], 3: [0, 1] }); assert.deepEqual(mapping[util.filePath].s, { 1: 1, 2: 0,