From badf1fcacd388c68c64c58ff5675cecefe33f09a Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Sat, 8 Oct 2011 22:00:38 +0100 Subject: [PATCH] Added unit tests for @enum. --- .../jsdoc/tag/dictionary/definitions.js | 2 +- test/cases/enum.js | 29 ------------------- test/cases/enumtag.js | 12 ++++++++ test/runner.js | 1 + test/t/cases/enumtag.js | 18 ++++++++++++ 5 files changed, 32 insertions(+), 30 deletions(-) delete mode 100644 test/cases/enum.js create mode 100644 test/cases/enumtag.js create mode 100644 test/t/cases/enumtag.js diff --git a/rhino_modules/jsdoc/tag/dictionary/definitions.js b/rhino_modules/jsdoc/tag/dictionary/definitions.js index 52fd2881..30a85eb6 100644 --- a/rhino_modules/jsdoc/tag/dictionary/definitions.js +++ b/rhino_modules/jsdoc/tag/dictionary/definitions.js @@ -166,7 +166,7 @@ exports.defineTags = function(dictionary) { onTagged: function(doclet, tag) { doclet.kind = 'member'; doclet.isEnum = true; - doclet.type = tag.value.type; + if (tag.value && tag.value.type) { doclet.type = tag.value.type; } } }); diff --git a/test/cases/enum.js b/test/cases/enum.js deleted file mode 100644 index 0cc95d0e..00000000 --- a/test/cases/enum.js +++ /dev/null @@ -1,29 +0,0 @@ - -/** @constructor */ -function Data() { - - /** - The current position. - @enum {number} - */ - this.point = { - /** The x coordinate of the point. */ - x: 0, - - /** The y coordinate of the point. */ - y: 0 - }; -} - -/** - * Enum for tri-state values. - * @enum {number} - */ -TriState = { - /** true */ - TRUE: 1, - /** false */ - FALSE: -1, - /** @type {boolean} */ - MAYBE: true -}; \ No newline at end of file diff --git a/test/cases/enumtag.js b/test/cases/enumtag.js new file mode 100644 index 00000000..2fb14167 --- /dev/null +++ b/test/cases/enumtag.js @@ -0,0 +1,12 @@ +/** + * Enum for tri-state values. + * @enum {number} + */ +var TriState = { + /** true */ + TRUE: 1, + /** false */ + FALSE: -1, + /** @type {boolean} */ + MAYBE: true +}; \ No newline at end of file diff --git a/test/runner.js b/test/runner.js index cc256c4f..d3cafb8a 100644 --- a/test/runner.js +++ b/test/runner.js @@ -123,6 +123,7 @@ testFile('test/t/cases/constructortag.js'); testFile('test/t/cases/copyrighttag.js'); testFile('test/t/cases/defaulttag.js'); testFile('test/t/cases/deprecatedtag.js'); +testFile('test/t/cases/enumtag.js'); testFile('test/t/cases/eventfirestag.js'); testFile('test/t/cases/exports.js'); testFile('test/t/cases/exportstag.js'); diff --git a/test/t/cases/enumtag.js b/test/t/cases/enumtag.js new file mode 100644 index 00000000..0fb53e14 --- /dev/null +++ b/test/t/cases/enumtag.js @@ -0,0 +1,18 @@ +(function() { + var docSet = testhelpers.getDocSetFromFile('test/cases/enumtag.js'), + tristate = docSet.getByLongname('TriState')[0]; + + //console.log(docSet); + + test('When a symbol has a @enum tag, it has a properties array.', function() { + assert.equal(typeof tristate.properties, 'object'); + }); + + test('If no @type is given for the property it is inherted from the enum.', function() { + assert.equal(tristate.properties[0].type.names.join(', '), 'number'); + }); + + test('If a @type is given for the property it is reflected in the property value.', function() { + assert.equal(tristate.properties[2].type.names.join(', '), 'boolean'); + }); +})(); \ No newline at end of file