diff --git a/lib/jsdoc/name.js b/lib/jsdoc/name.js index 1e9124a9..17172ea8 100644 --- a/lib/jsdoc/name.js +++ b/lib/jsdoc/name.js @@ -197,6 +197,11 @@ exports.applyNamespace = function(longname, ns) { return longname; }; +// TODO: docs +exports.stripNamespace = function(longname) { + return longname.replace(/^[a-zA-Z]+:/, ''); +}; + // TODO: docs function atomize(longname, sliceChars, forcedMemberof) { var i; @@ -290,9 +295,14 @@ exports.combine = function(parts) { (parts.variation || ''); }; -function stripVariation(name) { - return name.replace(/\([^)]\)$/, ''); -} +// TODO: docs +exports.stripVariation = function(name) { + var parts = exports.shorten(name); + + parts.variation = ''; + + return exports.combine(parts); +}; function splitLongname(longname, options) { var chunks = []; @@ -307,7 +317,7 @@ function splitLongname(longname, options) { do { if (!options.includeVariation) { - previousName = stripVariation(previousName); + previousName = exports.stripVariation(previousName); } currentNameInfo = nameInfo[previousName] = atomize(previousName, splitters); previousName = currentNameInfo.memberof; diff --git a/test/specs/jsdoc/name.js b/test/specs/jsdoc/name.js index 9e1a412b..d7e88851 100644 --- a/test/specs/jsdoc/name.js +++ b/test/specs/jsdoc/name.js @@ -21,6 +21,10 @@ describe('jsdoc/name', function() { expect(typeof jsdoc.name.applyNamespace).toBe('function'); }); + it('should export a "stripNamespace" function', function() { + expect(typeof jsdoc.name.stripNamespace).toBe('function'); + }); + // TODO: add tests for other exported constants it('should export a SCOPE enum', function() { expect(jsdoc.name.SCOPE).toBeDefined(); @@ -37,6 +41,10 @@ describe('jsdoc/name', function() { expect(typeof jsdoc.name.combine).toBe('function'); }); + it('should export a "stripVariation" function', function() { + expect(typeof jsdoc.name.stripVariation).toBe('function'); + }); + it('should export a "longnamesToTree" function', function() { expect(jsdoc.name.longnamesToTree).toBeDefined(); expect(typeof jsdoc.name.longnamesToTree).toBe('function'); @@ -233,10 +241,49 @@ describe('jsdoc/name', function() { }); }); + describe('stripNamespace', function() { + it('should not change longnames without a leading namespace', function() { + var startName = 'Foo#bar'; + var endName = jsdoc.name.stripNamespace(startName); + + expect(endName).toBe(startName); + }); + + it('should not change longnames with an embedded namespace', function() { + var startName = 'foo/bar.baz~event:qux'; + var endName = jsdoc.name.stripNamespace(startName); + + expect(endName).toBe(startName); + }); + + it('should remove the leading namespace, if present', function() { + var startName = 'module:foo/bar/baz'; + var endName = jsdoc.name.stripNamespace(startName); + + expect(endName).toBe('foo/bar/baz'); + }); + }); + xdescribe('combine', function() { // TODO: tests }); + describe('stripVariation', function() { + it('should not change longnames without a variation', function() { + var startName = 'Foo#bar'; + var endName = jsdoc.name.stripVariation(startName); + + expect(endName).toBe(startName); + }); + + it('should remove the variation, if present', function() { + var startName = 'Foo#bar(qux)'; + var endName = jsdoc.name.stripVariation(startName); + + expect(endName).toBe('Foo#bar'); + }); + }); + xdescribe('longnamesToTree', function() { // TODO: tests });