diff --git a/test/runall.js b/test/runall.js index e99e29dd..0df3b474 100644 --- a/test/runall.js +++ b/test/runall.js @@ -23,6 +23,8 @@ load(BASEDIR + '/test/tests/21_tag_const.js'); load(BASEDIR + '/test/tests/22_tag_preserve.js'); load(BASEDIR + '/test/tests/23_tag_fires.js'); load(BASEDIR + '/test/tests/24_tag_exception.js'); +load(BASEDIR + '/test/tests/25_tag_scope.js'); + // see http://visionmedia.github.com/jspec/ JSpec.run({ diff --git a/test/samples/tag_scope.js b/test/samples/tag_scope.js new file mode 100644 index 00000000..d6dda3b8 --- /dev/null +++ b/test/samples/tag_scope.js @@ -0,0 +1,26 @@ +/** A global function + @function +*/ +function outie() { + /** An inner function + @function + */ + function innie(){} +} + +/** A static function + @function +*/ +outie.stat = function() { +} + +/** A global var function + @function +*/ +var varoutie = function() { + /** An inner var function + @function + */ + var varinnie = function() { + } +} diff --git a/test/tests/25_tag_scope.js b/test/tests/25_tag_scope.js new file mode 100644 index 00000000..64fc852f --- /dev/null +++ b/test/tests/25_tag_scope.js @@ -0,0 +1,98 @@ +(function() { + var jsdoc, + doclets; + + JSpec.describe('@scope', function() { + + before(function() { + // docsets can only be created by parsers + jsdoc = { + tag: require('jsdoc/tag'), + parser: require('jsdoc/parser') + }; + jsdoc.parser.parseFiles(BASEDIR + 'test/samples/tag_scope.js'); + + doclets = jsdoc.parser.result.map(function($){ return $.toObject(); }); + }); + + describe('A doclet with global scope', function() { + it('should have a `scope` property of type string equalling "global"', function() { + var doclet = doclets[0]; + expect(doclet).to(have_property, 'scope'); + expect(doclet.scope).to(be_an, String); + expect(doclet.scope).to(be, 'global'); + }); + + it('should have a `path` property of type string equalling its namepath', function() { + var doclet = doclets[0]; + expect(doclet).to(have_property, 'path'); + expect(doclet.path).to(be_an, String); + expect(doclet.path).to(be, 'outie'); + }); + }); + + describe('A doclet with inner scope', function() { + it('should have a `scope` property of type string equalling "inner"', function() { + var doclet = doclets[1]; + expect(doclet).to(have_property, 'scope'); + expect(doclet.scope).to(be_an, String); + expect(doclet.scope).to(be, 'inner'); + }); + + it('should have a `path` property of type string equalling its namepath', function() { + var doclet = doclets[1]; + expect(doclet).to(have_property, 'path'); + expect(doclet.path).to(be_an, String); + expect(doclet.path).to(be, 'outie~innie'); + }); + }); + + describe('A doclet with static scope', function() { + it('should have a `scope` property of type string equalling "static"', function() { + var doclet = doclets[2]; + expect(doclet).to(have_property, 'scope'); + expect(doclet.scope).to(be_an, String); + expect(doclet.scope).to(be, 'static'); + }); + + it('should have a `path` property of type string equalling its namepath', function() { + var doclet = doclets[2]; + expect(doclet).to(have_property, 'path'); + expect(doclet.path).to(be_an, String); + expect(doclet.path).to(be, 'outie.stat'); + }); + }); + + describe('A var doclet with global scope', function() { + it('should have a `scope` property of type string equalling "global"', function() { + var doclet = doclets[3]; + expect(doclet).to(have_property, 'scope'); + expect(doclet.scope).to(be_an, String); + expect(doclet.scope).to(be, 'global'); + }); + + it('should have a `path` property of type string equalling its namepath', function() { + var doclet = doclets[3]; + expect(doclet).to(have_property, 'path'); + expect(doclet.path).to(be_an, String); + expect(doclet.path).to(be, 'varoutie'); + }); + }); + + describe('A var doclet with inner scope', function() { + it('should have a `scope` property of type string equalling "inner"', function() { + var doclet = doclets[4]; + expect(doclet).to(have_property, 'scope'); + expect(doclet.scope).to(be_an, String); + expect(doclet.scope).to(be, 'inner'); + }); + + it('should have a `path` property of type string equalling its namepath', function() { + var doclet = doclets[4]; + expect(doclet).to(have_property, 'path'); + expect(doclet.path).to(be_an, String); + expect(doclet.path).to(be, 'varoutie~varinnie'); + }); + }); + }); +})();