Permalink
Browse files

Fixes #1 - Added Branch parsing support

  • Loading branch information...
1 parent 1693248 commit ff0e6a75986275d1c55391434c03ad498efc7ada @davglass committed Jan 15, 2013
Showing with 67 additions and 13 deletions.
  1. +30 −9 lib/index.js
  2. +26 −0 tests/info/parts.info
  3. +11 −4 tests/parse.js
View
@@ -1,17 +1,16 @@
var fs = require('fs'),
path = require('path'),
-
exists = fs.exists || path.exists;
-var results = {};
-
var walkFile = function(str, cb) {
- var data = [];
+ var data = [], item = {};
+
str = str.split('\n');
- var item = {};
str.forEach(function(line) {
line = line.trim();
- var parts = line.split(':');
+
+ var parts = line.split(':'), lines, fn;
+
switch (parts[0].toUpperCase()) {
case 'TN':
item.title = parts[1].trim();
@@ -39,7 +38,7 @@ var walkFile = function(str, cb) {
details: []
};
}
- var lines = parts[1].split(',');
+ lines = parts[1].split(',');
item.lines.details.push({
line: Number(lines[0]),
hit: Number(lines[1])
@@ -53,21 +52,43 @@ var walkFile = function(str, cb) {
details: []
};
}
- var fn = parts[1].split(',');
+ fn = parts[1].split(',');
item.functions.details.push({
name: fn[1],
line: Number(fn[0])
});
break;
case 'FNDA':
- var fn = parts[1].split(',');
+ fn = parts[1].split(',');
item.functions.details.some(function(i, k) {
if (i.name === fn[1] && i.hit === undefined) {
item.functions.details[k].hit = Number(fn[0]);
return true;
}
});
break;
+ case 'BRDA':
+ if (!item.branches) {
+ item.branches = {
+ hit: 0,
+ found: 0,
+ details: []
+ };
+ }
+ fn = parts[1].split(',');
+ item.branches.details.push({
+ line: Number(fn[0]),
+ block: Number(fn[1]),
+ branch: Number(fn[2]),
+ taken: ((fn[3] === '-') ? 0 : Number(fn[3]))
+ });
+ break;
+ case 'BRF':
+ item.branches.found = Number(parts[1]);
+ break;
+ case 'BRH':
+ item.branches.hit = Number(parts[1]);
+ break;
}
if (line.indexOf('end_of_record') > -1) {
View
@@ -366,4 +366,30 @@ DA:353,6
LF:76
LH:70
+
+BRDA:3,1,0,1
+BRDA:3,1,1,0
+BRDA:13,2,0,2
+BRDA:13,2,1,2
+BRDA:13,2,2,2
+BRDA:13,2,3,2
+BRDA:13,2,4,2
+BRDA:13,2,5,2
+BRDA:13,2,6,257
+BRDA:13,2,7,46
+BRDA:13,2,8,46
+BRDA:33,3,0,2
+BRDA:33,3,1,255
+BRDA:47,4,0,2
+BRDA:47,4,1,44
+BRDA:63,5,0,46
+BRDA:63,5,1,542
+BRDA:63,6,0,588
+BRDA:63,6,1,51
+BRDA:71,7,0,2
+BRDA:71,7,1,368
+BRDA:82,8,0,1
+BRDA:82,8,1,-
+BRF:23
+BRH:22
end_of_record
View
@@ -1,11 +1,10 @@
var vows = require('vows'),
path = require('path'),
assert = require('assert'),
- parse = require(path.join(__dirname, '../lib')),
+ parse = require('../lib'),
yuiFile = path.join(__dirname, 'info/parts.info');
-
-vows.describe('Test Loading and Bindings').addBatch({
+var tests = {
'Should be loaded': {
topic: function() {
return parse;
@@ -52,6 +51,12 @@ vows.describe('Test Loading and Bindings').addBatch({
assert.equal(data[1].functions.found, 17);
assert.equal(data[1].functions.hit, 17);
},
+ 'verify number of branches': function(err, data) {
+ assert.equal(data[1].branches.found, 23);
+ assert.equal(data[1].branches.hit, 22);
+ assert.equal(data[1].branches.found, data[1].branches.details.length);
+ assert.equal(data[1].branches.details[data[1].branches.details.length - 1].taken, 0);
+ },
'verify function details': function(err, data) {
assert.equal(data[0].functions.details.length, 29);
assert.equal(data[1].functions.details.length, 17);
@@ -81,5 +86,7 @@ vows.describe('Test Loading and Bindings').addBatch({
},
}
-}).export(module);
+};
+
+vows.describe('Test Loading and Bindings').addBatch(tests)['export'](module);

0 comments on commit ff0e6a7

Please sign in to comment.