Merge branch 'tests-fixes-dictionary' into tests-tag

This commit is contained in:
mathematicalcoffee 2013-02-08 11:13:34 +10:00
commit eeb1c8da47
3 changed files with 123 additions and 8 deletions

View File

@ -33,13 +33,15 @@ TagDefinition.prototype.synonym = function(synonymName) {
dictionary = { dictionary = {
/** @function */ /** @function */
defineTag: function(title, opts) { defineTag: function(title, opts) {
_definitions[title] = new TagDefinition(title, opts); var def = new TagDefinition(title, opts);
// all the other dictionary functions use normalised names; we should too.
_definitions[def.title] = def;
if (opts.isNamespace) { if (opts.isNamespace) {
_namespaces.push(title); _namespaces.push(def.title);
} }
return _definitions[title]; return _definitions[def.title];
}, },
/** @function */ /** @function */
@ -55,9 +57,12 @@ dictionary = {
/** @function */ /** @function */
isNamespace: function(kind) { isNamespace: function(kind) {
if (kind) {
kind = dictionary.normalise(kind);
if ( _namespaces.indexOf(kind) !== -1) { if ( _namespaces.indexOf(kind) !== -1) {
return true; return true;
} }
}
return false; return false;
}, },

View File

@ -1,3 +1,98 @@
describe("jsdoc/tag/dictionary", function() { describe('jsdoc/tag/dictionary', function() {
//TODO var dictionary = require('jsdoc/tag/dictionary');
it('should exist', function() {
expect(dictionary).toBeDefined();
expect(typeof dictionary).toEqual('object');
});
it('should export a defineTag function', function() {
expect(dictionary.defineTag).toBeDefined();
expect(typeof dictionary.defineTag).toEqual('function');
});
it('should export a lookUp function', function() {
expect(dictionary.lookUp).toBeDefined();
expect(typeof dictionary.lookUp).toEqual('function');
});
it('should export a isNamespace function', function() {
expect(dictionary.isNamespace).toBeDefined();
expect(typeof dictionary.isNamespace).toEqual('function');
});
it('should export a normalise function', function() {
expect(dictionary.normalise).toBeDefined();
expect(typeof dictionary.normalise).toEqual('function');
});
// TODO: should really remove this tag from the dictionary after, but how?
var tagOptions = {
canHaveValue: true,
isNamespace: true
},
tagTitle = 'testTag',
tagSynonym = 'testTag2';
var def = dictionary.defineTag(tagTitle, tagOptions).synonym(tagSynonym);
// Should really test TagDefinition but they are private.
// Instead, we'll just tests all the properties we expect of it.
describe("defineTag", function() {
// Since TagDefinition is private, I'll just test for its properties here.
it("returns an object with 'title' property", function() {
expect(typeof def).toEqual('object');
// how to test?
expect(def.title).toBeDefined();
expect(typeof def.title).toEqual('string');
expect(def.title).toEqual(dictionary.normalise(tagTitle));
});
it("returned object has all the tag properties copied over", function() {
for (var prop in tagOptions) {
if (tagOptions.hasOwnProperty(prop)) {
expect(def[prop]).toEqual(tagOptions[prop]);
}
}
});
});
describe("lookUp", function() {
it("retrieves definition when using the tag's canonical name", function() {
expect(dictionary.lookUp(tagTitle)).toEqual(def);
});
it("retrieves definition when using a synonym", function() {
expect(dictionary.lookUp(tagSynonym)).toEqual(def);
});
it("returns FALSE when a tag is not found", function() {
expect(dictionary.lookUp('lkjas1l24jk')).toEqual(false);
});
});
describe("isNamespace", function() {
it("returns whether a tag is a namespace when using its canonical name", function() {
expect(dictionary.isNamespace(tagTitle)).toEqual(true);
});
it("returns whether a tag is a namespace when using its synonym", function() {
expect(dictionary.isNamespace(tagSynonym)).toEqual(true);
});
it("non-existent tags or non-namespace tags should return false", function() {
expect(dictionary.isNamespace('see')).toEqual(false);
expect(dictionary.isNamespace('lkjasd90034')).toEqual(false);
});
});
describe("normalise", function() {
it("should return the tag's title if it is not a synonym", function() {
expect(dictionary.normalise('FooBar')).toEqual('foobar');
expect(dictionary.normalise(tagTitle)).toEqual(def.title);
});
it("should return the canonical name of a tag if the synonym is normalised", function() {
expect(dictionary.normalise(tagSynonym)).toEqual(def.title);
});
});
}); });

View File

@ -0,0 +1,15 @@
describe('jsdoc/tag/dictionary/definitions', function() {
var type = require('jsdoc/tag/dictionary/definitions');
it('should exist', function() {
expect(type).toBeDefined();
expect(typeof type).toEqual('object');
});
it('should export a defineTags function', function() {
expect(type.defineTags).toBeDefined();
expect(typeof type.defineTags).toEqual('function');
});
// whole bit of dictionary.defineTags...but it just calls dictionary.defineTag
// and if I validate that then the rest is automatically validated?
});