diff --git a/src/processors/suite-numbering-processor.js b/src/processors/suite-numbering-processor.js index f87360c9..19c7fcda 100644 --- a/src/processors/suite-numbering-processor.js +++ b/src/processors/suite-numbering-processor.js @@ -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(); } } diff --git a/src/spec-display.js b/src/spec-display.js index ec4adbc6..015a14a5 100644 --- a/src/spec-display.js +++ b/src/spec-display.js @@ -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}); } },