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