Source Code Cross Referenced for ArgumentTest.java in  » Scripting » Jatha » org » jatha » test » junit » 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 » Scripting » Jatha » org.jatha.test.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jatha - a Common LISP-compatible LISP library in Java.
003:         * Copyright (C) 1997-2005 Micheal Scott Hewett
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         *
020:         * For further information, please contact Micheal Hewett at
021:         *   hewett@cs.stanford.edu
022:         *
023:         */
024:        /**
025:         * $Id: ArgumentTest.java,v 1.1 2005/05/21 16:28:45 olagus Exp $
026:         */package org.jatha.test.junit;
027:
028:        import java.util.Map;
029:
030:        import junit.framework.Test;
031:        import junit.framework.TestCase;
032:        import junit.framework.TestSuite;
033:
034:        import org.jatha.Jatha;
035:        import org.jatha.compile.args.LambdaList;
036:        import org.jatha.compile.args.OrdinaryLambdaList;
037:        import org.jatha.compile.args.NormalArgument;
038:        import org.jatha.compile.args.OptionalArgument;
039:        import org.jatha.compile.args.RestArgument;
040:        import org.jatha.compile.args.KeyArgument;
041:        import org.jatha.compile.args.AuxArgument;
042:        import org.jatha.dynatype.LispValue;
043:
044:        /**
045:         * <p>Tests the handling of arguments.</p>
046:         *
047:         * @author <a href="mailto:Ola.Bini@itc.ki.se">Ola Bini</a>
048:         * @version $Revision: 1.1 $
049:         */
050:        public class ArgumentTest extends TestCase {
051:            private static Jatha lisp;
052:
053:            static {
054:                lisp = new Jatha(false, false, false); // no Jatha gui
055:                lisp.init();
056:                lisp.start();
057:            }
058:
059:            private LambdaList list1; // (a b)                                               //tested
060:            private LambdaList list2; // (a &optional (b 2))                                 //tested
061:            private LambdaList list2_x; // (a &optional (b a))                               //tested
062:            private LambdaList list2_y; // (a &optional (b (+ a 3)))                         //tested
063:            private LambdaList list3; // (&optional (a 2 b) (c 3 d))                         //tested
064:            private LambdaList list4; // (&optional (a 2 b) (c 3 d) &rest x)                 //tested
065:            private LambdaList list5; // (a b &key c d)                                      //tested
066:            private LambdaList list6; // (a &optional (b 3) &rest x &key c (d a))            //tested
067:            private LambdaList list7; // (a &optional (b 3) &rest x &key c (d a) &allow-other-keys) //tested
068:            private LambdaList list8; // (a &key ((:c int) 13 supp))                         //tested
069:            private LambdaList list9; // (&aux (a 13))                                       //tested
070:
071:            private LispValue list2_b_default;
072:            private LispValue list3_a_default;
073:            private LispValue list3_c_default;
074:            private LispValue list4_a_default;
075:            private LispValue list4_c_default;
076:            private LispValue list6_b_default;
077:            private LispValue list7_b_default;
078:            private LispValue list8_c_default;
079:
080:            private LispValue a_key;
081:            private LispValue a_sym;
082:            private LispValue b_key;
083:            private LispValue b_sym;
084:            private LispValue c_key;
085:            private LispValue c_sym;
086:            private LispValue d_key;
087:            private LispValue d_sym;
088:            private LispValue x_key;
089:            private LispValue x_sym;
090:            private LispValue supp_sym;
091:            private LispValue int_sym;
092:
093:            public ArgumentTest(final String name) {
094:                super (name);
095:            }
096:
097:            /**
098:             * Use -gui to enable the gui.
099:             * @param args command-line arguments.
100:             */
101:            public static void main(String[] args) {
102:                boolean useGui = false; // default behavior
103:
104:                for (int i = 0, j = args.length; i < j; i++) {
105:                    if (args[i].equalsIgnoreCase("-gui")) {
106:                        useGui = true;
107:                        break;
108:                    }
109:                }
110:
111:                if (useGui) {
112:                    junit.swingui.TestRunner.run(ArgumentTest.class);
113:                } else {
114:                    junit.textui.TestRunner.run(suite());
115:                }
116:            }
117:
118:            public static Test suite() {
119:                return new TestSuite(ArgumentTest.class);
120:            }
121:
122:            protected void setUp() throws Exception {
123:                list1 = new OrdinaryLambdaList(lisp);
124:                list2 = new OrdinaryLambdaList(lisp);
125:                list2_x = new OrdinaryLambdaList(lisp);
126:                list2_y = new OrdinaryLambdaList(lisp);
127:                list3 = new OrdinaryLambdaList(lisp);
128:                list4 = new OrdinaryLambdaList(lisp);
129:                list5 = new OrdinaryLambdaList(lisp);
130:                list6 = new OrdinaryLambdaList(lisp);
131:                list7 = new OrdinaryLambdaList(lisp);
132:                list8 = new OrdinaryLambdaList(lisp);
133:                list9 = new OrdinaryLambdaList(lisp);
134:
135:                a_sym = lisp.EVAL.intern("A");
136:                a_key = lisp.EVAL.intern(":A");
137:                b_sym = lisp.EVAL.intern("B");
138:                b_key = lisp.EVAL.intern(":B");
139:                c_sym = lisp.EVAL.intern("C");
140:                c_key = lisp.EVAL.intern(":C");
141:                d_sym = lisp.EVAL.intern("D");
142:                d_key = lisp.EVAL.intern(":D");
143:                x_sym = lisp.EVAL.intern("X");
144:                x_key = lisp.EVAL.intern(":X");
145:                int_sym = lisp.EVAL.intern("INT");
146:                supp_sym = lisp.EVAL.intern("SUPP");
147:
148:                list1.getNormalArguments().add(new NormalArgument(a_sym));
149:                list1.getNormalArguments().add(new NormalArgument(b_sym));
150:
151:                list2.getNormalArguments().add(new NormalArgument(a_sym));
152:                list2_b_default = lisp.makeInteger(2);
153:                list2.getOptionalArguments().add(
154:                        new OptionalArgument(b_sym, list2_b_default));
155:
156:                list2_x.getNormalArguments().add(new NormalArgument(a_sym));
157:                list2_x.getOptionalArguments().add(
158:                        new OptionalArgument(b_sym, a_sym));
159:
160:                list2_y.getNormalArguments().add(new NormalArgument(a_sym));
161:                list2_y.getOptionalArguments().add(
162:                        new OptionalArgument(b_sym, lisp.makeList(lisp.EVAL
163:                                .intern("+"), a_sym, lisp.makeInteger(3))));
164:
165:                list3_a_default = lisp.makeInteger(2);
166:                list3.getOptionalArguments().add(
167:                        new OptionalArgument(a_sym, list3_a_default, b_sym));
168:                list3_c_default = lisp.makeInteger(3);
169:                list3.getOptionalArguments().add(
170:                        new OptionalArgument(c_sym, list3_c_default, d_sym));
171:
172:                list4_a_default = lisp.makeInteger(2);
173:                list4.getOptionalArguments().add(
174:                        new OptionalArgument(a_sym, list4_a_default, b_sym));
175:                list4_c_default = lisp.makeInteger(3);
176:                list4.getOptionalArguments().add(
177:                        new OptionalArgument(c_sym, list4_c_default, d_sym));
178:                list4.setRestArgument(new RestArgument(x_sym));
179:
180:                list5.getNormalArguments().add(new NormalArgument(a_sym));
181:                list5.getNormalArguments().add(new NormalArgument(b_sym));
182:                list5.getKeyArguments().put(c_key,
183:                        new KeyArgument(c_sym, c_key));
184:                list5.getKeyArguments().put(d_key,
185:                        new KeyArgument(d_sym, d_key));
186:
187:                list6.getNormalArguments().add(new NormalArgument(a_sym));
188:                list6_b_default = lisp.makeInteger(3);
189:                list6.getOptionalArguments().add(
190:                        new OptionalArgument(b_sym, list6_b_default));
191:                list6.setRestArgument(new RestArgument(x_sym));
192:                list6.getKeyArguments().put(c_key,
193:                        new KeyArgument(c_sym, c_key));
194:                list6.getKeyArguments().put(d_key,
195:                        new KeyArgument(d_sym, d_key, a_sym));
196:
197:                list7.getNormalArguments().add(new NormalArgument(a_sym));
198:                list7_b_default = lisp.makeInteger(3);
199:                list7.getOptionalArguments().add(
200:                        new OptionalArgument(b_sym, list7_b_default));
201:                list7.setRestArgument(new RestArgument(x_sym));
202:                list7.getKeyArguments().put(c_key,
203:                        new KeyArgument(c_sym, c_key));
204:                list7.getKeyArguments().put(d_key,
205:                        new KeyArgument(d_sym, d_key, a_sym));
206:                list7.setAllowOtherKeys(true);
207:
208:                list8.getNormalArguments().add(new NormalArgument(a_sym));
209:                list8_c_default = lisp.makeInteger(13);
210:                list8.getKeyArguments().put(
211:                        c_key,
212:                        new KeyArgument(int_sym, c_key, list8_c_default,
213:                                supp_sym));
214:
215:                list9.getAuxArguments().add(
216:                        new AuxArgument(a_sym, lisp.makeInteger(13)));
217:            }
218:
219:            protected void tearDown() {
220:                list1 = null;
221:                list2 = null;
222:                list2_x = null;
223:                list2_y = null;
224:                list3 = null;
225:                list4 = null;
226:                list5 = null;
227:                list6 = null;
228:                list7 = null;
229:                list8 = null;
230:                list9 = null;
231:
232:                a_sym = null;
233:                a_key = null;
234:                b_sym = null;
235:                b_key = null;
236:                c_sym = null;
237:                c_key = null;
238:                d_sym = null;
239:                d_key = null;
240:                x_sym = null;
241:                x_key = null;
242:                supp_sym = null;
243:
244:                list2_b_default = null;
245:                list3_a_default = null;
246:                list3_c_default = null;
247:                list4_a_default = null;
248:                list4_c_default = null;
249:                list6_b_default = null;
250:                list7_b_default = null;
251:            }
252:
253:            public void testNormalArguments() {
254:                final LispValue arg1 = lisp.makeInteger(17);
255:                final LispValue arg2 = lisp.makeString("Ojsan sa");
256:
257:                final LispValue argList1 = lisp.makeList(arg1, arg2);
258:                final Map outp = list1.parse(argList1);
259:                assertEquals("Argument 1 should be correct", arg1, outp
260:                        .get(a_sym));
261:                assertEquals("Argument 2 should be correct", arg2, outp
262:                        .get(b_sym));
263:            }
264:
265:            public void testOptionalArguments() {
266:                final LispValue arg1 = lisp.makeInteger(17);
267:                final LispValue arg2 = lisp.makeString("Ojsan sa");
268:                final LispValue argList1 = lisp.makeList(arg1, arg2);
269:                final LispValue argList2 = lisp.makeList(arg1);
270:                final LispValue argList3 = lisp.makeList(arg1, list2_b_default);
271:                final Map outp1 = list2.parse(argList1);
272:                final Map outp2 = list2.parse(argList2);
273:                final Map outp3 = list2.parse(argList3);
274:                assertEquals("Argument 1 should be correct", arg1, outp1
275:                        .get(a_sym));
276:                assertEquals("Argument 2 should be correct", arg2, outp1
277:                        .get(b_sym));
278:
279:                assertEquals("Argument 1 should be correct", arg1, outp2
280:                        .get(a_sym));
281:                assertEquals("Defaultargument 2 should be correct",
282:                        list2_b_default, outp2.get(b_sym));
283:
284:                assertEquals("Argument 1 should be correct", arg1, outp3
285:                        .get(a_sym));
286:                assertEquals("Argument 2 should be correct", list2_b_default,
287:                        outp3.get(b_sym));
288:            }
289:
290:            public void testOptionalArgumentsWithInternalDefaults() {
291:                final LispValue arg1 = lisp.makeInteger(17);
292:                final LispValue argList = lisp.makeList(arg1);
293:                final Map outp = list2_x.parse(argList);
294:                assertEquals("Argument 1 should be correct", arg1, outp
295:                        .get(a_sym));
296:                assertEquals("Argument 2 should be correct", arg1, outp
297:                        .get(b_sym));
298:            }
299:
300:            public void testOptionalArgumentsWithInternalDefaultForm() {
301:                final LispValue arg1 = lisp.makeInteger(17);
302:                final LispValue expected = lisp.makeInteger(20);
303:                final LispValue argList = lisp.makeList(arg1);
304:                final Map outp = list2_y.parse(argList);
305:                assertEquals("Argument 1 should be correct", arg1, outp
306:                        .get(a_sym));
307:                assertEquals("Argument 2 should be correct", expected
308:                        .toStringSimple(), ((LispValue) outp.get(b_sym))
309:                        .toStringSimple());
310:            }
311:
312:            public void testOptionalArgumentsWithSupplied() {
313:                final LispValue arg1 = lisp.makeInteger(17);
314:                final LispValue arg2 = lisp.makeString("Ojsan sa");
315:                final LispValue argList1 = lisp.makeList(arg1, arg2);
316:                final LispValue argList2 = lisp.makeList(arg1);
317:                final LispValue argList3 = lisp.NIL;
318:                final Map outp1 = list3.parse(argList1);
319:                final Map outp2 = list3.parse(argList2);
320:                final Map outp3 = list3.parse(argList3);
321:
322:                assertEquals("Argument 1 should be correct", arg1, outp1
323:                        .get(a_sym));
324:                assertEquals("Argument 2 should be correct", arg2, outp1
325:                        .get(c_sym));
326:                assertEquals("Argument 1 supplied should be correct", lisp.T,
327:                        outp1.get(b_sym));
328:                assertEquals("Argument 2 supplied should be correct", lisp.T,
329:                        outp1.get(d_sym));
330:
331:                assertEquals("Argument 1 should be correct", arg1, outp2
332:                        .get(a_sym));
333:                assertEquals("Argument 2 should be correct", list3_c_default,
334:                        outp2.get(c_sym));
335:                assertEquals("Argument 1 supplied should be correct", lisp.T,
336:                        outp2.get(b_sym));
337:                assertEquals("Argument 2 supplied should be correct", lisp.NIL,
338:                        outp2.get(d_sym));
339:
340:                assertEquals("Argument 1 should be correct", list3_a_default,
341:                        outp3.get(a_sym));
342:                assertEquals("Argument 2 should be correct", list3_c_default,
343:                        outp3.get(c_sym));
344:                assertEquals("Argument 1 supplied should be correct", lisp.NIL,
345:                        outp3.get(b_sym));
346:                assertEquals("Argument 2 supplied should be correct", lisp.NIL,
347:                        outp3.get(d_sym));
348:            }
349:
350:            public void testOptionalArgumentsWithSuppliedAndRest() {
351:                final LispValue arg1 = lisp.makeInteger(17);
352:                final LispValue arg2 = lisp.makeString("Ojsan sa");
353:                final LispValue argList1 = lisp.makeList(arg1, arg2);
354:                final LispValue argList2 = lisp.makeList(arg1);
355:                final LispValue argList3 = lisp.NIL;
356:                final Map outp1 = list4.parse(argList1);
357:                final Map outp2 = list4.parse(argList2);
358:                final Map outp3 = list4.parse(argList3);
359:
360:                assertEquals("Argument 1 should be correct", arg1, outp1
361:                        .get(a_sym));
362:                assertEquals("Argument 2 should be correct", arg2, outp1
363:                        .get(c_sym));
364:                assertEquals("Argument 1 supplied should be correct", lisp.T,
365:                        outp1.get(b_sym));
366:                assertEquals("Argument 2 supplied should be correct", lisp.T,
367:                        outp1.get(d_sym));
368:                assertEquals("Rest argument should be correct", lisp.NIL, outp1
369:                        .get(x_sym));
370:
371:                assertEquals("Argument 1 should be correct", arg1, outp2
372:                        .get(a_sym));
373:                assertEquals("Argument 2 should be correct", list4_c_default,
374:                        outp2.get(c_sym));
375:                assertEquals("Argument 1 supplied should be correct", lisp.T,
376:                        outp2.get(b_sym));
377:                assertEquals("Argument 2 supplied should be correct", lisp.NIL,
378:                        outp2.get(d_sym));
379:                assertEquals("Rest argument should be correct", lisp.NIL, outp2
380:                        .get(x_sym));
381:
382:                assertEquals("Argument 1 should be correct", list4_a_default,
383:                        outp3.get(a_sym));
384:                assertEquals("Argument 2 should be correct", list4_c_default,
385:                        outp3.get(c_sym));
386:                assertEquals("Argument 1 supplied should be correct", lisp.NIL,
387:                        outp3.get(b_sym));
388:                assertEquals("Argument 2 supplied should be correct", lisp.NIL,
389:                        outp3.get(d_sym));
390:                assertEquals("Rest argument should be correct", lisp.NIL, outp3
391:                        .get(x_sym));
392:
393:                final LispValue argList4 = lisp.makeList(arg1, arg2, arg1);
394:                final LispValue argList5 = lisp
395:                        .makeList(arg1, arg2, arg1, arg2);
396:                final LispValue argList6 = lisp.makeList(arg1, arg2, arg1)
397:                        .append(lisp.makeList(arg2, arg1));
398:                final LispValue expected4 = lisp.makeList(arg1);
399:                final LispValue expected5 = lisp.makeList(arg1, arg2);
400:                final LispValue expected6 = lisp.makeList(arg1, arg2, arg1);
401:
402:                final Map outp4 = list4.parse(argList4);
403:                final Map outp5 = list4.parse(argList5);
404:                final Map outp6 = list4.parse(argList6);
405:
406:                assertEquals("Argument 1 should be correct", arg1, outp4
407:                        .get(a_sym));
408:                assertEquals("Argument 2 should be correct", arg2, outp4
409:                        .get(c_sym));
410:                assertEquals("Argument 1 supplied should be correct", lisp.T,
411:                        outp4.get(b_sym));
412:                assertEquals("Argument 2 supplied should be correct", lisp.T,
413:                        outp4.get(d_sym));
414:                assertTrue("Rest argument should be correct", expected4
415:                        .equal((LispValue) outp4.get(x_sym)) == lisp.T);
416:
417:                assertEquals("Argument 1 should be correct", arg1, outp5
418:                        .get(a_sym));
419:                assertEquals("Argument 2 should be correct", arg2, outp5
420:                        .get(c_sym));
421:                assertEquals("Argument 1 supplied should be correct", lisp.T,
422:                        outp5.get(b_sym));
423:                assertEquals("Argument 2 supplied should be correct", lisp.T,
424:                        outp5.get(d_sym));
425:                assertTrue("Rest argument should be correct", expected5
426:                        .equal((LispValue) outp5.get(x_sym)) == lisp.T);
427:
428:                assertEquals("Argument 1 should be correct", arg1, outp6
429:                        .get(a_sym));
430:                assertEquals("Argument 2 should be correct", arg2, outp6
431:                        .get(c_sym));
432:                assertEquals("Argument 1 supplied should be correct", lisp.T,
433:                        outp6.get(b_sym));
434:                assertEquals("Argument 2 supplied should be correct", lisp.T,
435:                        outp6.get(d_sym));
436:                assertTrue("Rest argument should be correct", expected6
437:                        .equal((LispValue) outp6.get(x_sym)) == lisp.T);
438:            }
439:
440:            public void testNormalKeyParameters() {
441:                final LispValue arg1 = lisp.makeInteger(17);
442:                final LispValue arg2 = lisp.makeString("Ojsan sa");
443:                final LispValue arg3 = lisp.makeInteger(42);
444:                final LispValue arg4 = lisp.makeString("well well well");
445:
446:                final LispValue argList1 = lisp.makeList(arg1, arg2);
447:                final LispValue argList2 = lisp.makeList(arg1, arg2, c_key,
448:                        arg3);
449:                final LispValue argList3 = lisp.makeList(arg1, arg2, c_key)
450:                        .append(lisp.makeList(arg3, d_key, arg4));
451:                final LispValue argList4 = lisp.makeList(arg1, arg2, d_key)
452:                        .append(lisp.makeList(arg4, c_key, arg3));
453:
454:                final Map outp1 = list5.parse(argList1);
455:                final Map outp2 = list5.parse(argList2);
456:                final Map outp3 = list5.parse(argList3);
457:                final Map outp4 = list5.parse(argList4);
458:
459:                assertEquals("Argument 1 should be correct", arg1, outp1
460:                        .get(a_sym));
461:                assertEquals("Argument 2 should be correct", arg2, outp1
462:                        .get(b_sym));
463:                assertEquals("Argument c should be correct", lisp.NIL, outp1
464:                        .get(c_sym));
465:                assertEquals("Argument d should be correct", lisp.NIL, outp1
466:                        .get(d_sym));
467:
468:                assertEquals("Argument 1 should be correct", arg1, outp2
469:                        .get(a_sym));
470:                assertEquals("Argument 2 should be correct", arg2, outp2
471:                        .get(b_sym));
472:                assertEquals("Argument c should be correct", arg3, outp2
473:                        .get(c_sym));
474:                assertEquals("Argument d should be correct", lisp.NIL, outp2
475:                        .get(d_sym));
476:
477:                assertEquals("Argument 1 should be correct", arg1, outp3
478:                        .get(a_sym));
479:                assertEquals("Argument 2 should be correct", arg2, outp3
480:                        .get(b_sym));
481:                assertEquals("Argument c should be correct", arg3, outp3
482:                        .get(c_sym));
483:                assertEquals("Argument d should be correct", arg4, outp3
484:                        .get(d_sym));
485:
486:                assertEquals("Argument 1 should be correct", arg1, outp4
487:                        .get(a_sym));
488:                assertEquals("Argument 2 should be correct", arg2, outp4
489:                        .get(b_sym));
490:                assertEquals("Argument c should be correct", arg3, outp4
491:                        .get(c_sym));
492:                assertEquals("Argument d should be correct", arg4, outp4
493:                        .get(d_sym));
494:            }
495:
496:            public void testCombinedComplicated() {
497:                // (a &optional (b 3) &rest x &key c (d a))
498:                // arguments to test:
499:                // (17)
500:                // (17 'z)
501:                // (17 'z :c "ojsan sa")
502:                // (17 'z :c "ojsan sa" :d 42)
503:                // (17 'z :d 42 :c "ojsan sa")
504:
505:                final LispValue arg1 = lisp.makeInteger(17);
506:                final LispValue arg2 = lisp.EVAL.intern("z");
507:                final LispValue arg3 = lisp.makeString("ojsan sa");
508:                final LispValue arg4 = lisp.makeInteger(42);
509:
510:                final LispValue argList1 = lisp.makeList(arg1);
511:                final LispValue argList2 = lisp.makeList(arg1, arg2);
512:                final LispValue argList3 = lisp.makeList(arg1, arg2, c_key,
513:                        arg3);
514:                final LispValue argList4 = lisp.makeList(arg1, arg2, c_key,
515:                        arg3).append(lisp.makeList(d_key, arg4));
516:                final LispValue argList5 = lisp.makeList(arg1, arg2, d_key,
517:                        arg4).append(lisp.makeList(c_key, arg3));
518:
519:                final Map outp1 = list6.parse(argList1);
520:                final Map outp2 = list6.parse(argList2);
521:                final Map outp3 = list6.parse(argList3);
522:                final Map outp4 = list6.parse(argList4);
523:                final Map outp5 = list6.parse(argList5);
524:
525:                final LispValue expected3 = lisp.makeList(c_key, arg3);
526:                final LispValue expected4 = lisp.makeList(c_key, arg3, d_key,
527:                        arg4);
528:                final LispValue expected5 = lisp.makeList(d_key, arg4, c_key,
529:                        arg3);
530:
531:                assertEquals("Argument 1 should be correct", arg1, outp1
532:                        .get(a_sym));
533:                assertEquals("Argument 2 should be correct", list6_b_default,
534:                        outp1.get(b_sym));
535:                assertEquals("Argument x should be correct", lisp.NIL, outp1
536:                        .get(x_sym));
537:                assertEquals("Argument c should be correct", lisp.NIL, outp1
538:                        .get(c_sym));
539:                assertEquals("Argument d should be correct", arg1, outp1
540:                        .get(d_sym));
541:
542:                assertEquals("Argument 1 should be correct", arg1, outp2
543:                        .get(a_sym));
544:                assertEquals("Argument 2 should be correct", arg2, outp2
545:                        .get(b_sym));
546:                assertEquals("Argument x should be correct", lisp.NIL, outp2
547:                        .get(x_sym));
548:                assertEquals("Argument c should be correct", lisp.NIL, outp2
549:                        .get(c_sym));
550:                assertEquals("Argument d should be correct", arg1, outp2
551:                        .get(d_sym));
552:
553:                assertEquals("Argument 1 should be correct", arg1, outp3
554:                        .get(a_sym));
555:                assertEquals("Argument 2 should be correct", arg2, outp3
556:                        .get(b_sym));
557:                assertTrue("Argument x should be correct", expected3
558:                        .equal((LispValue) outp3.get(x_sym)) == lisp.T);
559:                assertEquals("Argument c should be correct", arg3, outp3
560:                        .get(c_sym));
561:                assertEquals("Argument d should be correct", arg1, outp3
562:                        .get(d_sym));
563:
564:                assertEquals("Argument 1 should be correct", arg1, outp4
565:                        .get(a_sym));
566:                assertEquals("Argument 2 should be correct", arg2, outp4
567:                        .get(b_sym));
568:                assertTrue("Argument x should be correct", expected4
569:                        .equal((LispValue) outp4.get(x_sym)) == lisp.T);
570:                assertEquals("Argument c should be correct", arg3, outp4
571:                        .get(c_sym));
572:                assertEquals("Argument d should be correct", arg4, outp4
573:                        .get(d_sym));
574:
575:                assertEquals("Argument 1 should be correct", arg1, outp5
576:                        .get(a_sym));
577:                assertEquals("Argument 2 should be correct", arg2, outp5
578:                        .get(b_sym));
579:                assertTrue("Argument x should be correct", expected5
580:                        .equal((LispValue) outp5.get(x_sym)) == lisp.T);
581:                assertEquals("Argument c should be correct", arg3, outp5
582:                        .get(c_sym));
583:                assertEquals("Argument d should be correct", arg4, outp5
584:                        .get(d_sym));
585:            }
586:
587:            public void testCombinedComplicatedAllowOtherKeys() {
588:                // (a &optional (b 3) &rest x &key c (d a) &allow-other-keys)
589:                // arguments to test:
590:                // (17)
591:                // (17 'z)
592:                // (17 'z :c "ojsan sa")
593:                // (17 'z :c "ojsan sa" :d 42)
594:                // (17 'z :d 42 :c "ojsan sa")
595:                // (17 'z :d 42 :c "ojsan sa" :testing t)
596:
597:                final LispValue arg1 = lisp.makeInteger(17);
598:                final LispValue arg2 = lisp.EVAL.intern("z");
599:                final LispValue arg3 = lisp.makeString("ojsan sa");
600:                final LispValue arg4 = lisp.makeInteger(42);
601:                final LispValue testing_key = lisp.EVAL.intern(":TESTING");
602:
603:                final LispValue argList1 = lisp.makeList(arg1);
604:                final LispValue argList2 = lisp.makeList(arg1, arg2);
605:                final LispValue argList3 = lisp.makeList(arg1, arg2, c_key,
606:                        arg3);
607:                final LispValue argList4 = lisp.makeList(arg1, arg2, c_key,
608:                        arg3).append(lisp.makeList(d_key, arg4));
609:                final LispValue argList5 = lisp.makeList(arg1, arg2, d_key,
610:                        arg4).append(lisp.makeList(c_key, arg3));
611:                final LispValue argList6 = lisp.makeList(arg1, arg2, d_key,
612:                        arg4).append(
613:                        lisp.makeList(c_key, arg3, testing_key, lisp.T));
614:
615:                final Map outp1 = list7.parse(argList1);
616:                final Map outp2 = list7.parse(argList2);
617:                final Map outp3 = list7.parse(argList3);
618:                final Map outp4 = list7.parse(argList4);
619:                final Map outp5 = list7.parse(argList5);
620:                final Map outp6 = list7.parse(argList6);
621:
622:                final LispValue expected3 = lisp.makeList(c_key, arg3);
623:                final LispValue expected4 = lisp.makeList(c_key, arg3, d_key,
624:                        arg4);
625:                final LispValue expected5 = lisp.makeList(d_key, arg4, c_key,
626:                        arg3);
627:                final LispValue expected6 = lisp.makeList(d_key, arg4, c_key,
628:                        arg3).append(lisp.makeList(testing_key, lisp.T));
629:
630:                assertEquals("Argument 1 should be correct", arg1, outp1
631:                        .get(a_sym));
632:                assertEquals("Argument 2 should be correct", list7_b_default,
633:                        outp1.get(b_sym));
634:                assertEquals("Argument x should be correct", lisp.NIL, outp1
635:                        .get(x_sym));
636:                assertEquals("Argument c should be correct", lisp.NIL, outp1
637:                        .get(c_sym));
638:                assertEquals("Argument d should be correct", arg1, outp1
639:                        .get(d_sym));
640:
641:                assertEquals("Argument 1 should be correct", arg1, outp2
642:                        .get(a_sym));
643:                assertEquals("Argument 2 should be correct", arg2, outp2
644:                        .get(b_sym));
645:                assertEquals("Argument x should be correct", lisp.NIL, outp2
646:                        .get(x_sym));
647:                assertEquals("Argument c should be correct", lisp.NIL, outp2
648:                        .get(c_sym));
649:                assertEquals("Argument d should be correct", arg1, outp2
650:                        .get(d_sym));
651:
652:                assertEquals("Argument 1 should be correct", arg1, outp3
653:                        .get(a_sym));
654:                assertEquals("Argument 2 should be correct", arg2, outp3
655:                        .get(b_sym));
656:                assertTrue("Argument x should be correct", expected3
657:                        .equal((LispValue) outp3.get(x_sym)) == lisp.T);
658:                assertEquals("Argument c should be correct", arg3, outp3
659:                        .get(c_sym));
660:                assertEquals("Argument d should be correct", arg1, outp3
661:                        .get(d_sym));
662:
663:                assertEquals("Argument 1 should be correct", arg1, outp4
664:                        .get(a_sym));
665:                assertEquals("Argument 2 should be correct", arg2, outp4
666:                        .get(b_sym));
667:                assertTrue("Argument x should be correct", expected4
668:                        .equal((LispValue) outp4.get(x_sym)) == lisp.T);
669:                assertEquals("Argument c should be correct", arg3, outp4
670:                        .get(c_sym));
671:                assertEquals("Argument d should be correct", arg4, outp4
672:                        .get(d_sym));
673:
674:                assertEquals("Argument 1 should be correct", arg1, outp5
675:                        .get(a_sym));
676:                assertEquals("Argument 2 should be correct", arg2, outp5
677:                        .get(b_sym));
678:                assertTrue("Argument x should be correct", expected5
679:                        .equal((LispValue) outp5.get(x_sym)) == lisp.T);
680:                assertEquals("Argument c should be correct", arg3, outp5
681:                        .get(c_sym));
682:                assertEquals("Argument d should be correct", arg4, outp5
683:                        .get(d_sym));
684:
685:                assertEquals("Argument 1 should be correct", arg1, outp6
686:                        .get(a_sym));
687:                assertEquals("Argument 2 should be correct", arg2, outp6
688:                        .get(b_sym));
689:                assertTrue("Argument x should be correct", expected6
690:                        .equal((LispValue) outp6.get(x_sym)) == lisp.T);
691:                assertEquals("Argument c should be correct", arg3, outp6
692:                        .get(c_sym));
693:                assertEquals("Argument d should be correct", arg4, outp6
694:                        .get(d_sym));
695:            }
696:
697:            public void testFullKey() {
698:                // (a &key ((:c int) 13 supp))
699:                // arguments to test:
700:                // (17)
701:                // (17 :c 'z)
702:                // (17 :c 13)
703:                final LispValue arg1 = lisp.makeInteger(17);
704:                final LispValue arg2 = lisp.EVAL.intern("z");
705:
706:                final LispValue argList1 = lisp.makeList(arg1);
707:                final LispValue argList2 = lisp.makeList(arg1, c_key, arg2);
708:                final LispValue argList3 = lisp.makeList(arg1, c_key,
709:                        list8_c_default);
710:
711:                final Map outp1 = list8.parse(argList1);
712:                final Map outp2 = list8.parse(argList2);
713:                final Map outp3 = list8.parse(argList3);
714:
715:                assertEquals("Argument 1 should be correct", arg1, outp1
716:                        .get(a_sym));
717:                assertEquals("Argument 2 should be correct", list8_c_default,
718:                        outp1.get(int_sym));
719:                assertEquals("Supplied2 should be correct", lisp.NIL, outp1
720:                        .get(supp_sym));
721:
722:                assertEquals("Argument 1 should be correct", arg1, outp2
723:                        .get(a_sym));
724:                assertEquals("Argument 2 should be correct", arg2, outp2
725:                        .get(int_sym));
726:                assertEquals("Supplied2 should be correct", lisp.T, outp2
727:                        .get(supp_sym));
728:
729:                assertEquals("Argument 1 should be correct", arg1, outp3
730:                        .get(a_sym));
731:                assertEquals("Argument 2 should be correct", list8_c_default,
732:                        outp3.get(int_sym));
733:                assertEquals("Supplied2 should be correct", lisp.T, outp3
734:                        .get(supp_sym));
735:            }
736:
737:            public void testSupplyAllowOtherKeys() {
738:                // (a &key ((:c int) 13 supp))
739:                // arguments to test:
740:                // (17 :c 3 :allow-other-keys t :start 14)
741:                // (17 :c 3 :start 14 :allow-other-keys t)
742:                final LispValue arg1 = lisp.makeInteger(17);
743:                final LispValue arg2 = lisp.makeInteger(3);
744:                final LispValue all_ = lisp.EVAL.intern(":ALLOW-OTHER-KEYS");
745:                final LispValue start_ = lisp.EVAL.intern(":START");
746:                final LispValue start_arg = lisp.makeInteger(14);
747:
748:                final LispValue argList1 = lisp.makeList(arg1, c_key, arg2,
749:                        all_).append(lisp.makeList(lisp.T, start_, start_arg));
750:                final LispValue argList2 = lisp.makeList(arg1, c_key, arg2,
751:                        start_).append(lisp.makeList(start_arg, all_, lisp.T));
752:
753:                final Map outp1 = list8.parse(argList1);
754:                final Map outp2 = list8.parse(argList2);
755:
756:                assertEquals("Argument 1 should be correct", arg1, outp1
757:                        .get(a_sym));
758:                assertEquals("Argument 2 should be correct", arg2, outp1
759:                        .get(int_sym));
760:                assertEquals("Supplied2 should be correct", lisp.T, outp1
761:                        .get(supp_sym));
762:
763:                assertEquals("Argument 1 should be correct", arg1, outp2
764:                        .get(a_sym));
765:                assertEquals("Argument 2 should be correct", arg2, outp2
766:                        .get(int_sym));
767:                assertEquals("Supplied2 should be correct", lisp.T, outp2
768:                        .get(supp_sym));
769:            }
770:
771:            public void testAuxArgument() {
772:                final Map outp = list9.parse(lisp.NIL);
773:                assertEquals("Aux argument should be correct", lisp
774:                        .makeInteger(13).toStringSimple(), ((LispValue) outp
775:                        .get(a_sym)).toStringSimple());
776:            }
777:        }// ArgumentTest
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.