PageRenderTime 44ms CodeModel.GetById 16ms app.highlight 23ms RepoModel.GetById 2ms app.codeStats 0ms

/branches/jsdoc_tk_gui/setup/test/run.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 307 lines | 273 code | 29 blank | 5 comment | 8 complexity | 8ee5d81e96dce64baf09b52c1afe964a MD5 | raw file
  1//// load required libraries
  2try {
  3	importClass(java.lang.System);
  4}
  5catch (e) {
  6	throw "RuntimeException: The class java.lang.System is required to run this script.";
  7}
  8
  9var __DIR__ = System.getProperty("user.dir")+Packages.java.io.File.separator;
 10
 11function require(lib) {
 12	try {
 13		var file = new Packages.java.io.File(__DIR__+lib);
 14		if(!file.exists()) throw "missing file.";
 15		load(__DIR__+lib);
 16	}
 17	catch (e) {
 18		print("Can't find required file '"+lib+"' in directory '"+__DIR__+"'.\nDo you need to change your working directory to jsdoc-toolkit?");
 19		quit();
 20	}
 21}
 22
 23require("app/JsDoc.js");
 24require("app/Util.js");
 25require("app/JsIO.js");
 26require("app/Symbol.js");
 27require("app/JsToke.js");
 28require("app/JsParse.js");
 29require("app/DocTag.js");
 30require("app/Doclet.js");
 31require("app/DocFile.js");
 32require("app/JsTestrun.js");
 33require("app/Dumper.js");
 34
 35//// set up harness
 36JsDoc.opt = {};
 37jsdoc = null;
 38
 39function testFile(path) {
 40	var srcFiles = JsDoc.opt._ = path;
 41	jsdoc = JsDoc.parse(srcFiles, JsDoc.opt).files;
 42}
 43
 44
 45//// set up some tests cases, order matters
 46
 47var testCases = [
 48	function() {
 49		testFile(__DIR__+"test/data/functions.js");
 50		ok('typeof(jsdoc) != "undefined"', 'jsdoc must be defined.');
 51		is('jsdoc[0].symbols[0].alias', "Layout", 'Nested commented method name can be found.');
 52	},
 53	function() {
 54		JsDoc.opt = {};
 55		testFile(__DIR__+"test/data/class.js");
 56		like('jsdoc[0].symbols[0].desc', /Construct/, 'Untagged description for constructor is found.');
 57	},
 58	function() {
 59		testFile(__DIR__+"test/data/obliterals.js");
 60		is('jsdoc[0].symbols[0].name', "Document", 'Nested commented object literal name can be found.');
 61	},
 62	function() {
 63		testFile(__DIR__+"test/data/oblit_func.js");
 64		is('jsdoc[0].symbols[0].name', "Site", 'Mixed object literal name can be found.');
 65	},
 66	function() {
 67		JsDoc.opt = {a: true};
 68		testFile(__DIR__+"test/data/prototypes.js");
 69		is('jsdoc[0].symbols[1].alias', "Article.getTitle", 'Prototype method name assigned from oblit can be found.');
 70		is('jsdoc[0].symbols[1].memberof', "Article", 'Prototype method memberof assigned from oblit can be found.');
 71		is('jsdoc[0].symbols[0].methods[0].name', "getTitle", 'Prototype method is registered with parent object.');
 72	
 73		is('jsdoc[0].symbols[4].alias', "Paragraph.lines", 'Prototype property name can be found.');
 74		is('jsdoc[0].symbols[4].isa', "OBJECT", 'Prototype property isa can be found.');
 75		is('jsdoc[0].symbols[5].alias', "Paragraph.getLines", 'Prototype method name can be found.');
 76		is('jsdoc[0].symbols[5].isa', "FUNCTION", 'Prototype method isa can be found.');
 77		is('jsdoc[0].symbols[6].alias', "Article.page", 'Prototype set to anonymous function call.');
 78		is('jsdoc[0].symbols[7].alias', "Article.page.turn", 'Prototype set to anonymous function call with scoped method.');
 79	},
 80	function() {
 81		JsDoc.opt = {a: true};
 82		testFile(__DIR__+"test/data/prototypes_props.js");
 83		is('jsdoc[0].symbols[0].properties[0].alias', "Person.name", 'Property set via prototype method is on instance.');
 84		is('jsdoc[0].symbols[0].methods[1].alias', "Person.getName", 'Method set via prototype method is on instance.');
 85	},
 86	function() {
 87		testFile(__DIR__+"test/data/anonfuncs.js");
 88		is('jsdoc[0].symbols[1].alias', "Item.name", 'Anonymous function call assigned to property can be found.');
 89		is('jsdoc[0].symbols[2].name', "Item.Price", 'Anonymous function call assigned to variable can be found.');
 90		is('jsdoc[0].symbols[3].name', "Product", 'Anonymous constructor call assigned to variable can be found.');
 91		is('jsdoc[0].symbols[4].isa', "OBJECT", 'Anonymous constructor property isa must be "PROPERTY".');
 92		is('jsdoc[0].symbols[4].alias', "Product.seller", 'Anonymous constructor property name can be found.');
 93	},
 94	function() {
 95		testFile(__DIR__+"test/data/overview.js");
 96		is('jsdoc[0].overview.doc.tags[1].title', "author", 'Author tag in overview can be found.');
 97	},
 98	function() {
 99		testFile(__DIR__+"test/data/tags.js");
100		is('jsdoc[0].symbols[0].doc.tags[0].title', "status", 'User-defined tag title can be found.');
101		is('jsdoc[0].symbols[0].doc.tags[0].desc', "experimental", 'User-defined tag with desc, desc can be found.');
102		is('jsdoc[0].symbols[0].doc.tags[1].title', "deprecated", 'User-defined tag with no desc, title can be found.');
103		is('jsdoc[0].symbols[0].doc.tags[1].desc', "", 'User-defined tag with no desc, desc can be found and is empty.');
104	},
105	function() {
106		testFile(__DIR__+"test/data/type.js");
107		is('jsdoc[0].symbols[0].type', "", 'Constructors can\'t have a type set.');
108		is('jsdoc[0].symbols[0].doc.tags.length', 0, 'Type doesn\'t appear in tags.');
109		is('jsdoc[0].symbols[1].type', "String", 'Properties can have a type set.');
110		is('jsdoc[0].symbols[2].type', "number", 'Variables can have a type set.');
111		is('jsdoc[0].symbols[3].type', "HTMLElement, HTMLElement[], null", 'Types can be separated with single bars and newlines.');
112		is('jsdoc[0].symbols[4].type', "FontDef, String", 'Types can be separated with double bars.');
113		is('jsdoc[0].symbols[5].type', "number, sizeDef", 'Type tag can be set by setting the type as well as desc.');
114	},
115	function() {
116		JsDoc.opt = {a:true};
117		testFile(__DIR__+"test/data/functions.js");
118		is('jsdoc[0].symbols[0].methods.length', 3, 'Undocumented function has undocumented methods.');
119		is('jsdoc[0].symbols[0].methods[2].name', "Canvas", 'Undocumented function has named undocumented methods.');
120		is('jsdoc[0].symbols[2].alias', "Layout.Element", 'Nested undocumented function has name.');
121		is('jsdoc[0].symbols[2].methods[0].name', "expand", 'Nested undocumented method is found.');
122		is('jsdoc[0].symbols[3].name', "expand", 'Nested undocumented function has name.');
123		is('jsdoc[0].symbols[3].alias', "Layout.Element.expand", 'Nested undocumented function has alias.');
124	},
125	function() {
126		testFile(__DIR__+"test/data/virtual.js");
127		is('jsdoc[0].symbols[0].name', "twiddle.flick", 'Virtual doclet name can be found.');
128		is('jsdoc[0].symbols[0].isa', "FUNCTION", 'Virtual doclet isa can be found.');
129		is('jsdoc[0].symbols[0].desc', "Twiddle the given flick.", 'Virtual doclet desc can be found.');
130		is('jsdoc[0].symbols[0].doc.tags.length', 0, 'Virtual doclet should have no tags.');
131		
132		is('jsdoc[0].symbols[1].name', "zipZap", 'Undocumented function following virtual doclet name can be found.');
133		
134		is('jsdoc[0].symbols[2].name', "Concat", 'Virtual function doclet name can be found.');
135		is('jsdoc[0].symbols[2].isa', "CONSTRUCTOR", 'Virtual function doclet isa can be found.');
136		is('jsdoc[0].symbols[2].doc.tags.length', 0, 'Virtual function doclet should have no tags.');
137		is('jsdoc[0].symbols[2].params[0].name', "strX", 'Virtual function parameter name can be found.');
138		
139		is('jsdoc[0].symbols[3].memberof', "Concat", 'Virtual function can define memberOf.');
140		is('jsdoc[0].symbols[3].alias', "Concat.join", 'Virtual function alias reflects memberOf tag.');
141		is('jsdoc[0].symbols[2].methods[0].name', "join", 'Virtual function appears as method in parent object.');
142		
143		is('jsdoc[0].symbols[4].memberof', "Concat", 'Virtual property can define memberOf.');
144		is('jsdoc[0].symbols[4].alias', "Concat.separator", 'Virtual property alias reflects memberOf tag.');
145		is('jsdoc[0].symbols[2].properties[0].name', "separator", 'Virtual property appears as property in parent object.');
146		is('jsdoc[0].symbols[4].type', "String", 'Virtual property can specify its type.');
147		
148		is('jsdoc[0].symbols[6].alias', "Employee.employeeId", 'Virtual property inside a function can be seen.');
149		is('jsdoc[0].symbols[5].properties[0].name', "employeeId", 'Virtual property inside a function appears as property.');
150	
151		is('jsdoc[0].symbols[7].alias', "Document.title", 'Virtual object inside an object literal can be seen.');
152	},
153	function() {
154		testFile(__DIR__+"test/data/properties.js");
155		is('jsdoc[0].symbols[1].properties[0].name', "methodId", 'Property in doc comment is added to parent.');
156		is('jsdoc[0].symbols[1].properties[0].type', "Number", 'Property in doc comment has type.');
157		
158		is('jsdoc[0].symbols[1].properties[0].desc', "The id of the method.", 'Property in doc comment has description.');
159		is('jsdoc[0].symbols[1].properties[3].desc', "Only used in older browsers.", 'Property in code body has description.');
160
161		is('jsdoc[0].symbols[1].properties[1].name', "_associated_with", 'Property in code body is added to parent.');
162		is('jsdoc[0].symbols[1].properties.length', 5, 'All properties in code body are added to parent.');
163		is('jsdoc[0].symbols[1].methods[0].name', "associated_with", 'Method in code body is added to parent.');
164		is('jsdoc[0].symbols[2].alias', "Codework.Method._associated_with", 'Property appears as own symbol.');
165		is('jsdoc[0].symbols[2].isa', "OBJECT", 'Property symbol is a object.');
166		is('jsdoc[0].symbols[2].type', "Object", 'Property symbol has type.');
167		is('jsdoc[0].symbols[6].alias', "Codework.Method.associated_with", 'Method appears as own symbol.');
168		is('jsdoc[0].symbols[6].isa', "FUNCTION", 'Method symbol is a function.');
169	},
170	function() {
171		JsDoc.opt = {a:true};
172		testFile(__DIR__+"test/data/memberof.js");
173		is('jsdoc[0].symbols[1].name', "SquareMaker", 'Constructor member name can be found.');
174		is('jsdoc[0].symbols[1].memberof', "ShapeFactory", 'Constructor which is a member of another constructor identified.');
175		is('jsdoc[0].symbols[2].name', "Square", 'Nested constructor member name can be found.');
176		is('jsdoc[0].symbols[2].memberof', "ShapeFactory.SquareMaker", 'Nested constructor which is a member of another constructor identified.');
177		is('jsdoc[0].symbols[5].isa', "CONSTRUCTOR", 'Class tag is a synonym for constructor.');
178		is('jsdoc[0].symbols[5].properties[1].alias', "Circle.getDiameter", 'Member tag is a synonym for memberof.');
179	},
180	function() {
181		JsDoc.opt = {};
182		testFile(__DIR__+"test/data/underscore.js");
183		is('jsdoc[0].symbols.length', 0, 'No undocumented symbols allowed without -a or -A.');
184		
185		JsDoc.opt = {a:true};
186		testFile(__DIR__+"test/data/underscore.js");
187		is('jsdoc[0].symbols.length', 3, 'No undocumented, underscored symbols allowed with -a but not -A.');
188	
189		JsDoc.opt = {A:true};
190		testFile(__DIR__+"test/data/underscore.js");
191		is('jsdoc[0].symbols.length', 5, 'All undocumented symbols allowed with -A.');
192		is('jsdoc[0].symbols[0].methods[1].name', "_debug", 'Undocumented, underscored methods allowed with -A.');
193	},
194	function() {
195		JsDoc.opt = {};
196		testFile(__DIR__+"test/data/allfuncs_option.js");
197		is('jsdoc[0].symbols.length', 1, 'Documented method of undocumented parent found without -a or -A.');
198		is('jsdoc[0].symbols[0].alias', "_Action.passTo", 'Documented method of undocumented parent alias includes parent.');
199
200		JsDoc.opt = {A:true};
201		testFile(__DIR__+"test/data/allfuncs_option.js");
202		is('jsdoc[0].symbols.length', 5, 'All functions found with -A.');
203	},
204	function() {
205		JsDoc.opt = {};
206		testFile(__DIR__+"test/data/ignore.js");
207		is('jsdoc[0].symbols.length', 0, 'Ignored and private functions are unseen without -p, -a or -A.');
208		
209		JsDoc.opt = {A:true};
210		testFile(__DIR__+"test/data/ignore.js");
211		is('jsdoc[0].symbols.length', 3, 'Ignored functions are unseen with -A.');
212		is('jsdoc[0].symbols[0].alias', "Log.warn", 'Ignored parent has visible method with -A.');
213		is('jsdoc[0].symbols[2].alias', "Action.passTo", 'Ignored method is unseen with -A.');
214	
215		JsDoc.opt = {A:true, p:true};
216		testFile(__DIR__+"test/data/ignore.js");
217		is('jsdoc[0].symbols.length', 4, 'Private functions are seen with -p.');
218	},
219	function() {
220		JsDoc.opt = {};
221		testFile(__DIR__+"test/data/returns.js");
222		is('jsdoc[0].symbols[0].returns.length', 1, 'A return tag appears in the returns array.');
223		is('jsdoc[0].symbols[0].doc.tags.length', 0, 'A return tag does not appear in the tags array.');
224		is('jsdoc[0].symbols[0].returns[0].type', "Array, String", 'A return type can contain multiple values and whitespaces.');
225		is('jsdoc[0].symbols[1].returns.length', 2, 'Multiple return tags are all found.');
226		is('jsdoc[0].symbols[2].returns[0].desc', "Characters from the file.", 'Returns is a synonym for return.');
227	},
228	function() {
229		JsDoc.opt = {a: true};
230		testFile(__DIR__+"test/data/params.js");
231		is('jsdoc[0].symbols[0].params.length', 1, 'A param tag appears in the params array.');
232		is('jsdoc[0].symbols[0].params[0].type', "String, Array", 'A param type van contain multiple values and whitespaces.');
233		is('jsdoc[0].symbols[1].params.length', 3, 'Undocumented param tags appear in the params array.');
234		is('jsdoc[0].symbols[1].signature()', "source, format, target", 'Can get params as a signature.');
235	},
236	function() {
237		JsDoc.opt = {a: true};
238		testFile(__DIR__+"test/data/scope.js");
239		is('jsdoc[0].symbols[0].alias', "Record.getRecord", 'Scope recognized as part of alias with new function(){} syntax.');
240		is('jsdoc[0].symbols[0].name', "Record.getRecord", 'Scope recognized as part of name with new function(){} syntax.');
241		is('jsdoc[0].symbols[1].alias', "Record.getRecord.Reader", 'Scope recognized as part of method with new function(){} syntax');
242		is('jsdoc[0].symbols[2].alias', "File.getId", 'Scope recognized as part of name with function(){}() syntax.');
243		is('jsdoc[0].symbols[3].alias', "Entry.getSubject", 'Scope recognized as part of method name with function(){}() syntax.');
244		is('jsdoc[0].symbols[4].alias', "dojo.widget.Widget.initializer", 'Scope within argument list is recognized.');
245		is('jsdoc[0].symbols[6].alias', "dojo.widget.Widget.doIt", 'Scope set to prototype is recognized.');
246		is('jsdoc[0].symbols[6].memberof', "dojo.widget.Widget", 'Scope set to prototype is a method, not static function.');
247	
248	},
249	function() {
250		JsDoc.opt = {a: true};
251		testFile(__DIR__+"test/data/framework.js");
252		is('jsdoc[0].symbols[1].alias', "Dragger.scroll", 'Scope recognized as part of method inside param call.');
253		is('jsdoc[0].symbols[2].alias', "Dragger.onChange", 'Function inside param call recognized when labelled function.');
254		is('jsdoc[0].symbols[3].alias', "Dragger.onUpdate", 'Method inside param call recognized when virtual.');
255		is('jsdoc[0].symbols[3].memberof', "Dragger", 'Method inside param call has memberof when virtual.');
256	},
257	function() {
258		JsDoc.opt = {a: true};
259		testFile(__DIR__+"test/data/throws.js");
260		is('jsdoc[0].symbols[0].exceptions[0]', "This is the label text.", 'Throws can be found.');
261		is('jsdoc[0].symbols[1].exceptions[0].type', "OutOfMemory", 'Exception is a synonym for throws.');
262		is('jsdoc[0].symbols[2].exceptions[0].type', "IOException", 'Multiple exception tags allowed, first.');
263		is('jsdoc[0].symbols[2].exceptions[1].type', "PermissionDenied", 'Multiple exception tags allowed, second.');
264	},
265	function() {
266		JsDoc.opt = {a: true};
267		testFile([__DIR__+"test/data/augments.js", __DIR__+"test/data/augments2.js"]);
268		is('jsdoc[0].symbols[4].augments[0]', "Layout", 'An augmented class can be found.');
269		is('jsdoc[0].symbols[6].augments[0]', "Page", 'The extends tag is a synonym for augments.');
270		is('jsdoc[1].symbols[4].augments[0]', "ThreeColumnPage", 'Can augment across file boundaries.');
271		is('jsdoc[1].symbols[4].augments.length', 2, 'Multiple augments are supported.');
272		is('jsdoc[1].symbols[4].inherits[0]', "Junkmail.annoy", 'Inherited method with augments.');
273		is('jsdoc[1].symbols[4].getInheritedMethods().length', 5, 'getInheritedMethods() returns all.');
274	},
275	function() {
276		JsDoc.opt = {A: true};
277		testFile(__DIR__+"test/data/nested_funcs.js");
278		is('jsdoc[0].symbols[0].alias', "Foo", 'An enclosing function is seen.');
279		is('jsdoc[0].symbols[1].alias', "Foo.methodOne", 'A nested function attached to the enclosing prototype is seen.');
280		is('jsdoc[0].symbols[2].alias', "Foo.methodTwo", 'A second nested method is seen.');
281		is('jsdoc[0].symbols.length', 3, 'Nested functions unattached to the enclosing prototype is not seen.');
282	},
283	function() {
284		JsDoc.opt = {};
285		testFile(__DIR__+"test/data/events.js");
286		//print(Dumper.dump(jsdoc));
287		is('jsdoc[0].symbols[0].events.length', 1, 'An event appears in th eevents array.');
288		is('jsdoc[0].symbols[0].events[0].isa', 'EVENT', 'The event isa EVENT.');
289		is('jsdoc[0].symbols[0].events[0].alias', 'Header.changeHeaderEvent', 'The name of the event can be is seen.');
290
291	},
292	function() {
293		JsDoc.opt = {A: true};
294		testFile(__DIR__+"test/data/function_property.js");
295		is('jsdoc[0].symbols[0].isa', 'OBJECT', 'Inline functions that are evaluated are objects.');
296		is('jsdoc[0].symbols[1].isa', 'FUNCTION', 'Inline functions that are not evaluated are functions.');
297		is('jsdoc[0].symbols[1].alias', 'WH.FLAG.w3c.getLevel', 'Nested functions inside inline functions that are evaluated are objects are found.');
298		is('jsdoc[0].symbols[2].isa', 'FUNCTION', 'Inline functions that are not evaluated are functions.');
299
300	}
301	
302];
303
304
305//// run and print results
306
307print(testrun(testCases));