Skip to content

Commit

Permalink
fix suite numbering #10
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Jan 24, 2015
1 parent ee2f5f3 commit 37cbbfe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
43 changes: 25 additions & 18 deletions src/processors/suite-numbering-processor.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
var DisplayProcessor = require('../display-processor');

function SuiteNumberingProcessor() {
this.suites = {};
this.currentHierarchy = [];

this.computeNumber = function (suite) {
var count = this.computeSuiteNumber(suite);
return this.computeParentNumber(suite, count);
this.computeHierarchy(suite);
return this.computeHierarchyNumber();
};
this.computeParentNumber = function (suite, count) {
var parent = suite.parentSuite;
while (parent != null) {
parent = parent.parentSuite;
count = this.suites[getId(parent)].count + "." + count;

this.computeHierarchy = function (suite) {
var parentName = this.getParentName(suite);
for (var i = 0 ; i < this.currentHierarchy.length ; i++) {
if (this.currentHierarchy[i].name == parentName) {
this.currentHierarchy[i].number++;
this.currentHierarchy.splice(i + 1, this.currentHierarchy.length - i - 1);
break;
}
}
if (i == this.currentHierarchy.length) {
this.currentHierarchy.push({name: parentName, number: 1})
}
return count;
};
this.computeSuiteNumber = function (suite) {
var parentId = getId(suite.parentSuite);
if (!this.suites[parentId]) {
this.suites[parentId] = {
count: 0
}

this.computeHierarchyNumber = function () {
var number = '';
for (var i = 0 ; i < this.currentHierarchy.length ; i++) {
number += this.currentHierarchy[i].number + '.';
}
return ++this.suites[parentId].count
return number.substring(0, number.length - 1);
};
function getId(suite) {
return (suite) ? suite.id : null;

this.getParentName = function (element) {
return element.fullName.replace(element.description, '').trim();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/spec-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SpecDisplay.prototype = {
ensureSuiteDisplayed: function (spec) {
if (this.displayedSuites.length == 0) {
var suiteName = this.getParentName(spec).trim();
this.suite({fullName: suiteName, description: suiteName});
this.suite({id: 'single suite', fullName: suiteName, description: suiteName});
}
},

Expand Down

0 comments on commit 37cbbfe

Please sign in to comment.