From ed6de4a5d9141576c4643ca70747f1c81d294baf Mon Sep 17 00:00:00 2001 From: mathematicalcoffee Date: Fri, 8 Feb 2013 13:59:21 +1000 Subject: [PATCH] added tests for jsdoc/tag/type/closerCompilerType --- .../jsdoc/tag/type/closureCompilerType.js | 58 ++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/test/specs/jsdoc/tag/type/closureCompilerType.js b/test/specs/jsdoc/tag/type/closureCompilerType.js index 61c556ca..d6ae73c2 100644 --- a/test/specs/jsdoc/tag/type/closureCompilerType.js +++ b/test/specs/jsdoc/tag/type/closureCompilerType.js @@ -1,7 +1,5 @@ /*global describe: true, expect: true, it: true */ describe('jsdoc/tag/type/closureCompilerType', function() { - // TODO: more tests - var type = require('jsdoc/tag/type/closureCompilerType'); it('should exist', function() { @@ -15,11 +13,67 @@ describe('jsdoc/tag/type/closureCompilerType', function() { }); describe('parse', function() { + it('should parse optional types', function() { + var info = type.parse({type: 'Asdf.Foobar='}); + expect(info.type).toEqual('Asdf.Foobar'); + expect(info.optional).toEqual(true); + }); + + it('should parse nullable types', function() { + var info = type.parse({type: '?Asdf.Foobar'}); + expect(info.type).toEqual('Asdf.Foobar'); + expect(info.nullable).toEqual(true); + }); + + it('should parse non-nullable types', function() { + var info = type.parse({type: '!Asdf.Foobar'}); + expect(info.type).toEqual('Asdf.Foobar'); + expect(info.nullable).toEqual(false); + }); + + it('should parse variable types', function() { + var info = type.parse({type: '...Fdsa.Baz'}); + expect(info.type).toEqual('Fdsa.Baz'); + expect(info.variable).toEqual(true); + }); + it('should correctly parse types that are both optional and nullable', function() { var info = type.parse( {type: '?string='} ); expect(info.type).toEqual('string'); expect(info.optional).toEqual(true); expect(info.nullable).toEqual(true); }); + + it('should correctly parse types that are both optional and variable', function() { + var info = type.parse( {type: '...string='} ); + expect(info.type).toEqual('string'); + expect(info.optional).toEqual(true); + expect(info.variable).toEqual(true); + }); + + it("should only change the `type`, `optional`, `nullable` and `variable` properties", function() { + var obj = { + name: "foo", + type: "?...number=", + text: "Sample text.", + optional: null, + nullable: null, + variable: null, + defaultvalue: null + }; + var shouldChange = [ "type", "optional", "nullable", "variable" ]; + + var info = type.parse(obj); + for (var key in info) { + if ( hasOwnProp.call(info, key) ) { + if ( shouldChange.indexOf(key) !== -1 ) { + expect( info[key] ).not.toEqual( obj[key] ); + } + else { + expect( info[key] ).toEqual( obj[key] ); + } + } + } + }); }); });