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


001:        /*BEGIN_COPYRIGHT_BLOCK
002:         *
003:         * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004:         * All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are met:
008:         *    * Redistributions of source code must retain the above copyright
009:         *      notice, this list of conditions and the following disclaimer.
010:         *    * Redistributions in binary form must reproduce the above copyright
011:         *      notice, this list of conditions and the following disclaimer in the
012:         *      documentation and/or other materials provided with the distribution.
013:         *    * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014:         *      names of its contributors may be used to endorse or promote products
015:         *      derived from this software without specific prior written permission.
016:         * 
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028:         *
029:         * This software is Open Source Initiative approved Open Source Software.
030:         * Open Source Initative Approved is a trademark of the Open Source Initiative.
031:         * 
032:         * This file is part of DrJava.  Download the current version of this project
033:         * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034:         * 
035:         * END_COPYRIGHT_BLOCK*/
036:
037:        package edu.rice.cs.drjava.model.definitions.indent;
038:
039:        import javax.swing.text.BadLocationException;
040:
041:        /**
042:         * Tests the indention rule which detects whether the current line
043:         * starts with a particular string.
044:         * @version $Id: QuestionCurrLineStartsWithTest.java 4255 2007-08-28 19:17:37Z mgricken $
045:         */
046:        public final class QuestionCurrLineStartsWithTest extends
047:                IndentRulesTestCase {
048:
049:            /** Tests not having the prefix in the text. */
050:            public void testNoPrefix() throws BadLocationException {
051:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith("{",
052:                        null, null);
053:
054:                // Open brace
055:                _setDocText("foo();\n}\n");
056:                assertTrue("no open brace", !rule.applyRule(_doc, 0,
057:                        Indenter.IndentReason.OTHER));
058:                assertTrue("line of close brace (no open brace)", !rule
059:                        .applyRule(_doc, 7, Indenter.IndentReason.OTHER));
060:                assertTrue("line after close brace (no open brace)", !rule
061:                        .applyRule(_doc, 8, Indenter.IndentReason.OTHER));
062:
063:                // Close brace
064:                rule = new QuestionCurrLineStartsWith("}", null, null);
065:                _setDocText("{\nfoo();");
066:                assertTrue("no close brace", !rule.applyRule(_doc, 0,
067:                        Indenter.IndentReason.OTHER));
068:            }
069:
070:            /**
071:             * Tests having a line start with prefix, with text following
072:             */
073:            public void testStartsWithPrefixWithText()
074:                    throws BadLocationException {
075:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith("}",
076:                        null, null);
077:
078:                // Prefix plus text (no space)
079:                _setDocText("foo();\n}bar();\n");
080:                assertTrue("line before brace (no space)", !rule.applyRule(
081:                        _doc, 0, Indenter.IndentReason.OTHER));
082:                assertTrue("just before brace (no space)", rule.applyRule(_doc,
083:                        7, Indenter.IndentReason.OTHER));
084:                assertTrue("just after brace (no space)", rule.applyRule(_doc,
085:                        9, Indenter.IndentReason.OTHER));
086:                assertTrue("line after brace (no space)", !rule.applyRule(_doc,
087:                        15, Indenter.IndentReason.OTHER));
088:
089:                // Prefix plus text (with space)
090:                rule = new QuestionCurrLineStartsWith("*", null, null);
091:                _setDocText("foo\n * comment\nbar");
092:                assertTrue("line before star (with space)", !rule.applyRule(
093:                        _doc, 0, Indenter.IndentReason.OTHER));
094:                assertTrue("just before star (with space)", rule.applyRule(
095:                        _doc, 4, Indenter.IndentReason.OTHER));
096:                assertTrue("just after star (with space)", rule.applyRule(_doc,
097:                        6, Indenter.IndentReason.OTHER));
098:                assertTrue("line after star (with space)", !rule.applyRule(
099:                        _doc, 15, Indenter.IndentReason.OTHER));
100:            }
101:
102:            /**
103:             * Tests having a line start with prefix, with no text following
104:             */
105:            public void testStartsWithPrefixNoText()
106:                    throws BadLocationException {
107:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith("{",
108:                        null, null);
109:
110:                // Prefix plus no text (no space)
111:                _setDocText("foo();\n{\nbar();\n");
112:                assertTrue("line before brace (no space)", !rule.applyRule(
113:                        _doc, 0, Indenter.IndentReason.OTHER));
114:                assertTrue("just before brace (no space)", rule.applyRule(_doc,
115:                        7, Indenter.IndentReason.OTHER));
116:                assertTrue("just after brace (no space)", rule.applyRule(_doc,
117:                        8, Indenter.IndentReason.OTHER));
118:                assertTrue("line after brace (no space)", !rule.applyRule(_doc,
119:                        10, Indenter.IndentReason.OTHER));
120:
121:                // Prefix plus no text (with space)
122:                _setDocText("foo();\n   {\nbar();\n");
123:                assertTrue("line before brace (with space)", !rule.applyRule(
124:                        _doc, 0, Indenter.IndentReason.OTHER));
125:                assertTrue("just before brace (with space)", rule.applyRule(
126:                        _doc, 7, Indenter.IndentReason.OTHER));
127:                assertTrue("just after brace (with space)", rule.applyRule(
128:                        _doc, 11, Indenter.IndentReason.OTHER));
129:                assertTrue("line after brace (with space)", !rule.applyRule(
130:                        _doc, 14, Indenter.IndentReason.OTHER));
131:            }
132:
133:            /**
134:             * Tests having a multiple character prefix.
135:             */
136:            public void testMultipleCharPrefix() throws BadLocationException {
137:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith(".*.",
138:                        null, null);
139:
140:                // Multi-char prefix
141:                _setDocText("*\n.*\n.*.\n.*.foo");
142:                assertTrue("star", !rule.applyRule(_doc, 0,
143:                        Indenter.IndentReason.OTHER));
144:                assertTrue("dot star", !rule.applyRule(_doc, 2,
145:                        Indenter.IndentReason.OTHER));
146:                assertTrue("dot star dot", rule.applyRule(_doc, 7,
147:                        Indenter.IndentReason.OTHER));
148:                assertTrue("dot star dot text", rule.applyRule(_doc, 9,
149:                        Indenter.IndentReason.OTHER));
150:            }
151:
152:            /**
153:             * Tests having a commented prefix without searching in comments.
154:             */
155:            public void testCommentedPrefixDontSearchComment()
156:                    throws BadLocationException {
157:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith("{",
158:                        null, null);
159:
160:                // Open brace in comment
161:                _setDocText("foo();\n// {\nbar();\n");
162:                assertTrue("just before brace", !rule.applyRule(_doc, 7,
163:                        Indenter.IndentReason.OTHER));
164:                assertTrue("just after brace", !rule.applyRule(_doc, 11,
165:                        Indenter.IndentReason.OTHER));
166:                assertTrue("line after brace", !rule.applyRule(_doc, 12,
167:                        Indenter.IndentReason.OTHER));
168:            }
169:
170:            /**
171:             * Tests having a commented prefix with searching in comments.
172:             */
173:            public void testCommentedPrefixSearchComment()
174:                    throws BadLocationException {
175:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith("*",
176:                        null, null);
177:
178:                // Star in comment
179:                _setDocText("/**\n* \ncomment\n");
180:                assertTrue("line before star", !rule.applyRule(_doc, 0,
181:                        Indenter.IndentReason.OTHER));
182:                assertTrue("just before star", rule.applyRule(_doc, 4,
183:                        Indenter.IndentReason.OTHER));
184:                assertTrue("just after star", rule.applyRule(_doc, 6,
185:                        Indenter.IndentReason.OTHER));
186:                assertTrue("line after star", !rule.applyRule(_doc, 7,
187:                        Indenter.IndentReason.OTHER));
188:            }
189:
190:            /**
191:             * Tests having text on a line before the prefix.
192:             */
193:            public void testDoesNotStartWithPrefix()
194:                    throws BadLocationException {
195:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith("}",
196:                        null, null);
197:
198:                // Close brace in text, not starting line
199:                _setDocText("foo(); }\nbar();\n");
200:                assertTrue("before brace", !rule.applyRule(_doc, 0,
201:                        Indenter.IndentReason.OTHER));
202:                assertTrue("just before brace", !rule.applyRule(_doc, 7,
203:                        Indenter.IndentReason.OTHER));
204:                assertTrue("just after brace", !rule.applyRule(_doc, 8,
205:                        Indenter.IndentReason.OTHER));
206:                assertTrue("line after brace", !rule.applyRule(_doc, 10,
207:                        Indenter.IndentReason.OTHER));
208:            }
209:
210:            /**
211:             * Prefix appears at the end of a document.
212:             */
213:            public void testPrefixAtEnd() throws BadLocationException {
214:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith("}",
215:                        null, null);
216:
217:                _setDocText("void foo() {\n}");
218:                assertTrue("first line", !rule.applyRule(_doc, 3,
219:                        Indenter.IndentReason.OTHER));
220:                assertTrue("end of first line", !rule.applyRule(_doc, 12,
221:                        Indenter.IndentReason.OTHER));
222:                assertTrue("beginning of second line", rule.applyRule(_doc, 13,
223:                        Indenter.IndentReason.OTHER));
224:                assertTrue("end of second line", rule.applyRule(_doc, 14,
225:                        Indenter.IndentReason.OTHER));
226:            }
227:
228:            /**
229:             * Tests multiple-character prefix.
230:             */
231:            public void testMultCharPrefix() throws BadLocationException {
232:                IndentRuleQuestion rule = new QuestionCurrLineStartsWith(
233:                        "abcdefg", null, null);
234:
235:                _setDocText("   abcdefghij\n  abcde");
236:                assertTrue("first line, beginning", rule.applyRule(_doc, 0,
237:                        Indenter.IndentReason.OTHER));
238:                assertTrue("first line, mid", rule.applyRule(_doc, 6,
239:                        Indenter.IndentReason.OTHER));
240:                assertTrue("first line, end", rule.applyRule(_doc, 13,
241:                        Indenter.IndentReason.OTHER));
242:                assertTrue("second line, beginning", !rule.applyRule(_doc, 14,
243:                        Indenter.IndentReason.OTHER));
244:                assertTrue("second line, mid", !rule.applyRule(_doc, 18,
245:                        Indenter.IndentReason.OTHER));
246:                assertTrue("second line, end", !rule.applyRule(_doc, 21,
247:                        Indenter.IndentReason.OTHER));
248:            }
249:        }
ww_w___._j_av___a__2___s___._co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.