Source Code Cross Referenced for ReducedModelTest.java in  » IDE » DrJava » edu » rice » cs » drjava » model » definitions » reducedmodel » 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 » IDE » DrJava » edu.rice.cs.drjava.model.definitions.reducedmodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*BEGIN_COPYRIGHT_BLOCK
0002:         *
0003:         * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
0004:         * All rights reserved.
0005:         * 
0006:         * Redistribution and use in source and binary forms, with or without
0007:         * modification, are permitted provided that the following conditions are met:
0008:         *    * Redistributions of source code must retain the above copyright
0009:         *      notice, this list of conditions and the following disclaimer.
0010:         *    * Redistributions in binary form must reproduce the above copyright
0011:         *      notice, this list of conditions and the following disclaimer in the
0012:         *      documentation and/or other materials provided with the distribution.
0013:         *    * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
0014:         *      names of its contributors may be used to endorse or promote products
0015:         *      derived from this software without specific prior written permission.
0016:         * 
0017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0018:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0019:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0020:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0021:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0022:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0023:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0024:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0025:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0026:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0027:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0028:         *
0029:         * This software is Open Source Initiative approved Open Source Software.
0030:         * Open Source Initative Approved is a trademark of the Open Source Initiative.
0031:         * 
0032:         * This file is part of DrJava.  Download the current version of this project
0033:         * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
0034:         * 
0035:         * END_COPYRIGHT_BLOCK*/
0036:
0037:        package edu.rice.cs.drjava.model.definitions.reducedmodel;
0038:
0039:        /** Tests insertion and move and other non-delete functionality of the reduced model.
0040:         * @version $Id: ReducedModelTest.java 4255 2007-08-28 19:17:37Z mgricken $
0041:         */
0042:        public final class ReducedModelTest extends BraceReductionTestCase
0043:                implements  ReducedModelStates {
0044:            /** Put your documentation comment here. */
0045:            public void testInsertGap() {
0046:                insertGap(model1, 4);
0047:                model1.move(-4);
0048:                //checks to make sure it is a gap
0049:                assertTrue("#0.0", model1.currentToken().isGap());
0050:                assertEquals("#0.2", 4, model1.currentToken().getSize());
0051:                model1.move(4);
0052:                //inserts another gap after the afor mentioned gap
0053:                insertGap(model2, 5);
0054:                model2.move(-5);
0055:                //makes sure they united to form an Uber gap.
0056:                assertTrue("#1.0", model2.currentToken().isGap());
0057:                assertEquals("#1.2", 5, model2.currentToken().getSize());
0058:            }
0059:
0060:            /** Test that a gap inserted previous to a gap, unites with that gap. */
0061:            public void testInsertGapBeforeGap() {
0062:                insertGap(model1, 3);
0063:                assertTrue("#0.0.0", model1.atEnd());
0064:                model1.move(-3);
0065:                insertGap(model1, 3);
0066:                //insert two consecutive gaps and make sure they combine.
0067:                assertTrue("#0.0", model1.currentToken().isGap());
0068:                assertEquals("#0.1", 3, model1.absOffset());
0069:                assertEquals("#0.2", 6, model1.currentToken().getSize());
0070:                model1.move(-3);
0071:                insertGap(model1, 2);
0072:                assertTrue("#1.0", model1.currentToken().isGap());
0073:                assertEquals("#1.1", 2, model1.absOffset());
0074:                assertEquals("#1.2", 8, model1.currentToken().getSize());
0075:            }
0076:
0077:            /** Put your documentation comment here. */
0078:            public void testInsertGapAfterGap() {
0079:                insertGap(model1, 3);
0080:                assertTrue("#0.0", model1.atEnd());
0081:                model1.move(-3);
0082:                assertTrue("#0.1", model1.currentToken().isGap());
0083:                assertEquals("#0.2", 3, model1.currentToken().getSize());
0084:                insertGap(model1, 4);
0085:                assertTrue("#1.1", model1.currentToken().isGap());
0086:                assertEquals("#1.2", 7, model1.currentToken().getSize());
0087:            }
0088:
0089:            /** Inserts one gap inside of the other. */
0090:            public void testInsertGapInsideGap() {
0091:                insertGap(model1, 3);
0092:                assertTrue("#0.0", model1.atEnd());
0093:                model1.move(-3);
0094:                assertTrue("#0.1", model1.currentToken().isGap());
0095:                assertEquals("#0.2", 3, model1.currentToken().getSize());
0096:                insertGap(model1, 3);
0097:                assertTrue("#1.1", model1.currentToken().isGap());
0098:                assertEquals("#1.2", 6, model1.currentToken().getSize());
0099:                assertEquals("#1.3", 3, model1.absOffset());
0100:                insertGap(model1, 4);
0101:                assertTrue("#1.1", model1.currentToken().isGap());
0102:                assertEquals("#1.2", 10, model1.currentToken().getSize());
0103:                assertEquals("#1.3", 7, model1._offset);
0104:            }
0105:
0106:            /** Put your documentation comment here. */
0107:            public void testInsertBraceAtStartAndEnd() {
0108:                model1.insertChar('(');
0109:                assertTrue("#0.0", model1.atEnd());
0110:                model1.move(-1);
0111:                assertEquals("#0.1", "(", model1.currentToken().getType());
0112:                assertEquals("#0.2", 1, model1.currentToken().getSize());
0113:                model2.insertChar(')');
0114:                assertTrue("#1.0", model2.atEnd());
0115:                model2.move(-1);
0116:                assertEquals("#1.1", ")", model2.currentToken().getType());
0117:                assertEquals("#1.2", 1, model2.currentToken().getSize());
0118:            }
0119:
0120:            //**************
0121:            public void testInsertBraceInsideGap() {
0122:                insertGap(model1, 4);
0123:                model1.move(-4);
0124:                insertGap(model1, 3);
0125:                assertEquals("#0.0", 3, model1.absOffset());
0126:                assertEquals("#0.1", 7, model1.currentToken().getSize());
0127:                model1.insertChar('{');
0128:                assertEquals("#1.0", 4, model1.absOffset());
0129:                assertEquals("#1.1", 4, model1.currentToken().getSize());
0130:                assertTrue("#1.2", model1.currentToken().isGap());
0131:                model1.move(-1);
0132:                assertEquals("#2.0", 1, model1.currentToken().getSize());
0133:                assertEquals("#2.1", "{", model1.currentToken().getType());
0134:                model1.move(-3);
0135:                assertEquals("#3.0", 0, model1.absOffset());
0136:                assertEquals("#3.1", 3, model1.currentToken().getSize());
0137:                assertTrue("#3.2", model1.currentToken().isGap());
0138:            }
0139:
0140:            /**
0141:             * put your documentation comment here
0142:             */
0143:            public void testInsertBrace() {
0144:                model1.insertChar('{');
0145:                assertTrue("#0.0", model1.atEnd());
0146:                model1.move(-1);
0147:                assertEquals("#1.0", 1, model1.currentToken().getSize());
0148:                assertEquals("#1.1", "{", model1.currentToken().getType());
0149:                model1.insertChar('(');
0150:                model1.insertChar('[');
0151:                assertEquals("#2.0", 1, model1.currentToken().getSize());
0152:                assertEquals("#2.1", "{", model1.currentToken().getType());
0153:                model1.move(-1);
0154:                assertEquals("#3.0", 1, model1.currentToken().getSize());
0155:                assertEquals("#3.1", "[", model1.currentToken().getType());
0156:                model1.move(-1);
0157:                assertEquals("#3.0", 1, model1.currentToken().getSize());
0158:                assertEquals("#3.1", "(", model1.currentToken().getType());
0159:            }
0160:
0161:            /**
0162:             * put your documentation comment here
0163:             */
0164:            public void testInsertBraceAndBreakLineComment() {
0165:                model1.insertChar('/');
0166:                model1.insertChar('/');
0167:                model1.move(-1);
0168:                assertEquals("#0.0", 2, model1.currentToken().getSize());
0169:                //move to the middle of the // and break it with a {
0170:                model1.insertChar('{');
0171:                assertEquals("#1.0", "/", model1.currentToken().getType());
0172:                assertEquals("#1.1", 1, model1.currentToken().getSize());
0173:                model1.move(-1);
0174:                assertEquals("#2.0", "{", model1.currentToken().getType());
0175:                assertEquals("#2.1", 1, model1.currentToken().getSize());
0176:                model1.move(-1);
0177:                assertEquals("#3.0", "/", model1.currentToken().getType());
0178:                assertEquals("#3.1", 1, model1.currentToken().getSize());
0179:            }
0180:
0181:            /**
0182:             * Tests the reduced model's ability to insert braces correctly
0183:             */
0184:            public void testInsertBraceAndBreakBlockCommentStart() {
0185:                model1.insertChar('/');
0186:                model1.insertChar('*');
0187:                model1.move(-2);
0188:                assertEquals("#0.0", 2, model1.currentToken().getSize());
0189:                model1.move(1);
0190:                model1.insertChar('{');
0191:                assertEquals("#1.0", "*", model1.currentToken().getType());
0192:                assertEquals("#1.1", 1, model1.currentToken().getSize());
0193:                model1.move(-1);
0194:                assertEquals("#2.0", "{", model1.currentToken().getType());
0195:                assertEquals("#2.1", 1, model1.currentToken().getSize());
0196:                model1.move(-1);
0197:                assertEquals("#3.0", "/", model1.currentToken().getType());
0198:                assertEquals("#3.1", 1, model1.currentToken().getSize());
0199:            }
0200:
0201:            //**************************
0202:            public void testInsertMultipleBraces() {
0203:                model1.insertChar('/');
0204:                model1.insertChar('*');
0205:                model1.insertChar('{');
0206:                model1.move(-1);
0207:                // /*#{
0208:                assertEquals("#0.0", INSIDE_BLOCK_COMMENT, model1
0209:                        .getStateAtCurrent());
0210:                model1.move(-2);
0211:                assertEquals("#0.1", FREE, model1.currentToken().getState());
0212:                model1.move(3);
0213:                model1.insertChar('*');
0214:                model1.insertChar('/');
0215:                // /*{*/#
0216:                model1.move(-2);
0217:                assertEquals("#1.0", FREE, model1.currentToken().getState());
0218:                model1.move(1);
0219:                model1.insertChar('{');
0220:                model1.move(0);
0221:                // /*{*{#/
0222:                model1.move(-1);
0223:                assertEquals("#2.0", INSIDE_BLOCK_COMMENT, model1
0224:                        .currentToken().getState());
0225:                assertEquals("#2.1", INSIDE_BLOCK_COMMENT, model1
0226:                        .currentToken().getState());
0227:                model1.move(1);
0228:                assertEquals("#2.2", "/", model1.currentToken().getType());
0229:            }
0230:
0231:            /**
0232:             * Test to ensure that a complex sequence of multi-lined Brace entries does not fail.
0233:             * Originally, the insertBraceInGap() had the chance of inserting at the beginning
0234:             * of a gap, in which case the gap to be split was actually never shrunk and a new
0235:             * gap of size 0 is added after the newly inserted Brace. This caused problems for
0236:             * brace-matching when new nested braces/parentheses piled up on top of each other.
0237:             */
0238:            public void testComplexBraceInsertion() {
0239:                model1.insertChar('\n');
0240:                model1.insertChar('\n');
0241:                model1.move(-1);
0242:                // \n#\n
0243:                assertEquals("#0.0", false, model1.atEnd());
0244:                model1.insertChar('{');
0245:                model1.insertChar('\n');
0246:                model1.insertChar('\n');
0247:                model1.insertChar('}');
0248:                model1.move(-2);
0249:                // \n{\n#\n}\n
0250:                assertEquals("#0.1", FREE, model1.currentToken().getState());
0251:                model1.insertChar('{');
0252:                model1.insertChar('{');
0253:                model1.insertChar('}');
0254:                model1.insertChar('}');
0255:                // \n{\n{{}}#\n}\n
0256:                assertEquals("#1.0", 4, model1.balanceBackward());
0257:                model1.move(-1);
0258:                assertEquals("#1.1", 2, model1.balanceBackward());
0259:            }
0260:
0261:            /**
0262:             * put your documentation comment here
0263:             */
0264:            public void testCrazyCase1() {
0265:                model1.insertChar('/');
0266:                insertGap(model1, 4);
0267:                model1.insertChar('*');
0268:                model1.insertChar('/');
0269:                //should not form an end block comment
0270:                model1.move(-1);
0271:                assertEquals("#0.0", "/", model1.currentToken().getType());
0272:                model1.move(-1);
0273:                assertEquals("#0.1", "*", model1.currentToken().getType());
0274:                // /____#*/
0275:                model1.move(1);
0276:                model1.insertChar('/');
0277:                // /____*/#/
0278:                assertEquals("#1.0", 2, model1.currentToken().getSize());
0279:                model1.move(-2);
0280:                // /____#*//
0281:                assertEquals("#1.0", "*", model1.currentToken().getType());
0282:                model1.move(-4);
0283:                model1.insertChar('*');
0284:                // /*#____*//
0285:                model1.move(-2);
0286:                assertEquals("#2.0", "/*", model1.currentToken().getType());
0287:                assertEquals("#2.1", FREE, model1.currentToken().getState());
0288:                model1.move(6);
0289:                // /*____#*//
0290:                assertEquals("#2.2", "*/", model1.currentToken().getType());
0291:                assertEquals("#2.3", FREE, model1.currentToken().getState());
0292:                assertEquals("#2.4", INSIDE_BLOCK_COMMENT, model1
0293:                        .getStateAtCurrent());
0294:                // /*____#*//
0295:            }
0296:
0297:            /**Test sequences of inserts*/
0298:            public void testCrazyCase2() {
0299:                model1.insertChar('/');
0300:                insertGap(model1, 4);
0301:                model1.move(-2);
0302:                model1.insertChar('/');
0303:                model1.move(0);
0304:                model1.move(-3);
0305:                //check that double slash works.
0306:                assertEquals("#0.0", 2, model1.currentToken().getSize());
0307:                assertEquals("#0.3", FREE, model1.getStateAtCurrent());
0308:                model1.move(2);
0309:                assertEquals("#0.2", 1, model1.currentToken().getSize());
0310:                assertEquals("#0.1", "/", model1.currentToken().getType());
0311:                model1.move(-2);
0312:                model1.insertChar('/');
0313:                model1.move(-2);
0314:                assertEquals("#1.1", "//", model1.currentToken().getType());
0315:                assertEquals("#1.3", FREE, model1.currentToken().getState());
0316:                model1.move(2);
0317:                // //#__/__
0318:                assertEquals("#1.2", INSIDE_LINE_COMMENT, model1
0319:                        .getStateAtCurrent());
0320:                assertEquals("1.4", INSIDE_LINE_COMMENT, model1.currentToken()
0321:                        .getState());
0322:                model1.move(2);
0323:                assertEquals("1.5", INSIDE_LINE_COMMENT, model1.currentToken()
0324:                        .getState());
0325:                model1.move(-2);
0326:            }
0327:
0328:            /**
0329:             * put your documentation comment here
0330:             */
0331:            public void testLineCommentBreakCrazy() {
0332:                model1.insertChar('/');
0333:                model1.insertChar('/');
0334:                insertGap(model1, 4);
0335:                model1.move(-2);
0336:                model1.insertChar('/');
0337:                // //#__/__
0338:                //break line comment simultaneously forming a new line comment
0339:                model1.move(-4);
0340:                model1.insertChar('/');
0341:                model1.move(0);
0342:                // //#/__/__
0343:                model1.move(-2);
0344:                assertEquals("#2.0", "//", model1.currentToken().getType());
0345:                assertEquals("#2.3", FREE, model1.currentToken().getState());
0346:                model1.move(2);
0347:                assertEquals("#2.1", "/", model1.currentToken().getType());
0348:                assertEquals("#2.2", INSIDE_LINE_COMMENT, model1
0349:                        .getStateAtCurrent());
0350:                assertEquals("2.4", INSIDE_LINE_COMMENT, model1.currentToken()
0351:                        .getState());
0352:                model1.move(1);
0353:                assertEquals("2.5", INSIDE_LINE_COMMENT, model1.currentToken()
0354:                        .getState());
0355:                //break line comment forming a block comment
0356:                model1.move(-2);
0357:                model1.insertChar('*'); //  ///__/__
0358:                model1.move(0);
0359:                // /*#//__/__
0360:                model1.move(-2);
0361:                assertEquals("#3.0", "/*", model1.currentToken().getType());
0362:                assertEquals("#3.3", FREE, model1.currentToken().getState());
0363:                model1.move(2);
0364:                assertEquals("#3.1", "/", model1.currentToken().getType());
0365:                assertEquals("#3.3", INSIDE_BLOCK_COMMENT, model1
0366:                        .getStateAtCurrent());
0367:                assertEquals("3.4", INSIDE_BLOCK_COMMENT, model1.currentToken()
0368:                        .getState());
0369:                model1.move(1);
0370:                assertEquals("#3.2", "/", model1.currentToken().getType());
0371:                assertEquals("3.5", INSIDE_BLOCK_COMMENT, model1.currentToken()
0372:                        .getState());
0373:            }
0374:
0375:            /**
0376:             * put your documentation comment here
0377:             */
0378:            public void testBreakBlockCommentWithStar() {
0379:                // /*#//__/__
0380:                model1.insertChar('/');
0381:                model1.insertChar('*');
0382:                model1.insertChar('/');
0383:                model1.insertChar('/');
0384:                insertGap(model1, 2);
0385:                model1.insertChar('/');
0386:                insertGap(model1, 2);
0387:                //break block comment start with a star.
0388:                model1.move(-8);
0389:                model1.insertChar('*');
0390:                // /*#*//__/__
0391:                model1.move(-2);
0392:                assertEquals("#4.0", "/*", model1.currentToken().getType());
0393:                assertEquals("#4.3", FREE, model1.currentToken().getState());
0394:                model1.move(2);
0395:                assertEquals("#4.1", "*/", model1.currentToken().getType());
0396:                assertEquals("#4.3", INSIDE_BLOCK_COMMENT, model1
0397:                        .getStateAtCurrent());
0398:                assertEquals("4.4", FREE, model1.currentToken().getState());
0399:                model1.move(2);
0400:                assertEquals("#4.2", "/", model1.currentToken().getType());
0401:                assertEquals("4.5", FREE, model1.currentToken().getState());
0402:            }
0403:
0404:            /**
0405:             * put your documentation comment here
0406:             */
0407:            public void testBreakCloseBlockCommentWithStar() {
0408:                model1.insertChar('/');
0409:                model1.insertChar('*');
0410:                model1.insertChar('*');
0411:                model1.insertChar('/');
0412:                model1.insertChar('/');
0413:                insertGap(model1, 2);
0414:                model1.insertChar('/');
0415:                insertGap(model1, 2);
0416:                model1.move(-7);
0417:                insertGap(model1, 3);
0418:                // /**___#//__/__
0419:                model1.move(-3);
0420:                assertEquals("#5.0", true, model1.currentToken().isGap());
0421:                assertEquals("#5.4", INSIDE_BLOCK_COMMENT, model1
0422:                        .currentToken().getState());
0423:                model1.move(3);
0424:                assertEquals("#5.1", INSIDE_BLOCK_COMMENT, model1
0425:                        .getStateAtCurrent());
0426:                assertEquals("#5.2", "/", model1.currentToken().getType());
0427:                assertEquals("5.5", INSIDE_BLOCK_COMMENT, model1.currentToken()
0428:                        .getState());
0429:                model1.move(1);
0430:                assertEquals("#5.3", "/", model1.currentToken().getType());
0431:                assertEquals("5.6", INSIDE_BLOCK_COMMENT, model1.currentToken()
0432:                        .getState());
0433:            }
0434:
0435:            /**
0436:             * put your documentation comment here
0437:             */
0438:            public void testBasicBlockComment() {
0439:                model1.insertChar('/');
0440:                model1.insertChar('*');
0441:                model1.insertChar('*');
0442:                model1.insertChar('/');
0443:                model1.move(-4);
0444:                assertEquals("0.1", FREE, model1.currentToken().getState());
0445:                assertEquals("0.2", "/*", model1.currentToken().getType());
0446:                model1.move(2);
0447:                assertEquals("0.3", FREE, model1.currentToken().getState());
0448:                assertEquals("0.4", "*/", model1.currentToken().getType());
0449:                model1.insertChar('/');
0450:                model1.move(-1);
0451:                assertEquals("1.1", INSIDE_BLOCK_COMMENT, model1.currentToken()
0452:                        .getState());
0453:                assertEquals("1.3", "/", model1.currentToken().getType());
0454:                model1.move(1);
0455:                assertEquals("1.0", FREE, model1.currentToken().getState());
0456:                assertEquals("1.2", "*/", model1.currentToken().getType());
0457:            }
0458:
0459:            /**
0460:             * put your documentation comment here
0461:             */
0462:            public void testInsertBlockInsideBlockComment() {
0463:                model1.insertChar('/');
0464:                model1.insertChar('*');
0465:                model1.insertChar('/');
0466:                model1.insertChar('*');
0467:                model1.insertChar('/');
0468:                ///*/*/#
0469:                model1.move(-2);
0470:                model1.insertChar('*');
0471:                ///*/*#*/
0472:                model1.move(-1);
0473:                assertEquals("1.1", INSIDE_BLOCK_COMMENT, model1.currentToken()
0474:                        .getState());
0475:                assertEquals("1.3", "*", model1.currentToken().getType());
0476:                model1.move(1);
0477:                assertEquals("1.0", FREE, model1.currentToken().getState());
0478:                assertEquals("1.2", "*/", model1.currentToken().getType());
0479:            }
0480:
0481:            /**
0482:             * put your documentation comment here
0483:             */
0484:            public void testInsertBlockCommentEnd() { // should not form an end without a start.
0485:                model1.insertChar('*');
0486:                model1.insertChar('/');
0487:                model1.move(-1);
0488:                assertEquals("#3.0", "/", model1.currentToken().getType());
0489:                assertEquals("#3.1", 1, model1.currentToken().getSize());
0490:            }
0491:
0492:            /**
0493:             * put your documentation comment here
0494:             */
0495:            public void testGetStateAtCurrent() {
0496:                assertEquals("#0.0", FREE, model1.getStateAtCurrent());
0497:                assertEquals("#0.1", FREE, model1.getStateAtCurrent());
0498:                model1.insertChar('(');
0499:                model1.move(-1);
0500:                assertEquals("#1.0", FREE, model1.currentToken().getState());
0501:                model1.move(1);
0502:                model1.insertChar('/');
0503:                model1.insertChar('/');
0504:                model1.move(-2);
0505:                assertEquals("#2.0", FREE, model1.currentToken().getState());
0506:                model1.move(2);
0507:                assertEquals("#2.1", INSIDE_LINE_COMMENT, model1
0508:                        .getStateAtCurrent());
0509:                // {//#
0510:                model1.move(-3);
0511:                model1.insertChar('/');
0512:                model1.insertChar('/');
0513:                // //#{//
0514:                model1.move(-2);
0515:                assertEquals("#3.0", FREE, model1.currentToken().getState());
0516:                model1.move(2);
0517:                assertEquals("#3.1", INSIDE_LINE_COMMENT, model1
0518:                        .getStateAtCurrent());
0519:                assertEquals("#3.2", INSIDE_LINE_COMMENT, model1.currentToken()
0520:                        .getState());
0521:                model1.move(1);
0522:                assertEquals("#3.3", INSIDE_LINE_COMMENT, model1.currentToken()
0523:                        .getState());
0524:                assertEquals("#3.4", "/", model1.currentToken().getType());
0525:                model1.move(1);
0526:                assertEquals("#4.1", INSIDE_LINE_COMMENT, model1.currentToken()
0527:                        .getState());
0528:                assertEquals("#4.2", "/", model1.currentToken().getType());
0529:            }
0530:
0531:            /**
0532:             * put your documentation comment here
0533:             */
0534:            public void testQuotesSimple() {
0535:                model1.insertChar('\"');
0536:                model1.insertChar('\"');
0537:                model1.move(-2);
0538:                assertEquals("#0.0", "\"", model1.currentToken().getType());
0539:                assertEquals("#0.3", FREE, model1.currentToken().getState());
0540:                model1.move(1);
0541:                assertEquals("#0.1", "\"", model1.currentToken().getType());
0542:                assertEquals("#0.2", FREE, model1.currentToken().getState());
0543:                assertEquals("#0.4", INSIDE_DOUBLE_QUOTE, model1
0544:                        .getStateAtCurrent());
0545:            }
0546:
0547:            /**
0548:             * put your documentation comment here
0549:             */
0550:            public void testQuotesWithGap() {
0551:                model1.insertChar('\"');
0552:                model1.insertChar('\"');
0553:                model1.move(-2);
0554:                assertEquals("#0.1", "\"", model1.currentToken().getType());
0555:                assertEquals("#0.3", FREE, model1.currentToken().getState());
0556:                model1.move(1);
0557:                assertEquals("#0.0", "\"", model1.currentToken().getType());
0558:                assertEquals("#0.2", FREE, model1.currentToken().getState());
0559:                assertEquals("#0.4", INSIDE_DOUBLE_QUOTE, model1
0560:                        .getStateAtCurrent());
0561:                insertGap(model1, 4);
0562:                // "____#"
0563:                model1.move(-4);
0564:                assertEquals("#1.1", true, model1.currentToken().isGap());
0565:                assertEquals("#1.3", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0566:                        .getState());
0567:                model1.move(4);
0568:                assertEquals("#1.0", "\"", model1.currentToken().getType());
0569:                assertEquals("#1.2", FREE, model1.currentToken().getState());
0570:                assertEquals("#1.4", INSIDE_DOUBLE_QUOTE, model1
0571:                        .getStateAtCurrent());
0572:                model1.move(-2);
0573:                model1.insertChar('/');
0574:                // "__/__"
0575:                model1.move(-1);
0576:                assertEquals("#2.1", "/", model1.currentToken().getType());
0577:                model1.move(1);
0578:                assertEquals("#2.0", true, model1.currentToken().isGap());
0579:                assertEquals("#2.4", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0580:                        .getState());
0581:                assertEquals("#2.6", INSIDE_DOUBLE_QUOTE, model1
0582:                        .getStateAtCurrent());
0583:                model1.move(2);
0584:                assertEquals("#2.2", "\"", model1.currentToken().getType());
0585:                assertEquals("#2.3", FREE, model1.currentToken().getState());
0586:            }
0587:
0588:            /**
0589:             * put your documentation comment here
0590:             */
0591:            public void testInsertQuoteToQuoteBlock() {
0592:                model1.insertChar('\"');
0593:                insertGap(model1, 2);
0594:                model1.insertChar('/');
0595:                insertGap(model1, 2);
0596:                model1.insertChar('\"');
0597:                model1.move(-3);
0598:                model1.insertChar('\"');
0599:                // "__/"#__"
0600:                model1.move(-1);
0601:                assertEquals("#3.1", "\"", model1.currentToken().getType());
0602:                assertEquals("#3.5", FREE, model1.currentToken().getState());
0603:                model1.move(1);
0604:                assertEquals("#3.0", true, model1.currentToken().isGap());
0605:                assertEquals("#3.4", FREE, model1.currentToken().getState());
0606:                assertEquals("#3.6", FREE, model1.getStateAtCurrent());
0607:                model1.move(2);
0608:                assertEquals("#3.2", "\"", model1.currentToken().getType());
0609:                assertEquals("#3.3", FREE, model1.currentToken().getState());
0610:                // "__/"__"
0611:                model1.move(-6);
0612:                assertEquals("#4.1", true, model1.currentToken().isGap());
0613:                assertEquals("#4.5", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0614:                        .getState());
0615:                model1.move(2);
0616:                assertEquals("#4.0", "/", model1.currentToken().getType());
0617:                assertEquals("#4.4", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0618:                        .getState());
0619:                assertEquals("#4.6", INSIDE_DOUBLE_QUOTE, model1
0620:                        .getStateAtCurrent());
0621:                model1.move(1);
0622:                assertEquals("#4.2", "\"", model1.currentToken().getType());
0623:                assertEquals("#4.3", FREE, model1.currentToken().getState());
0624:                model1.move(-1);
0625:                // "__/#"__"
0626:                //break quote with newline
0627:                model1.insertChar('\n');
0628:                // "__\n#/"__"
0629:                model1.move(-1);
0630:                assertEquals("#5.5", FREE, model1.currentToken().getState());
0631:                model1.move(1);
0632:                assertEquals("#5.4", FREE, model1.currentToken().getState());
0633:                assertEquals("#5.6", FREE, model1.getStateAtCurrent());
0634:                model1.move(1);
0635:                assertEquals("#5.3", FREE, model1.currentToken().getState());
0636:                model1.move(1);
0637:                assertEquals("#5.7", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0638:                        .getState());
0639:                assertEquals("#5.8", true, model1.currentToken().isGap());
0640:            }
0641:
0642:            /**
0643:             * put your documentation comment here
0644:             */
0645:            public void testQuoteBreaksComment() {
0646:                model1.insertChar('/');
0647:                model1.insertChar('*');
0648:                model1.insertChar('*');
0649:                model1.insertChar('/');
0650:                model1.move(-2);
0651:                model1.insertChar('\"');
0652:                model1.move(-1);
0653:                // /*#"*/
0654:                model1.move(-2);
0655:                assertEquals("#1.1", FREE, model1.currentToken().getState());
0656:                model1.move(2);
0657:                assertEquals("#1.1", INSIDE_BLOCK_COMMENT, model1
0658:                        .getStateAtCurrent());
0659:                assertEquals("#1.2", INSIDE_BLOCK_COMMENT, model1
0660:                        .currentToken().getState());
0661:                model1.move(1);
0662:                assertEquals("#1.2", FREE, model1.currentToken().getState());
0663:                model1.move(-3);
0664:                // #/*"*/
0665:                model1.insertChar('\"');
0666:                model1.move(-1);
0667:                assertEquals("#2.2", FREE, model1.currentToken().getState());
0668:                model1.move(1);
0669:                assertEquals("#2.0", INSIDE_DOUBLE_QUOTE, model1
0670:                        .getStateAtCurrent());
0671:                assertEquals("#2.1", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0672:                        .getState());
0673:                assertEquals("#2.3", "/", model1.currentToken().getType());
0674:                model1.move(1);
0675:                assertEquals("#2.4", "*", model1.currentToken().getType());
0676:                // "/#*"*/
0677:                model1.move(2);
0678:                // "/*"#*/
0679:                assertEquals("#5.0", FREE, model1.getStateAtCurrent());
0680:                assertEquals("#5.1", FREE, model1.currentToken().getState());
0681:                assertEquals("#5.3", "*", model1.currentToken().getType());
0682:                model1.move(1);
0683:                assertEquals("#5.4", "/", model1.currentToken().getType());
0684:                assertEquals("#5.5", FREE, model1.currentToken().getState());
0685:            }
0686:
0687:            /**
0688:             * put your documentation comment here
0689:             */
0690:            public void testQuoteBreakComment2() {
0691:                model1.insertChar('/');
0692:                model1.insertChar('*');
0693:                model1.insertChar('*');
0694:                model1.insertChar('/');
0695:                model1.move(-4);
0696:                assertEquals("#0.0", "/*", model1.currentToken().getType());
0697:                model1.move(2);
0698:                assertEquals("#0.1", "*/", model1.currentToken().getType());
0699:                model1.move(-2);
0700:                // "#/**/
0701:                model1.insertChar('\"');
0702:                model1.move(-1);
0703:                assertEquals("#1.0", FREE, model1.currentToken().getState());
0704:                assertEquals("#1.4", "\"", model1.currentToken().getType());
0705:                model1.move(1);
0706:                assertEquals("#1.1", INSIDE_DOUBLE_QUOTE, model1
0707:                        .getStateAtCurrent());
0708:                assertEquals("#1.4", "/", model1.currentToken().getType());
0709:                assertEquals("#1.2", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0710:                        .getState());
0711:                model1.move(1);
0712:                assertEquals("#1.3", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0713:                        .getState());
0714:                assertEquals("#1.4", "*", model1.currentToken().getType());
0715:            }
0716:
0717:            /**
0718:             * put your documentation comment here
0719:             */
0720:            public void testInsertNewlineEndLineComment() {
0721:                model1.insertChar('/');
0722:                model1.insertChar('/');
0723:                insertGap(model1, 5);
0724:                model1.move(-2);
0725:                model1.insertChar('\n');
0726:                // //___\n#__
0727:                model1.move(-1);
0728:                assertEquals("#0.2", "\n", model1.currentToken().getType());
0729:                assertEquals("#0.4", FREE, model1.currentToken().getState());
0730:                model1.move(1);
0731:                assertEquals("#0.0", FREE, model1.getStateAtCurrent());
0732:                assertTrue("#0.1", model1.currentToken().isGap());
0733:                assertEquals("#0.3", 2, model1.currentToken().getSize());
0734:                assertEquals("#0.5", FREE, model1.currentToken().getState());
0735:            }
0736:
0737:            /**
0738:             * put your documentation comment here
0739:             */
0740:            public void testInsertNewlineEndQuote() {
0741:                model1.insertChar('\"');
0742:                insertGap(model1, 5);
0743:                model1.move(-2);
0744:                model1.insertChar('\n');
0745:                // "___\n#__
0746:                model1.move(-1);
0747:                assertEquals("#0.4", FREE, model1.currentToken().getState());
0748:                assertEquals("#0.2", "\n", model1.currentToken().getType());
0749:                model1.move(1);
0750:                assertEquals("#0.0", FREE, model1.getStateAtCurrent());
0751:                assertTrue("#0.1", model1.currentToken().isGap());
0752:                assertEquals("#0.3", 2, model1.currentToken().getSize());
0753:                assertEquals("#0.5", FREE, model1.currentToken().getState());
0754:            }
0755:
0756:            /**
0757:             * put your documentation comment here
0758:             */
0759:            public void testInsertNewlineChainReaction() {
0760:                model1.insertChar('/');
0761:                model1.insertChar('/');
0762:                model1.insertChar('/');
0763:                model1.insertChar('*');
0764:                // ///*#
0765:                model1.move(-1);
0766:                // ///#*
0767:                model1.move(-1);
0768:                assertEquals("#0.2", "/", model1.currentToken().getType());
0769:                assertEquals("#0.3", INSIDE_LINE_COMMENT, model1.currentToken()
0770:                        .getState());
0771:                model1.move(1);
0772:                assertEquals("#0.0", INSIDE_LINE_COMMENT, model1
0773:                        .getStateAtCurrent());
0774:                assertEquals("#0.1", "*", model1.currentToken().getType());
0775:                assertEquals("#0.4", INSIDE_LINE_COMMENT, model1.currentToken()
0776:                        .getState());
0777:                model1.move(1);
0778:                model1.insertChar('\n');
0779:                model1.insertChar('\"');
0780:                model1.insertChar('*');
0781:                model1.insertChar('/');
0782:                model1.move(-1);
0783:                // ///*
0784:                // "*#/
0785:                assertEquals("#1.0", INSIDE_DOUBLE_QUOTE, model1
0786:                        .getStateAtCurrent());
0787:                assertEquals("#1.1", "/", model1.currentToken().getType());
0788:                assertEquals("#1.4", INSIDE_DOUBLE_QUOTE, model1.currentToken()
0789:                        .getState());
0790:                model1.move(-5);
0791:                assertEquals("#2.1", "/", model1.currentToken().getType());
0792:                model1.insertChar('\n');
0793:                // //
0794:                // #/*
0795:                // "*/
0796:                assertEquals("#3.0", FREE, model1.getStateAtCurrent());
0797:                assertEquals("#3.4", FREE, model1.currentToken().getState());
0798:                model1.move(1);
0799:                assertEquals("#3.1", "/*", model1.currentToken().getType());
0800:                // //
0801:                // /*
0802:                // #"*/
0803:                model1.move(2);
0804:                assertEquals("#4.0", INSIDE_BLOCK_COMMENT, model1
0805:                        .getStateAtCurrent());
0806:                assertEquals("#4.1", "\"", model1.currentToken().getType());
0807:                assertEquals("#4.4", INSIDE_BLOCK_COMMENT, model1
0808:                        .currentToken().getState());
0809:                model1.move(1);
0810:                assertEquals("#4.6", "*/", model1.currentToken().getType());
0811:            }
0812:
0813:            /**
0814:             * put your documentation comment here
0815:             */
0816:            public void testMoveWithinToken() {
0817:                insertGap(model1, 10);
0818:                assertTrue("#0.0", model1.atEnd());
0819:                assertEquals("#0.1", 10, model1.absOffset());
0820:                model1.move(-5);
0821:                assertTrue("#1.0", model1.currentToken().isGap());
0822:                assertEquals("#1.1", 5, model1.absOffset());
0823:                model1.move(2);
0824:                assertTrue("#2.0", model1.currentToken().isGap());
0825:                assertEquals("#2.1", 7, model1.absOffset());
0826:                model1.move(-4);
0827:                assertTrue("#3.0", model1.currentToken().isGap());
0828:                assertEquals("#3.1", 3, model1.absOffset());
0829:                model1.move(-3);
0830:                assertTrue("#4.0", model1.currentToken().isGap());
0831:                assertEquals("#4.1", 0, model1.absOffset());
0832:                model1.move(10);
0833:                assertTrue("#5.0", model1.atEnd());
0834:                assertEquals("#5.1", 10, model1.absOffset());
0835:            }
0836:
0837:            /**
0838:             * put your documentation comment here
0839:             */
0840:            public void testMoveOnEmpty() {
0841:                model1.move(0);
0842:                assertTrue("#0.0", model1.atStart());
0843:                try {
0844:                    model1.move(-1);
0845:                    assertTrue("#0.1", false);
0846:                } catch (Exception e) {
0847:                }
0848:                try {
0849:                    model1.move(1);
0850:                    assertTrue("#0.2", false);
0851:                } catch (Exception e) {
0852:                }
0853:            }
0854:
0855:            /**
0856:             * put your documentation comment here
0857:             */
0858:            public void testMove0StaysPut() {
0859:                model0.insertChar('/');
0860:                assertEquals("#1", 1, model0.absOffset());
0861:                model0.move(0);
0862:                assertEquals("#2", 1, model0.absOffset());
0863:                model0.insertChar('/');
0864:                assertEquals("#3", 2, model0.absOffset());
0865:                model0.move(0);
0866:                assertEquals("#4", 2, model0.absOffset());
0867:                model0.move(-1);
0868:                assertEquals("#5", 1, model0.absOffset());
0869:                model0.move(0);
0870:                assertEquals("#6", 1, model0.absOffset());
0871:            }
0872:
0873:            /** tests the function to test if something is inside comments */
0874:            public void testInsideComment() {
0875:                assertEquals("#0.0", FREE, model0.getStateAtCurrent());
0876:                model0.insertChar('/');
0877:                model0.insertChar('*');
0878:                assertEquals("#0.1", INSIDE_BLOCK_COMMENT, model0
0879:                        .getStateAtCurrent());
0880:                model1.insertChar('/');
0881:                model1.insertChar('/');
0882:                assertEquals("#0.2", INSIDE_LINE_COMMENT, model1
0883:                        .getStateAtCurrent());
0884:                model1.insertChar('(');
0885:                assertEquals("#0.3", INSIDE_LINE_COMMENT, model1
0886:                        .getStateAtCurrent());
0887:                model1.insertChar('\n');
0888:                assertEquals("#0.4", FREE, model1.getStateAtCurrent());
0889:                model0.insertChar('*');
0890:                model0.insertChar('/');
0891:                assertEquals("#0.4", FREE, model0.getStateAtCurrent());
0892:            }
0893:
0894:            /** tests the function to test if something is inside quotes */
0895:            public void testInsideString() {
0896:                assertEquals("#0.0", FREE, model0.getStateAtCurrent());
0897:                model0.insertChar('\"');
0898:                assertEquals("#0.1", INSIDE_DOUBLE_QUOTE, model0
0899:                        .getStateAtCurrent());
0900:                model1.insertChar('\"');
0901:                assertEquals("#0.2", INSIDE_DOUBLE_QUOTE, model1
0902:                        .getStateAtCurrent());
0903:                model1.insertChar('(');
0904:                assertEquals("#0.3", INSIDE_DOUBLE_QUOTE, model1
0905:                        .getStateAtCurrent());
0906:                model1.insertChar('\"');
0907:                assertEquals("#0.4", FREE, model1.getStateAtCurrent());
0908:            }
0909:
0910:            /** tests inserting braces */
0911:            public void testInsertBraces() {
0912:                assertEquals("#0.0", 0, model0.absOffset());
0913:                model0.insertChar('/');
0914:                // /#
0915:                assertEquals("#1.0", FREE, model0.getStateAtCurrent());
0916:                model0.insertChar('*');
0917:                // /*#
0918:                assertEquals("#2.0", INSIDE_BLOCK_COMMENT, model0
0919:                        .getStateAtCurrent());
0920:                assertEquals("#2.1", 2, model0.absOffset());
0921:                model0.move(-1);
0922:                // /#*
0923:                assertEquals("#3.0", 1, model0.absOffset());
0924:                model0.insertChar('(');
0925:                // /(#*
0926:                assertEquals("#4.0", FREE, model0.getStateAtCurrent());
0927:                model0.move(-1);
0928:                // /#(*
0929:                model0.delete(1);
0930:                // /#*
0931:                model0.move(1);
0932:                // /*#
0933:                assertEquals("#5.0", INSIDE_BLOCK_COMMENT, model0
0934:                        .getStateAtCurrent());
0935:                model0.insertChar('*');
0936:                // /**#
0937:                assertEquals("#6.0", INSIDE_BLOCK_COMMENT, model0
0938:                        .getStateAtCurrent());
0939:                model0.insertChar('/');
0940:                // /**/#
0941:                assertEquals("#7.0", 4, model0.absOffset());
0942:                assertEquals("#7.1", FREE, model0.getStateAtCurrent());
0943:                model0.move(-2);
0944:                // /*#*/
0945:                assertEquals("#8.0", INSIDE_BLOCK_COMMENT, model0
0946:                        .getStateAtCurrent());
0947:                assertEquals("#8.1", 2, model0.absOffset());
0948:                model0.insertChar('(');
0949:                assertEquals("#9.0", INSIDE_BLOCK_COMMENT, model0
0950:                        .getStateAtCurrent());
0951:                // /*(#*/
0952:                model0.move(1);
0953:                // /*(*#/
0954:                assertEquals("#10.0", INSIDE_BLOCK_COMMENT, model0
0955:                        .getStateAtCurrent());
0956:                model0.move(-2);
0957:                // /*#(*/
0958:                assertEquals("#11.0", INSIDE_BLOCK_COMMENT, model0
0959:                        .getStateAtCurrent());
0960:                model0.move(1);
0961:                // /*(#*/
0962:                // /*(#*/
0963:                assertEquals("#12.0", INSIDE_BLOCK_COMMENT, model0
0964:                        .getStateAtCurrent());
0965:                assertEquals("#12.1", 3, model0.absOffset());
0966:                insertGap(model0, 4);
0967:                // /*(____#*/
0968:                model0.move(-2);
0969:                // /*(__#__*/
0970:                assertEquals("#13.0", 5, model0.absOffset());
0971:                model0.insertChar(')');
0972:                // /*(__)#__*/
0973:                assertEquals("#14.0", 6, model0.absOffset());
0974:                // move to the closed paren
0975:                model0.move(-1);
0976:                // /*(__#)__*/
0977:                assertEquals("#12.0", INSIDE_BLOCK_COMMENT, model0
0978:                        .getStateAtCurrent());
0979:            }
0980:
0981:            /** tests inserting gaps */
0982:            public void testInsertGap2() {
0983:                model0.insertChar('/');
0984:                model0.insertChar('*');
0985:                insertGap(model0, 5);
0986:                assertEquals("#0.0", 7, model0.absOffset());
0987:                model0.insertChar('(');
0988:                model0.move(-1);
0989:                insertGap(model0, 3);
0990:                assertEquals("#1.0", 10, model0.absOffset());
0991:            }
0992:
0993:            /** tests the cursor movement function */
0994:            public void testMove() {
0995:                model0.insertChar('(');
0996:                insertGap(model0, 5);
0997:                model0.insertChar(')');
0998:                model0.insertChar('\n');
0999:                insertGap(model0, 2);
1000:                model0.insertChar('{');
1001:                model0.insertChar('}');
1002:                try {
1003:                    model0.move(-30);
1004:                    assertTrue("#0.0", false);
1005:                } catch (Exception e) {
1006:                }
1007:                try {
1008:                    model0.move(1);
1009:                    assertTrue("#0.1", false);
1010:                } catch (Exception e) {
1011:                }
1012:                assertEquals("#0.2", 12, model0.absOffset());
1013:                model0.move(-2);
1014:                assertEquals("#0.3", 10, model0.absOffset());
1015:                model0.move(-8);
1016:                assertEquals("#0.4", 2, model0.absOffset());
1017:                model0.move(3);
1018:                assertEquals("#0.5", 5, model0.absOffset());
1019:                model0.move(4);
1020:                assertEquals("#0.6", 9, model0.absOffset());
1021:            }
1022:
1023:            /** sets up example reduction for the following tests */
1024:            protected ReducedModelControl setUpExample() {
1025:                ReducedModelControl model = new ReducedModelControl();
1026:                model.insertChar('{');
1027:                model.insertChar('\n');
1028:                insertGap(model, 3);
1029:                model.insertChar('\n');
1030:                model.insertChar('(');
1031:                insertGap(model, 2);
1032:                model.insertChar(')');
1033:                model.insertChar('\n');
1034:                insertGap(model, 3);
1035:                model.insertChar('/');
1036:                model.insertChar('/');
1037:                insertGap(model, 3);
1038:                model.insertChar('\n');
1039:                model.insertChar('\"');
1040:                insertGap(model, 1);
1041:                model.insertChar('{');
1042:                insertGap(model, 1);
1043:                model.insertChar('\"');
1044:                model.insertChar('/');
1045:                model.insertChar('*');
1046:                insertGap(model, 1);
1047:                model.insertChar('(');
1048:                insertGap(model, 1);
1049:                model.insertChar(')');
1050:                insertGap(model, 1);
1051:                model.insertChar('*');
1052:                model.insertChar('/');
1053:                model.insertChar('\n');
1054:                model.insertChar('}');
1055:                // {
1056:                // ___
1057:                // (__)
1058:                // ___//___
1059:                // "_{_"/*_(_)_*/
1060:                // }#
1061:                return model;
1062:            }
1063:
1064:            /** tests forward balancer, e.g., '(' balances with ')' */
1065:            public void testBalanceForward() {
1066:                assertEquals("#0.0", -1, model0.balanceForward());
1067:                model0 = setUpExample();
1068:                assertEquals("#1.0", -1, model0.balanceForward());
1069:                model0.move(-1);
1070:                //    System.out.println(model0.currentToken());
1071:                assertEquals("#2.0", -1, model0.balanceForward());
1072:                model0.move(-34);
1073:                //    System.out.println(model0.currentToken());
1074:                assertEquals("#3.0", 35, model0.balanceForward());
1075:                model0.move(1);
1076:                //    System.out.println(model0.currentToken());
1077:                assertEquals("#4.0", -1, model0.balanceForward());
1078:                model0.move(5);
1079:                //    System.out.println(model0.currentToken());
1080:                assertEquals("#5.0", 3, model0.balanceForward());
1081:                model0.move(27);
1082:                //    System.out.println(model0.currentToken());
1083:                assertEquals("#6.0", -1, model0.balanceForward());
1084:                model0.move(-20);
1085:                //    System.out.println(model0.currentToken());
1086:                assertEquals("#7.0", -1, model0.balanceForward());
1087:                model1.insertChar('(');
1088:                model1.move(-1);
1089:                //    System.out.println(model0.currentToken());
1090:                assertEquals("#8.0", -1, model1.balanceForward());
1091:                model1.move(1);
1092:                model1.insertChar('}');
1093:                model1.move(-1);
1094:                //    System.out.println(model0.currentToken());
1095:                assertEquals("#9.0", -1, model1.balanceForward());
1096:            }
1097:
1098:            /** tests backwards balancer, e.g., ')' balances with '(' */
1099:            public void testBalanceBackward() {
1100:                assertEquals("#0.0", -1, model0.balanceBackward());
1101:                model0 = setUpExample();
1102:                // {
1103:                // ___
1104:                // (__)
1105:                // ___//___
1106:                // "_{_"/*_(_)_*/
1107:                // }#
1108:                assertEquals("#1.0", 36, model0.balanceBackward());
1109:                model0.move(-2);
1110:                assertEquals("#2.0", -1, model0.balanceBackward());
1111:                model0.move(-14);
1112:                assertEquals("#3.0", -1, model0.balanceBackward());
1113:                model0.move(-10);
1114:                assertEquals("#4.0", 4, model0.balanceBackward());
1115:                model0.move(-10);
1116:                assertEquals("#5.0", -1, model0.balanceBackward());
1117:                model1.insertChar(')');
1118:                assertEquals("#6.0", -1, model1.balanceBackward());
1119:                model1.move(-1);
1120:                model1.insertChar('{');
1121:                model1.move(1);
1122:                assertEquals("#7.0", -1, model1.balanceBackward());
1123:            }
1124:        };
w_w_w_.___j___av___a_2_s_.__c_o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.