From 22fc216425bc3797cd8e21ba1e7db3ea698de3d4 Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Sun, 16 Jan 2011 19:45:59 +0000 Subject: [PATCH] Added tests for @class tag. --- modules/jsdoc/tag/dictionary/definitions.js | 11 ++++++----- test/cases/accesstag.js | 16 ++++++++++++++++ test/cases/classtag.js | 8 ++++++++ test/cases/deprecatedtag.js | 2 +- test/runner.js | 1 + test/t/cases/accesstag.js | 18 ++++++++++++++++++ test/t/cases/classtag.js | 15 +++++++++++++++ test/t/cases/deprecatedtag.js | 2 +- 8 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 test/cases/classtag.js create mode 100644 test/t/cases/classtag.js diff --git a/modules/jsdoc/tag/dictionary/definitions.js b/modules/jsdoc/tag/dictionary/definitions.js index ecc1ee73..a1d7e7bd 100644 --- a/modules/jsdoc/tag/dictionary/definitions.js +++ b/modules/jsdoc/tag/dictionary/definitions.js @@ -11,11 +11,12 @@ dictionary.defineTag('access', { mustHaveValue: true, onTagged: function(doclet, tag) { - if ( /^(private|protected)$/.test(tag.value) ) { - doclet.access = tag.value; + // only valid values are private and protected, public is default + if ( /^(private|protected)$/i.test(tag.value) ) { + doclet.access = tag.value.toLowerCase(); } - else if (tag.value === 'public') { - delete doclet.access; + else { + delete doclet.access; } return true; @@ -313,7 +314,7 @@ dictionary.defineTag('public', { mustNotHaveValue: true, onTagged: function(doclet, tag) { - doclet.access = 'public'; + delete doclet.access; // public is default return true; } diff --git a/test/cases/accesstag.js b/test/cases/accesstag.js index eebe3f5b..497c20dd 100644 --- a/test/cases/accesstag.js +++ b/test/cases/accesstag.js @@ -10,4 +10,20 @@ function Thingy() { /** @access public */ this.pez = 2; +} + +// same as... + +/** @constructor */ +function OtherThingy() { + + /** @private */ + var foo = 0; + + /** @protected */ + this._bar = 1; + + /** @public */ + this.pez = 2; + } \ No newline at end of file diff --git a/test/cases/classtag.js b/test/cases/classtag.js new file mode 100644 index 00000000..25276d89 --- /dev/null +++ b/test/cases/classtag.js @@ -0,0 +1,8 @@ +/** + This function creates a new Foo. + @constructor + @class The class of Foo represent all those foo things. + */ +function Foo() { + +} diff --git a/test/cases/deprecatedtag.js b/test/cases/deprecatedtag.js index 9a593a77..d920101f 100644 --- a/test/cases/deprecatedtag.js +++ b/test/cases/deprecatedtag.js @@ -4,7 +4,7 @@ function foo() { } -/** @deprec v1.0.2 +/** @deprec since version 2.0 */ function bar() { diff --git a/test/runner.js b/test/runner.js index 93fa63da..f970f6b5 100644 --- a/test/runner.js +++ b/test/runner.js @@ -92,6 +92,7 @@ testFile('test/t/cases/alias2.js'); testFile('test/t/cases/augmentstag.js'); testFile('test/t/cases/accesstag.js'); testFile('test/t/cases/authortag.js'); +testFile('test/t/cases/classtag.js'); testFile('test/t/cases/copyrighttag.js'); testFile('test/t/cases/deprecatedtag.js'); testFile('test/t/cases/exceptiontag.js'); diff --git a/test/t/cases/accesstag.js b/test/t/cases/accesstag.js index 02477646..9165cf95 100644 --- a/test/t/cases/accesstag.js +++ b/test/t/cases/accesstag.js @@ -6,6 +6,24 @@ //dump(docSet.doclets); + test('When a symbol has a @access private tag, the doclet has a access="private" property.', function() { + assert.equal(foo.access, 'private'); + }); + + test('When a symbol has a @access protected tag, the doclet has a access="protected" property.', function() { + assert.equal(_bar.access, 'protected'); + }); + + test('When a symbol has a @access public tag, the doclet has no access property.', function() { + assert.equal(typeof pez.access, 'undefined'); + }); + + // same as... + + foo = docSet.getByLongname('OtherThingy~foo')[0]; + _bar = docSet.getByLongname('OtherThingy#_bar')[0]; + pez = docSet.getByLongname('OtherThingy#pez')[0]; + test('When a symbol has a @private tag, the doclet has a access="private" property.', function() { assert.equal(foo.access, 'private'); }); diff --git a/test/t/cases/classtag.js b/test/t/cases/classtag.js new file mode 100644 index 00000000..7b1c33f6 --- /dev/null +++ b/test/t/cases/classtag.js @@ -0,0 +1,15 @@ +(function() { + var docSet = testhelpers.getDocSetFromFile('test/cases/classtag.js'), + foo = docSet.getByLongname('Foo')[0]; + + //dump(docSet.doclets); exit(0); + + test('When a symbol has a @class tag, the doclet has a classdesc property with that value.', function() { + assert.equal(foo.classdesc, 'The class of Foo represent all those foo things.'); + }); + + test('When a symbol has a @class tag, the doclet doclet description is separate from the classdesc.', function() { + assert.equal(foo.description, 'This function creates a new Foo.'); + }); + +})(); \ No newline at end of file diff --git a/test/t/cases/deprecatedtag.js b/test/t/cases/deprecatedtag.js index d09ce8b7..5a93f131 100644 --- a/test/t/cases/deprecatedtag.js +++ b/test/t/cases/deprecatedtag.js @@ -10,7 +10,7 @@ }); test('When a symbol has a @deprec tag with a value, the doclet has a deprecated property set to that value.', function() { - assert.equal(bar.deprecated, 'v1.0.2'); + assert.equal(bar.deprecated, 'since version 2.0'); }); })(); \ No newline at end of file