Source Code Cross Referenced for JS2Doc_Test.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » js2doc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » Laszlo 4.0.10 » org.openlaszlo.js2doc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ****************************************************************************
002:         * JS2Doc_Test.java
003:         *
004:         * ****************************************************************************/
005:
006:        /* J_LZ_COPYRIGHT_BEGIN *******************************************************
007:         * Copyright 2007 Laszlo Systems, Inc.  All Rights Reserved.                   *
008:         * Use is subject to license terms.                                            *
009:         * J_LZ_COPYRIGHT_END *********************************************************/
010:
011:        package org.openlaszlo.js2doc;
012:
013:        import org.openlaszlo.utils.*;
014:        import java.io.*;
015:        import java.util.*;
016:        import junit.framework.*;
017:        import org.w3c.dom.*;
018:        import javax.xml.transform.*;
019:        import javax.xml.transform.dom.*;
020:        import javax.xml.transform.stream.*;
021:        import org.custommonkey.xmlunit.*;
022:
023:        public class JS2Doc_Test extends XMLTestCase {
024:
025:            public JS2Doc_Test(String name) {
026:                super (name);
027:            }
028:
029:            public void setUp() {
030:            }
031:
032:            public void testComments() {
033:                String[] tests = {
034:                        // Each case is input, expected output
035:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
036:
037:                        "",
038:                        "<js2doc/>",
039:
040:                        // properly-formatted but empty comment
041:                        "/** */ var foo;",
042:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
043:
044:                        // comment applying to variable statement (var foo)
045:                        "/** this is a js2doc comment */ var foo;",
046:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a js2doc comment</text></doc></property></js2doc>",
047:
048:                        // invalid comment applying to variable statement (var foo)
049:                        "/* this is a non-js2doc comment */ var foo;",
050:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
051:
052:                        // another invalid comment syntax
053:                        "// this is a comment\n var foo;",
054:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
055:
056:                        // multi-line comments
057:                        "/** this is the subject\n *\n * and here's some more text\n */\n var foo;",
058:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is the subject\n\n and here's some more text</text></doc></property></js2doc>",
059:
060:                        "/** this is the subject\n *** \n ** and here's some more text\n */\n var foo;",
061:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is the subject\n \n and here's some more text</text></doc></property></js2doc>",
062:
063:                        // formatted comments
064:                        "/** this is the subject\n * @field1 foo\n */\n var foo;",
065:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is the subject</text><tag name=\"field1\"><text>foo</text></tag></doc></property></js2doc>",
066:
067:                        "/** this is the subject\n * @field1 foo\n * @field2 bar\n */\n var foo;",
068:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is the subject</text><tag name=\"field1\"><text>foo</text></tag><tag name=\"field2\"><text>bar</text></tag></doc></property></js2doc>",
069:
070:                        "/** this is the subject\n * here's more\n * @field1 foo\n * bar\n */\n var foo;",
071:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is the subject\n here's more</text><tag name=\"field1\"><text>foo\n bar</text></tag></doc></property></js2doc>",
072:
073:                        "/** this is the subject\n *  here's more\n * @field1 foo\n *  bar\n */\n var foo;",
074:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is the subject\n  here's more</text><tag name=\"field1\"><text>foo\n  bar</text></tag></doc></property></js2doc>",
075:
076:                        "/** this is <b>the</b> subject\n *  here's more\n * @field1 foo\n *  bar\n */\n var foo;",
077:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is <b>the</b> subject\n  here's more</text><tag name=\"field1\"><text>foo\n  bar</text></tag></doc></property></js2doc>",
078:
079:                        // consecutive comments
080:                        "// garbage\n/** legit */\nvar foo;",
081:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>legit</text></doc></property></js2doc>",
082:
083:                        "/* nope */\n/* nope */\n/** yep */\nvar foo;",
084:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>yep</text></doc></property></js2doc>",
085:
086:                        // don't pick up js2doc-formatted comment in the middle of a sequence of regular comments
087:                        "/* nope */\n/** you wish */\n/* nope */\nvar foo;",
088:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
089:
090:                        "/**\n  * foo\n  * @access private */\nvar foo;",
091:                        "<js2doc><property id=\"foo\" name=\"foo\" access=\"private\"><doc><text>foo</text></doc></property></js2doc>",
092:
093:                        "/** jaz &lt; bar */\nvar foo;",
094:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>jaz &lt; bar</text></doc></property></js2doc>", };
095:
096:                iterateTests(tests);
097:            }
098:
099:            public void testVariableDeclarations() {
100:                String[] tests = {
101:                        // simple variable declaration without comment
102:                        "var foo;",
103:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
104:
105:                        // simple multiple variable declaration without comment
106:                        "var foo, bar;",
107:                        "<js2doc><property id=\"foo\" name=\"foo\"/><property id=\"bar\" name=\"bar\"/></js2doc>",
108:
109:                        // simple multiple variable declaration without comment
110:                        "var foo; var bar;",
111:                        "<js2doc><property id=\"foo\" name=\"foo\"/><property id=\"bar\" name=\"bar\"/></js2doc>",
112:
113:                        // comment applying to one decl is var statement
114:                        "/** this is a comment */ var foo;",
115:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a comment</text></doc></property></js2doc>",
116:
117:                        // access keyword applying to one decl is var statement
118:                        "/** @keywords private */ var foo;",
119:                        "<js2doc><property id=\"foo\" name=\"foo\" access=\"private\"/></js2doc>",
120:
121:                        // access keyword applying to one decl is var statement
122:                        "/** @access private */ var foo;",
123:                        "<js2doc><property id=\"foo\" name=\"foo\" access=\"private\"/></js2doc>",
124:
125:                        "/** @type Boolean */ var foo;",
126:                        "<js2doc><property id=\"foo\" name=\"foo\" type=\"Boolean\"/></js2doc>",
127:
128:                        // comment applying to all decls in a multiple-decl var statement
129:                        "/** this is a comment */ var foo, bar;",
130:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a comment</text></doc></property><property id=\"bar\" name=\"bar\"><doc><text>this is a comment</text></doc></property></js2doc>",
131:
132:                        // comment applying to variable declaration ("foo")
133:                        "var /** this is a comment */ foo;",
134:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a comment</text></doc></property></js2doc>",
135:
136:                        // separate comments applying to each variable decl in a statement
137:                        "var /** comment A */ foo, /** comment B */ bar;",
138:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>comment A</text></doc></property><property id=\"bar\" name=\"bar\"><doc><text>comment B</text></doc></property></js2doc>",
139:
140:                        "var foo = new Object;",
141:                        "<js2doc><property id=\"foo\" name=\"foo\"><object/></property></js2doc>",
142:
143:                        // no real purpose with support for new Function(arg1, ..., argn, body)
144:                        "var foo = new Function;",
145:                        "<js2doc><property id=\"foo\" name=\"foo\"><function/></property></js2doc>",
146:
147:                        "var foo = new LzEvent;",
148:                        "<js2doc><property id=\"foo\" name=\"foo\"><object type=\"LzEvent\"/></property></js2doc>", };
149:
150:                iterateTests(tests);
151:            }
152:
153:            public void testTopLevelAssignments() {
154:
155:                String[] tests = {
156:                        // Each case is input, expected-output
157:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
158:
159:                        "var foo = new Object; foo.bar = 10;",
160:                        "<js2doc><property id=\"foo\" name=\"foo\"><object><property id=\"foo.bar\" name=\"bar\" value=\"10\"/></object></property></js2doc>",
161:
162:                        "var foo = new Object(); foo.bar = 10;",
163:                        "<js2doc><property id=\"foo\" name=\"foo\"><object><property id=\"foo.bar\" name=\"bar\" value=\"10\"/></object></property></js2doc>",
164:
165:                        "var foo = new String; foo.bar = 10;",
166:                        "<js2doc><property id=\"foo\" name=\"foo\"><object type=\"String\"><property id=\"foo.bar\" name=\"bar\" value=\"10\"/></object></property></js2doc>",
167:
168:                        "var foo = new String(); foo.bar = 10;",
169:                        "<js2doc><property id=\"foo\" name=\"foo\"><object type=\"String\"><property id=\"foo.bar\" name=\"bar\" value=\"10\"/></object></property></js2doc>",
170:
171:                        "var foo = new Object; foo.bar = 'baz';",
172:                        "<js2doc><property id=\"foo\" name=\"foo\"><object><property id=\"foo.bar\" name=\"bar\" value=\"baz\"/></object></property></js2doc>",
173:
174:                        "var foo = new Object; foo.bar = function () {};",
175:                        "<js2doc><property id=\"foo\" name=\"foo\"><object><property id=\"foo.bar\" name=\"bar\"><function/></property></object></property></js2doc>",
176:
177:                        "var foo = new Object; foo.prototype.bar = 10;",
178:                        "<js2doc><property id=\"foo\" name=\"foo\"><object><property id=\"foo.prototype\" name=\"prototype\"><object><property id=\"foo.prototype.bar\" name=\"bar\" value=\"10\"/></object></property></object></property></js2doc>",
179:
180:                        "var foo = function () {};",
181:                        "<js2doc><property id=\"foo\" name=\"foo\"><function/></property></js2doc>",
182:
183:                        "var foo = function (a) {};",
184:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"a\"/></function></property></js2doc>",
185:
186:                        "/** @param String a */ var foo = function (a) {};",
187:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"a\" type=\"String\"/></function></property></js2doc>",
188:
189:                        "var foo = function (a) {}; foo.bar = 10;",
190:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"a\"/><property id=\"foo.bar\" name=\"bar\" value=\"10\"/></function></property></js2doc>",
191:
192:                        "var foo = function (a) {}; foo.prototype.bar = 10;",
193:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"a\"/><property id=\"foo.prototype\" name=\"prototype\"><object><property id=\"foo.prototype.bar\" name=\"bar\" value=\"10\"/></object></property></function></property></js2doc>",
194:
195:                        "a = 10",
196:                        "<js2doc><property id=\"a\" name=\"a\" value=\"10\"/></js2doc>",
197:
198:                        "a = { foo: 10 }",
199:                        "<js2doc><property id=\"a\" name=\"a\"><object><property name=\"foo\" id=\"a.foo\" value=\"10\"/></object></property></js2doc>",
200:
201:                        "a = { /** @access private */ foo: 10 }",
202:                        "<js2doc><property id=\"a\" name=\"a\"><object><property name=\"foo\" id=\"a.foo\" value=\"10\" access=\"private\"/></object></property></js2doc>",
203:
204:                        "var Debug; /** @access private  */ Debug.addText = function (msg1) { }; /** Foo */ Debug.addText = function (msg2) { };",
205:                        "<js2doc><property id=\"Debug\" name=\"Debug\"><object><property id=\"Debug.addText\" name=\"addText\"><doc><text>Foo</text></doc><function><parameter name=\"msg2\"/></function></property></object></property></js2doc>",
206:
207:                        "Object.make = function () {}",
208:                        "<js2doc><property id=\"Object\" name=\"Object\" topic=\"JavaScript\" subtopic=\"Intrinsic Classes\"><object><property id=\"Object.make\" name=\"make\"><function/></property></object></property></js2doc>", };
209:
210:                iterateTests(tests);
211:            }
212:
213:            public void testFunctionDefinitions() {
214:
215:                String[] tests = {
216:                        // Each case is input, expected-output
217:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
218:
219:                        // simple function definition
220:                        "function foo () { }",
221:                        "<js2doc><property id=\"foo\" name=\"foo\"><function/></property></js2doc>",
222:
223:                        // simple function definition with comment
224:                        "/** this is a comment */ function foo () { }",
225:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a comment</text></doc><function/></property></js2doc>",
226:
227:                        // alternative comment syntax
228:                        "// this is a comment\n function foo () { }",
229:                        "<js2doc><property id=\"foo\" name=\"foo\"><function/></property></js2doc>",
230:
231:                        // simple function definition with access keyword
232:                        "/** @keywords private */ function foo () { }",
233:                        "<js2doc><property id=\"foo\" name=\"foo\" access=\"private\"><function/></property></js2doc>",
234:
235:                        // simple function definition with access keyword
236:                        "/** @access private */ function foo () { }",
237:                        "<js2doc><property id=\"foo\" name=\"foo\" access=\"private\"><function/></property></js2doc>",
238:
239:                        // function definition with one parameter
240:                        "function foo (bar) {}",
241:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/></function></property></js2doc>",
242:
243:                        // function definition with three parameters
244:                        "function foo (bar, bazzle, batchelder) {}",
245:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/><parameter name=\"bazzle\"/><parameter name=\"batchelder\"/></function></property></js2doc>",
246:
247:                        // function definition with commented params
248:                        "/** @param String bar: test */ function foo(bar) {}",
249:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\" type=\"String\"><doc><text>test</text></doc></parameter></function></property></js2doc>",
250:
251:                        // function definition with commented params
252:                        "/** blest\n @param String bar: test */ function foo(bar) {}",
253:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>blest</text></doc><function><parameter name=\"bar\" type=\"String\"><doc><text>test</text></doc></parameter></function></property></js2doc>",
254:
255:                        "/** @param bar: test */ function foo(bar) {}",
256:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"><doc><text>test</text></doc></parameter></function></property></js2doc>",
257:
258:                        "/** @param String bar: */ function foo(bar) {}",
259:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\" type=\"String\"></parameter></function></property></js2doc>",
260:
261:                        "/** @param String bar */ function foo(bar) {}",
262:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\" type=\"String\"></parameter></function></property></js2doc>",
263:
264:                        "/** @return String */ function foo(bar) {}",
265:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/><returns type=\"String\"/></function></property></js2doc>",
266:
267:                        "/** @returns String */ function foo(bar) {}",
268:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/><returns type=\"String\"/></function></property></js2doc>",
269:
270:                        "/** @return String: test */ function foo(bar) {}",
271:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/><returns type=\"String\"><doc><text>test</text></doc></returns></function></property></js2doc>",
272:
273:                        "/** @return String: <p>test</p> */ function foo(bar) {}",
274:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/><returns type=\"String\"><doc><text><p>test</p></text></doc></returns></function></property></js2doc>",
275:
276:                        "/** @return String: test &lt; best */ function foo(bar) {}",
277:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/><returns type=\"String\"><doc><text>test &lt; best</text></doc></returns></function></property></js2doc>",
278:
279:                        "/** @return String */ function foo(bar) {}",
280:                        "<js2doc><property id=\"foo\" name=\"foo\"><function><parameter name=\"bar\"/><returns type=\"String\"/></function></property></js2doc>",
281:
282:                        "/**\n  * Set the x scroll position of the textfield.\n  * @param Number n: set the left edge of the textfield to offset\n  * n pixels \n  * (n is always &lt; 0)\n  */\nfunction setXScroll ( n ){\n    this.sprite.setXScroll(n);\n}",
283:                        "<js2doc><property id=\"setXScroll\" name=\"setXScroll\"><doc><text>Set the x scroll position of the textfield.</text></doc><function><parameter name=\"n\" type=\"Number\"><doc><text>set the left edge of the textfield to offset\n n pixels \n (n is always &lt; 0)</text></doc></parameter></function></property></js2doc>",
284:
285:                        "/** @access private  */ function addText (msg1) { }; /** Foo */ function addText (msg2) { };",
286:                        "<js2doc><property id=\"addText\" name=\"addText\"><doc><text>Foo</text></doc><function><parameter name=\"msg2\"/></function></property></js2doc>", };
287:
288:                iterateTests(tests);
289:            }
290:
291:            public void testCallExpressions() {
292:
293:                String[] tests = {
294:                // Each case is input, expected-output
295:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
296:
297:                        "DeclareEvent(foo, \"onBar\");", "<js2doc/>", };
298:
299:                iterateTests(tests);
300:            }
301:
302:            public void testUnhandledDirectives() {
303:
304:                String[] tests = {
305:                // Each case is input, expected-output
306:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
307:
308:                        "foo(10)", "<js2doc/>",
309:
310:                        "#pragma 'warnUndefinedReferences=false'", "<js2doc/>", };
311:
312:                iterateTests(tests);
313:            }
314:
315:            public void testClassDefinitions() {
316:
317:                String[] tests = {
318:                        // Each case is input, expected-output
319:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
320:
321:                        // simple class declaration, no comment
322:                        "class foo {};",
323:                        "<js2doc><property id=\"foo\" name=\"foo\"><class/></property></js2doc>",
324:
325:                        // simple class declaration with comment
326:                        "/** this is a comment */ class foo {};",
327:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a comment</text></doc><class/></property></js2doc>",
328:
329:                        "// this is a comment\n class foo {};",
330:                        "<js2doc><property id=\"foo\" name=\"foo\"><class/></property></js2doc>",
331:
332:                        // class declaration with superclass, no comment
333:                        "class foo extends bar {};",
334:                        "<js2doc><property id=\"foo\" name=\"foo\"><class extends=\"bar\"/></property></js2doc>",
335:
336:                        // class declaration with superclass, with comment
337:                        "/** this is a comment */ class foo extends bar {};",
338:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a comment</text></doc><class extends=\"bar\"/></property></js2doc>",
339:
340:                        "// garbage\n\n/** this is a comment\n  */\nclass foo {};",
341:                        "<js2doc><property id=\"foo\" name=\"foo\"><doc><text>this is a comment</text></doc><class/></property></js2doc>",
342:
343:                        "// this is a comment\n class foo extends bar {};",
344:                        "<js2doc><property id=\"foo\" name=\"foo\"><class extends=\"bar\"/></property></js2doc>",
345:
346:                        "class foo { var bar; };",
347:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\"/></object></property></class></property></js2doc>",
348:
349:                        "class foo { var bar; }; var baz; ",
350:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\"/></object></property></class></property><property id=\"baz\" name=\"baz\"/></js2doc>",
351:
352:                        "class foo { static var bar; };",
353:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.bar\" name=\"bar\" /></class></property></js2doc>",
354:
355:                        "class foo { static var bar; var baz; };",
356:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.bar\" name=\"bar\" /><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.baz\" name=\"baz\"/></object></property></class></property></js2doc>",
357:
358:                        "class foo { var bar, baz; };",
359:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\"/><property id=\"foo.__ivars__.baz\" name=\"baz\"/></object></property></class></property></js2doc>",
360:
361:                        // no comment, but an attribute declaration
362:                        "class foo { var bar; var baz; };",
363:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\"/><property id=\"foo.__ivars__.baz\" name=\"baz\"/></object></property></class></property></js2doc>",
364:
365:                        "class foo { function bar () {}; };",
366:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.prototype\" name=\"prototype\"><object><property id=\"foo.prototype.bar\" name=\"bar\"><function/></property></object></property></class></property></js2doc>",
367:
368:                        "class foo { static function bar () {}; };",
369:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.bar\" name=\"bar\"><function/></property></class></property></js2doc>",
370:
371:                        // no comment, but an attribute declaration
372:                        "class foo { function bar (baz) {}; };",
373:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property name=\"prototype\" id=\"foo.prototype\"><object><property id=\"foo.prototype.bar\" name=\"bar\"><function><parameter name=\"baz\"/></function></property></object></property></class></property></js2doc>",
374:
375:                        "class foo { /** @access private */ var bar; };",
376:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\" access=\"private\"/></object></property></class></property></js2doc>",
377:
378:                        "class foo { /** comment */ static var bar; };",
379:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.bar\" name=\"bar\"><doc><text>comment</text></doc></property></class></property></js2doc>",
380:
381:                        "class foo { /** @access private */ static var bar; };",
382:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.bar\" name=\"bar\" access=\"private\"/></class></property></js2doc>",
383:
384:                        "class foo { /** comment */ static function bar () {}; };",
385:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.bar\" name=\"bar\"><doc><text>comment</text></doc><function/></property></class></property></js2doc>",
386:
387:                        "class foo { /** @access private */ static function bar () {}; };",
388:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.bar\" name=\"bar\" access=\"private\"><function/></property></class></property></js2doc>",
389:
390:                        "class foo { /** @keywords private */ var bar; };",
391:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\" access=\"private\"/></object></property></class></property></js2doc>",
392:
393:                        "class foo { /** @type Boolean */ var bar; };",
394:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\" type=\"Boolean\"/></object></property></class></property></js2doc>",
395:
396:                        "class foo { /** @keywords private hack */ var bar; };",
397:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\" access=\"private\"><doc keywords=\"hack\"/></property></object></property></class></property></js2doc>",
398:
399:                        "class foo { var bar = true; };",
400:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\" value=\"true\" /></object></property></class></property></js2doc>",
401:
402:                        "class foo { var bar = null; };",
403:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\" value=\"null\" /></object></property></class></property></js2doc>",
404:
405:                        "class foo { DeclareEvent(prototype, \"onhack\"); };",
406:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property name=\"prototype\" id=\"foo.prototype\"><object><property id=\"foo.prototype.onhack\" name=\"onhack\" type=\"LzEvent\" value=\"LzNullEvent\"/></object></property></class></property></js2doc>",
407:
408:                        "class foo { /** a hack */ DeclareEvent(prototype, \"onhack\"); };",
409:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property name=\"prototype\" id=\"foo.prototype\"><object><property id=\"foo.prototype.onhack\" name=\"onhack\" type=\"LzEvent\" value=\"LzNullEvent\"><doc><text>a hack</text></doc></property></object></property></class></property></js2doc>",
410:
411:                        // should trigger "no referent" warning
412:                        "class foo { DeclareEvent(bar, \"onhack\"); };",
413:                        "<js2doc><property id=\"foo\" name=\"foo\"><class/></property></js2doc>",
414:
415:                        "/** @access private */ class foo {};",
416:                        "<js2doc><property id=\"foo\" name=\"foo\" access=\"private\"><class/></property></js2doc>",
417:
418:                        "/** @keywords private */ class foo { };",
419:                        "<js2doc><property id=\"foo\" name=\"foo\" access=\"private\"><class/></property></js2doc>",
420:
421:                        "class foo { function construct(parent, args) {} };",
422:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property name=\"prototype\" id=\"foo.prototype\"><object><property id=\"foo.prototype.construct\" name=\"construct\"><function><parameter name=\"parent\"/><parameter name=\"args\"/></function></property></object></property></class></property></js2doc>",
423:
424:                        "/** @initarg foo */ class foo {};",
425:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><initarg id=\"foo.foo\" name=\"foo\"/></class></property></js2doc>",
426:
427:                        "/** @initarg foo: bar */ class foo {};",
428:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><initarg id=\"foo.foo\" name=\"foo\"><doc><text>bar</text></doc></initarg></class></property></js2doc>",
429:
430:                        "/** @initarg Number foo */ class foo {};",
431:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><initarg id=\"foo.foo\" name=\"foo\" type=\"Number\"/></class></property></js2doc>",
432:
433:                        "/** @initarg Number foo: bar */ class foo {};",
434:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><initarg id=\"foo.foo\" name=\"foo\" type=\"Number\"><doc><text>bar</text></doc></initarg></class></property></js2doc>",
435:
436:                        "/** @initarg public Number foo */ class foo {};",
437:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><initarg id=\"foo.foo\" name=\"foo\" type=\"Number\" access=\"public\"/></class></property></js2doc>",
438:
439:                        "/** @initarg public Number foo: bar */ class foo {};",
440:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><initarg id=\"foo.foo\" name=\"foo\" type=\"Number\" access=\"public\"><doc><text>bar</text></doc></initarg></class></property></js2doc>",
441:
442:                        "/** @initarg deprecated Number foo: bar */ class foo {};",
443:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><initarg id=\"foo.foo\" name=\"foo\" type=\"Number\" modifiers=\"deprecated\"><doc><text>bar</text></doc></initarg></class></property></js2doc>",
444:
445:                        "class foo { setters.bar = \"setBar\"; };",
446:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.setters\" name=\"setters\"><object><property id=\"foo.setters.bar\" name=\"bar\" value=\"setBar\"/></object></property></class></property></js2doc>",
447:
448:                        "class foo { setters.bar = \"setBar\"; var bar; };",
449:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.setters\" name=\"setters\"><object><property id=\"foo.setters.bar\" name=\"bar\" value=\"setBar\"/></object></property><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\"/></object></property></class></property></js2doc>",
450:
451:                        "class foo { var bar; setters.bar = \"setBar\"; };",
452:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property id=\"foo.__ivars__.bar\" name=\"bar\"/></object></property><property id=\"foo.setters\" name=\"setters\"><object><property id=\"foo.setters.bar\" name=\"bar\" value=\"setBar\"/></object></property></class></property></js2doc>",
453:
454:                        "class foo { foo.prototype.bar = 10; }",
455:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property name=\"prototype\" id=\"foo.prototype\"><object><property name=\"bar\" id=\"foo.prototype.bar\" value=\"10\"/></object></property></class></property></js2doc>",
456:
457:                        "class foo { function bar() {}; bar.prototype.baz = 10; }",
458:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.prototype\" name=\"prototype\"><object><property id=\"foo.prototype.bar\" name=\"bar\"><function/></property></object></property></class></property></js2doc>", };
459:
460:                iterateTests(tests);
461:            }
462:
463:            public void testTopLevelIfDirective() {
464:
465:                String[] tests = {
466:                        // Each case is input, expected-output
467:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
468:
469:                        "if (false) { var foo; }",
470:                        "<js2doc></js2doc>",
471:
472:                        "if (true) { var foo; }",
473:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
474:
475:                        "if (true) { var foo; } else { var bar; }",
476:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
477:
478:                        "if (true) { var foo; } else if (true) { var bar; }",
479:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
480:
481:                        "if (true) { var foo; } else if (false) { var bar; }",
482:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
483:
484:                        "if (false) { var foo; } else { var bar; }",
485:                        "<js2doc><property id=\"bar\" name=\"bar\"/></js2doc>",
486:
487:                        "if (false) { var foo; } else if (true) { var bar; }",
488:                        "<js2doc><property id=\"bar\" name=\"bar\"/></js2doc>",
489:
490:                        "if (false) { var foo; } else if (false) { var bar; }",
491:                        "<js2doc></js2doc>",
492:
493:                        "if ($dhtml) { var foo; }",
494:                        "<js2doc><property name=\"foo\" id=\"foo+dhtml\" runtimes=\"dhtml\"/></js2doc>",
495:
496:                        "if ($dhtml) { function foo() {}; }",
497:                        "<js2doc><property name=\"foo\" id=\"foo+dhtml\" runtimes=\"dhtml\"><function/></property></js2doc>",
498:
499:                        "if ($swf8) { var foo; } else { }",
500:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/></js2doc>",
501:
502:                        "if ($swf8) { var foo; } else { var bar; }",
503:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+dhtml+j2me+svg+swf9\" runtimes=\"dhtml j2me svg swf9\"/></js2doc>",
504:
505:                        "if ($swf8) { var foo; } else { var bar; var baz; }",
506:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+dhtml+j2me+svg+swf9\" runtimes=\"dhtml j2me svg swf9\"/><property name=\"baz\" id=\"baz+dhtml+j2me+svg+swf9\" runtimes=\"dhtml j2me svg swf9\"/></js2doc>",
507:
508:                        "if ($swf8) { var foo; } else { if ($dhtml) { var bar; } }",
509:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+dhtml\" runtimes=\"dhtml\"/></js2doc>",
510:
511:                        "if ($swf8) { var foo; } else { if ($dhtml) { var bar; } var baz; }",
512:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+dhtml\" runtimes=\"dhtml\"/><property name=\"baz\" id=\"baz+dhtml+j2me+svg+swf9\" runtimes=\"dhtml j2me svg swf9\"/></js2doc>",
513:
514:                        "if ($swf8) { var foo; } else if ($dhtml) { var bar; }",
515:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+dhtml\" runtimes=\"dhtml\"/></js2doc>",
516:
517:                        "if ($swf8) { var foo; } else if ($swf9) { var fab; } else if ($dhtml) { var bar; }",
518:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"fab\" id=\"fab+swf9\" runtimes=\"swf9\"/><property name=\"bar\" id=\"bar+dhtml\" runtimes=\"dhtml\"/></js2doc>",
519:
520:                        "if ($swf8) { var foo; } else if (!$swf8) { var bar; }",
521:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+dhtml+j2me+svg+swf9\" runtimes=\"dhtml j2me svg swf9\"/></js2doc>",
522:
523:                        "if ($swf8) { var foo; } else if (false) { var bar; }",
524:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/></js2doc>",
525:
526:                        "if ($swf8) { var foo; } else if (true) { var bar; }",
527:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+dhtml+j2me+svg+swf9\" runtimes=\"dhtml j2me svg swf9\"/></js2doc>",
528:
529:                        "if (! $dhtml) { var foo; }",
530:                        "<js2doc><property name=\"foo\" id=\"foo+j2me+svg+swf8+swf9\" runtimes=\"j2me svg swf8 swf9\"/></js2doc>",
531:
532:                        "if (! ($swf8 || $swf9)) { var foo; }",
533:                        "<js2doc><property name=\"foo\" id=\"foo+dhtml+j2me+svg\" runtimes=\"dhtml j2me svg\"/></js2doc>",
534:
535:                        "if (true || false) { var foo; }",
536:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
537:
538:                        "if (true || true) { var foo; }",
539:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
540:
541:                        "if (false || true) { var foo; }",
542:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
543:
544:                        "if (false || false) { var foo; }",
545:                        "<js2doc/>",
546:
547:                        "if ($swf8 || $swf9) { var foo; }",
548:                        "<js2doc><property name=\"foo\" id=\"foo+swf8+swf9\" runtimes=\"swf8 swf9\"/></js2doc>",
549:
550:                        "if (true || $swf9) { var foo; }",
551:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
552:
553:                        "if ($swf9 || true) { var foo; }",
554:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
555:
556:                        "if (false || $swf9) { var foo; }",
557:                        "<js2doc><property name=\"foo\" id=\"foo+swf9\" runtimes=\"swf9\"/></js2doc>",
558:
559:                        "if ($swf9 || false) { var foo; }",
560:                        "<js2doc><property name=\"foo\" id=\"foo+swf9\" runtimes=\"swf9\"/></js2doc>",
561:
562:                        "if ($swf8 || $swf9) { var foo; } else { var bar; }",
563:                        "<js2doc><property name=\"foo\" id=\"foo+swf8+swf9\" runtimes=\"swf8 swf9\"/><property name=\"bar\" id=\"bar+dhtml+j2me+svg\" runtimes=\"dhtml j2me svg\"/></js2doc>",
564:
565:                        "if ($swf8 || !$swf9) { var foo; } else { var bar; }",
566:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property name=\"bar\" id=\"bar+swf9\" runtimes=\"swf9\"/></js2doc>",
567:
568:                        "if (true && true) { var foo; }",
569:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
570:
571:                        "if (true && false) { var foo; }",
572:                        "<js2doc/>",
573:
574:                        "if (false && true) { var foo; }",
575:                        "<js2doc/>",
576:
577:                        "if (false && false) { var foo; }",
578:                        "<js2doc/>",
579:
580:                        "if (true && $swf9) { var foo; }",
581:                        "<js2doc><property name=\"foo\" id=\"foo+swf9\" runtimes=\"swf9\"/></js2doc>",
582:
583:                        "if ($swf9 && true) { var foo; }",
584:                        "<js2doc><property name=\"foo\" id=\"foo+swf9\" runtimes=\"swf9\"/></js2doc>",
585:
586:                        "if (false && $swf9) { var foo; }",
587:                        "<js2doc/>",
588:
589:                        "if ($swf9 && false) { var foo; }",
590:                        "<js2doc/>",
591:
592:                        // we punt if we see something like this -- too complex to model
593:                        "if ($swf8 && $swf9) { var foo; }",
594:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
595:
596:                        // we punt if we see something like this -- too complex to model
597:                        "if ($swf8 && $swf9) { var foo; } else { var bar; }",
598:                        "<js2doc><property id=\"foo\" name=\"foo\" /></js2doc>",
599:
600:                        // punt
601:                        "if ($swf8 && !$swf9) { var foo; } else { var bar; }",
602:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
603:
604:                        // punt
605:                        "if ((! $swf8) && (! $swf9)) { var foo; }",
606:                        "<js2doc><property id=\"foo\" name=\"foo\"/></js2doc>",
607:
608:                        // punt
609:                        "if ($swf8) { var foo; } if ((!$swf8) && $dhtml) { var bar; }",
610:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/><property id=\"bar\" name=\"bar\"/></js2doc>",
611:
612:                        // punt
613:                        "if ($debug) { function foo () {}; if ($swf8) { foo.bar = 10; } }",
614:                        "<js2doc><property name=\"foo\" id=\"foo+debug\" includebuilds=\"debug\"><function/></property></js2doc>",
615:                        //"<js2doc><property name=\"foo\" id=\"foo+debug\" includebuilds=\"debug\"><function><property name=\"bar\" id=\"foo+debug.bar+swf8\" value=\"10\" runtimes=\"swf8\" /></function></property></js2doc>",
616:
617:                        "if (! $swf9) { if (! $swf8) { var foo; } }",
618:                        "<js2doc><property name=\"foo\" id=\"foo+dhtml+j2me+svg\" runtimes=\"dhtml j2me svg\"/></js2doc>",
619:
620:                        "if ($swf8) { class foo { var bar; function baz () {}; } }",
621:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"><class><property name=\"__ivars__\" id=\"foo+swf8.__ivars__\"><object><property id=\"foo+swf8.__ivars__.bar\" name=\"bar\"/></object></property><property name=\"prototype\" id=\"foo+swf8.prototype\"><object><property id=\"foo+swf8.prototype.baz\" name=\"baz\"><function/></property></object></property></class></property></js2doc>",
622:
623:                        "if ($swf8) { class foo { prototype.bar = 10; } }",
624:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"><class><property id=\"foo+swf8.prototype\" name=\"prototype\"><object><property id=\"foo+swf8.prototype.bar\" name=\"bar\" value=\"10\" /></object></property></class></property></js2doc>",
625:
626:                        "if ($swf8) { /** this is a comment */ var foo; }",
627:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"><doc><text>this is a comment</text></doc></property></js2doc>",
628:
629:                        "if ($swf8) { /** this is a comment */ var foo; // another comment\n var bar; }",
630:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"><doc><text>this is a comment</text></doc></property><property name=\"bar\" id=\"bar+swf8\" runtimes=\"swf8\"/></js2doc>",
631:
632:                        "if ($swf8) { /** this is a comment */ var foo; function bar (baz) {} }",
633:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"><doc><text>this is a comment</text></doc></property><property name=\"bar\" id=\"bar+swf8\" runtimes=\"swf8\"><function><parameter name=\"baz\"/></function></property></js2doc>",
634:
635:                        "if ($swf8) { /* this is a comment */ var foo; }",
636:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/></js2doc>",
637:
638:                        "if ($swf8) { // this is a comment\n var foo; }",
639:                        "<js2doc><property name=\"foo\" id=\"foo+swf8\" runtimes=\"swf8\"/></js2doc>",
640:
641:                        "class foo { if ($dhtml) { function construct(parent, args) {} } };",
642:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property name=\"prototype\" id=\"foo.prototype\"><object><property name=\"construct\" runtimes=\"dhtml\" id=\"foo.prototype.construct+dhtml\"><function><parameter name=\"parent\"/><parameter name=\"args\"/></function></property></object></property></class></property></js2doc>",
643:
644:                        "if ($swf8) { var foo; } else if ($dhtml) { var foo; }",
645:                        "<js2doc><property id=\"foo+swf8\" name=\"foo\" runtimes=\"swf8\"/><property id=\"foo+dhtml\" name=\"foo\" runtimes=\"dhtml\"/></js2doc>",
646:
647:                        "if ($swf8) { class foo extends bar {}; }",
648:                        "<js2doc><property id=\"foo+swf8\" name=\"foo\" runtimes=\"swf8\"><class extends=\"bar\"/></property></js2doc>", };
649:
650:                iterateTests(tests);
651:            }
652:
653:            public void testClassIfDirective() {
654:
655:                String[] tests = {
656:                        // Each case is input, expected-output
657:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
658:
659:                        "class foo { if ($dhtml) { var bar; } };",
660:                        "<js2doc><property id=\"foo\" name=\"foo\"><class><property id=\"foo.__ivars__\" name=\"__ivars__\"><object><property name=\"bar\" id=\"foo.__ivars__.bar+dhtml\" runtimes=\"dhtml\"/></object></property></class></property></js2doc>",
661:
662:                };
663:
664:                iterateTests(tests);
665:            }
666:
667:            public void testObjectLiteral() {
668:
669:                String[] tests = {
670:                        // Each case is input, expected-output
671:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
672:
673:                        "var foo = { bar: 10 }",
674:                        "<js2doc><property id=\"foo\" name=\"foo\"><object><property id=\"foo.bar\" name=\"bar\" value=\"10\"/></object></property></js2doc>",
675:
676:                        "var foo = { bar: function () {} }",
677:                        "<js2doc><property id=\"foo\" name=\"foo\"><object><property id=\"foo.bar\" name=\"bar\"><function/></property></object></property></js2doc>",
678:
679:                };
680:
681:                iterateTests(tests);
682:            }
683:
684:            public void testOldSkoolClassDeclarations() {
685:
686:                String[] tests = {
687:                        // Each case is input, expected-output
688:                        // "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" is automatically prepended to output
689:
690:                        "var LzMessage = function (message) {}; LzMessage.prototype = new String();",
691:                        "<js2doc><property id=\"LzMessage\" name=\"LzMessage\"><function><parameter name=\"message\"/><property id=\"LzMessage.prototype\" name=\"prototype\"><object type=\"String\"></object></property></function></property></js2doc>",
692:
693:                        "var LzMessage = function (message) {}; LzMessage.prototype = new String(); LzMessage.prototype.message = '';",
694:                        "<js2doc><property id=\"LzMessage\" name=\"LzMessage\"><function><parameter name=\"message\"/><property id=\"LzMessage.prototype\" name=\"prototype\"><object type=\"String\"><property id=\"LzMessage.prototype.message\" name=\"message\" value=\"\"/></object></property></function></property></js2doc>",
695:
696:                        "if ($swf8) { var LzMessage = function (message) {}; LzMessage.prototype = new String(); LzMessage.prototype.message = ''; }",
697:                        "<js2doc><property id=\"LzMessage+swf8\" name=\"LzMessage\" runtimes=\"swf8\"><function><parameter name=\"message\"/><property id=\"LzMessage+swf8.prototype\" name=\"prototype\"><object type=\"String\"><property id=\"LzMessage+swf8.prototype.message\" name=\"message\" value=\"\"/></object></property></function></property></js2doc>",
698:
699:                };
700:
701:                iterateTests(tests);
702:            }
703:
704:            static final String[] runtimeOptionStrings = { "swf8", "swf9",
705:                    "dhtml", "svg", "j2me" };
706:            static final Set runtimeOptions = new HashSet(Arrays
707:                    .asList(runtimeOptionStrings));
708:            static final String[][] runtimeAliasStrings = {
709:                    { "as2", "swf8", "swf9" }, { "as3", "swf9" },
710:                    { "js1", "dhtml", "j2me", "svg" } };
711:            static final List runtimeAliases = Arrays
712:                    .asList(runtimeAliasStrings);
713:            static final String[] buildOptionStrings = { "debug", "profile" };
714:            static final List buildOptions = Arrays.asList(buildOptionStrings);
715:
716:            private void iterateTests(String[] tests) {
717:
718:                for (Iterator iter = Arrays.asList(tests).iterator(); iter
719:                        .hasNext();) {
720:                    String source = (String) iter.next();
721:                    assertTrue(iter.hasNext());
722:                    String result = (String) iter.next();
723:                    result = result
724:                            .replace(
725:                                    "<js2doc",
726:                                    "<js2doc buildoptions=\"debug profile\" runtimeoptions=\"dhtml j2me svg swf8 swf9\"");
727:                    result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
728:                            + result;
729:
730:                    try {
731:                        Document control = XMLUnit.buildControlDocument(result);
732:
733:                        Document test = JS2Doc.toXML(source, null, null, null,
734:                                runtimeOptions, runtimeAliases, buildOptions);
735:
736:                        Diff diff = new Diff(control, test);
737:
738:                        String testString = JS2DocUtils.xmlToString(test);
739:
740:                        if (diff.identical() == false) {
741:                            System.out
742:                                    .println("identical: " + diff.identical());
743:                            System.out.println("input:  " + source);
744:                            System.out.println("output: " + testString);
745:                            System.out.println("expect: " + result);
746:                        }
747:
748:                        assertXMLIdentical(diff, true, "JS2Doc.toXML(\""
749:                                + source + "\")");
750:
751:                    } catch (org.xml.sax.SAXException exc) {
752:                        fail("SAXException JS2Doc.toXML(\"" + source + "\")");
753:                        exc.printStackTrace();
754:                    } catch (java.io.IOException exc) {
755:                        fail("IOException JS2Doc.toXML(\"" + source + "\")");
756:                        exc.printStackTrace();
757:                    } catch (javax.xml.parsers.ParserConfigurationException exc) {
758:                        fail("ParserConfigurationException JS2Doc.toXML(\""
759:                                + source + "\")");
760:                        exc.printStackTrace();
761:                    }
762:                }
763:            }
764:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.