The type property of long tags is now only an array when there are multiples.

This commit is contained in:
Michael Mathews 2010-12-17 16:09:20 +00:00
parent 610c254aa5
commit f9d07621d8
4 changed files with 36 additions and 17 deletions

View File

@ -178,7 +178,8 @@
tagValue.name = tag.pname; // the parameter name
}
if (tag.type && tag.type.length && tag.type[0] !== '') {
tagValue.type = tag.type;
if (tag.type.length === 1) { tagValue.type = tag.type[0]; }
else { tagValue.type = tag.type; }
}
if (tag.pdesc) { tagValue.description = tag.pdesc; }
if (typeof tag.poptional === 'boolean') { tagValue.optional = tag.poptional; }

View File

@ -23,10 +23,10 @@
});
describe('The returns value of that doclet', function() {
it('should have an `type` property set to the given type', function() {
it('should have a single `type` documented as the given type', function() {
var returns = doclets[0].returns;
expect(returns).to(have_property, 'type');
expect(returns.type).to(eql, ['number']);
expect(returns.type).to(eql, 'number');
});
it('should have an `description` property set to the given description', function() {
@ -51,6 +51,22 @@
});
});
describe('The returns value of a doclet with multiple @returns', function() {
it('should only have the first return documented.', function() {
var returns = doclets[2].returns;
expect(returns).to(have_property, 'description');
expect(returns.description).to(eql, 'And so forth.');
});
});
describe('The return with multiple types', function() {
it('should document those types as an array.', function() {
var returns = doclets[2].returns;
expect(returns).to(have_property, 'type');
expect(returns.type).to(eql, ['number', 'string']);
});
});
});
})();
@ -65,5 +81,11 @@
@function bar
@return So a horse walks into a....
*/
/**
@function baz
@returns {number|string} And so forth.
@returns And so on.
*/
})();

View File

@ -48,19 +48,17 @@
expect(doclet).to(have_property, 'param');
expect(doclet.param).to(have_length, 2);
expect(doclet.param[0]).to(have_property, 'type');
expect(doclet.param[0].type).to(eql, ['string']);
expect(doclet.param[0].type).to(eql, 'string');
expect(doclet.param[1]).to(have_property, 'type');
expect(doclet.param[1].type).to(eql, ['string']);
expect(doclet.param[1].type).to(eql, 'string');
});
});
describe('A doclet with one param tag', function() {
it('should have a `param` property that is an array of one object', function() {
it('should have a `param` property that is an array', function() {
var doclet = doclets[2];
expect(doclet).to(have_property, 'param');
expect(doclet.param).to(be_an, Array);
expect(doclet.param.length).to(be, 1);
expect(doclet.param[0]).to(be_an, Object);
});
});
@ -68,8 +66,8 @@
it('should have a `param` array with a single member with a `type` and `name`', function() {
var doclet = doclets[2];
expect(doclet).to(have_property, 'param');
expect(doclet.param[0].type).to(be_an, Array); // types are always arrays
expect(doclet.param[0].type).to(eql, ['string']);
expect(doclet.param[0].type.push).to(be_undefined); // types are only arrays when there are many
expect(doclet.param[0].type).to(eql, 'string');
expect(doclet.param[0].name).to(be_an, String);
expect(doclet.param[0].name).to(eql, 'str');
});
@ -84,8 +82,7 @@
it('should have a `param` array with a single member with a `type`, `name` and `description`', function() {
var doclet = doclets[3];
expect(doclet).to(have_property, 'param');
expect(doclet.param[0].type).to(be_an, Array); // types are always arrays
expect(doclet.param[0].type).to(eql, ['string']);
expect(doclet.param[0].type).to(eql, 'string');
expect(doclet.param[0].name).to(be_an, String);
expect(doclet.param[0].name).to(eql, 'message');
expect(doclet.param[0].description).to(be_an, String);
@ -96,8 +93,7 @@
describe('A param tag using the dash syntax with a `type`, `name` and `description`', function() {
it('should have a `type`, `name` and `description`', function() {
var param = doclets[4].param[0];
expect(param.type).to(be_an, Array); // types are always arrays
expect(param.type).to(eql, ['Panel']);
expect(param.type).to(eql, 'Panel');
expect(param.name).to(be_an, String);
expect(param.name).to(eql, 'p');
expect(param.description).to(be_an, String);
@ -118,8 +114,8 @@
describe('A param tag using the dash syntax with a `type` and a `description`', function() {
it('should have a `description` and `type` but no `name`', function() {
var param = doclets[4].param[2];
expect(param.type).to(be_an, Array); // types are always arrays
expect(param.type).to(eql, ['boolean']);
expect(param.type).to(be_an, String);
expect(param.type).to(eql, 'boolean');
expect(param.description).to(be_an, String);
expect(param.description).to(eql, 'Don\'t replace existing content.');
expect(param.name).to(be_undefined);

View File

@ -25,7 +25,7 @@
describe('The type of the `exception` property', function() {
it('should be equal to the type of the given tag value', function() {
var doclet = doclets[0];
expect(doclet.exception.type).to(eql, ['divideByZeroError']);
expect(doclet.exception.type).to(eql, 'divideByZeroError');
});
});