handle enums with numeric keys (#946)

This commit is contained in:
Jeff Williams 2015-03-09 17:28:12 -07:00
parent 09d0c1a0ed
commit be77aa4344
4 changed files with 26 additions and 11 deletions

View File

@ -260,7 +260,7 @@ function newSymbolDoclet(parser, docletSrc, e) {
processAlias(parser, newDoclet, e.astnode);
}
// otherwise, get the symbol name from the code
else if (e.code && e.code.name) {
else if (e.code && typeof e.code.name !== 'undefined' && e.code.name !== '') {
newDoclet.addTag('name', e.code.name);
if (!newDoclet.memberof) {
addSymbolMemberof(parser, newDoclet, e.astnode);

View File

@ -38,7 +38,7 @@ function trim(text, opts, meta) {
var match;
opts = opts || {};
text = String(text || '');
text = String(typeof text !== 'undefined' ? text : '');
if ( mustPreserveWhitespace(text, meta) ) {
text = util.format('"%s"', text);

View File

@ -8,4 +8,14 @@ var TriState = {
FALSE: -1,
/** @type {boolean} */
MAYBE: true
};
};
/**
* Numeric enum for true/false values.
* @enum {boolean}
*/
var TrueFalseNumeric = {
/** false */
0: false,
1: true
};

View File

@ -31,15 +31,20 @@ describe('@enum tag', function() {
expect( dump(tristate) ).not.toMatch('<CircularRef>');
});
describe('chained assignments', function() {
var pentaState;
var PENTASTATE;
var quadState;
describe('numeric object properties', function() {
it('When an enum is defined with numeric object properties, the enum is parsed correctly.', function() {
var zero = docSet.getByLongname('TrueFalseNumeric.0')[0];
docSet = jasmine.getDocSetFromFile('test/fixtures/enumtag2.js');
pentaState = docSet.getByLongname('module:my/enums.PentaState')[0];
PENTASTATE = docSet.getByLongname('module:my/enums.PENTASTATE')[0];
quadState = docSet.getByLongname('module:my/enums.QuadState')[0];
expect(zero).toBeDefined();
expect(zero.description).toBe('false');
});
});
describe('chained assignments', function() {
var docSet2 = jasmine.getDocSetFromFile('test/fixtures/enumtag2.js');
var pentaState = docSet2.getByLongname('module:my/enums.PentaState')[0];
var PENTASTATE = docSet2.getByLongname('module:my/enums.PENTASTATE')[0];
var quadState = docSet2.getByLongname('module:my/enums.QuadState')[0];
it('When a symbol at the start of an assignment chain has an @enum tag, that symbol has a properties array.', function() {
expect( Array.isArray(quadState.properties) ).toBe(true);