Source Code Cross Referenced for ArgumentTokenizerTest.java in  » IDE » DrJava » edu » rice » cs » util » 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.util 
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.util;
038:
039:        import edu.rice.cs.drjava.DrJavaTestCase;
040:
041:        import java.util.Arrays;
042:        import java.util.List;
043:
044:        /**
045:         * Tests that an ArgumentTokenizer can correctly divide up a string
046:         * into command line-style arguments.  Tries to follow the precedent
047:         * set by a Unix bash shell in most cases.
048:         * @version $Id: ArgumentTokenizerTest.java 4255 2007-08-28 19:17:37Z mgricken $
049:         */
050:        public class ArgumentTokenizerTest extends DrJavaTestCase {
051:
052:            /**
053:             * Creates a new ArgumentTokenizer to be used in every test.
054:             */
055:            public ArgumentTokenizerTest(String name) {
056:                super (name);
057:            }
058:
059:            /**
060:             * Asserts that the given string is tokenized to become the
061:             * given array of string arguments.
062:             * @param typed A string containing all arguments (as typed by a user)
063:             * @param expected What the tokenizer should return
064:             */
065:            protected void _assertTokenized(String typed, String[] expected) {
066:                _assertTokenized(typed, expected, false);
067:            }
068:
069:            /**
070:             * Asserts that the given string is tokenized to become the
071:             * given array of string arguments.
072:             * @param typed A string containing all arguments (as typed by a user)
073:             * @param expected What the tokenizer should return
074:             * @param stringify Whether to format the resulting arguments to print
075:             * out as Strings.
076:             */
077:            protected void _assertTokenized(String typed, String[] expected,
078:                    boolean stringify) {
079:                List<String> actual = ArgumentTokenizer.tokenize(typed,
080:                        stringify);
081:                List expectedList = Arrays.asList(expected);
082:                assertEquals("tokenized argument list should match expected",
083:                        expectedList, actual);
084:            }
085:
086:            /**
087:             * Tests that the argument tokenizer can split up a simple list of arguments.
088:             */
089:            public void testTokenizeArguments() {
090:                // a b c
091:                // [a, b, c]
092:                _assertTokenized("a b c", new String[] { "a", "b", "c" });
093:                // "a b c"
094:                // [a b c]
095:                _assertTokenized("\"a b c\"", new String[] { "a b c" });
096:
097:                // "a b"c d
098:                // [a bc, d]
099:                // This behavior seems unintuitive, but it's the way both DOS and Unix
100:                //  handle command-line arguments.
101:                _assertTokenized("\"a b\"c d", new String[] { "a bc", "d" });
102:
103:                // 'a b'c d
104:                // [a bc, d]
105:                // This behavior seems unintuitive, but it's the way both DOS and Unix
106:                //  handle command-line arguments.
107:                _assertTokenized("'a b'c d", new String[] { "a bc", "d" });
108:
109:                // a b"c d"
110:                // [a, bc d]
111:                // This behavior seems unintuitive, but it's the way both DOS and Unix
112:                //  handle command-line arguments.
113:                _assertTokenized("a b\"c d\"", new String[] { "a", "bc d" });
114:
115:                // a b'c d'
116:                // [a, bc d]
117:                // This behavior seems unintuitive, but it's the way both DOS and Unix
118:                //  handle command-line arguments.
119:                _assertTokenized("a b'c d'", new String[] { "a", "bc d" });
120:
121:                // a b'c d'"e f" g "hi "
122:                // [a, bc de f, g, hi ]
123:                _assertTokenized("a b'c d'\"e f\" g \"hi \"", new String[] {
124:                        "a", "bc de f", "g", "hi " });
125:
126:                // c:\\file.txt
127:                // [c:\file.txt]
128:                _assertTokenized("c:\\\\file.txt",
129:                        new String[] { "c:\\file.txt" });
130:
131:                // /home/user/file
132:                // [/home/user/file]
133:                _assertTokenized("/home/user/file",
134:                        new String[] { "/home/user/file" });
135:
136:                // "asdf
137:                // [asdf]
138:                _assertTokenized("\"asdf", new String[] { "asdf" });
139:            }
140:
141:            /**
142:             * Tests that escaped characters just return the character itself.
143:             * Escaped whitespace is considered a character, not a delimiter.
144:             * (This is how Unix behaves.)
145:             *
146:             * not currently enforcing any behavior for a simple implementation
147:             * using a StreamTokenizer
148:             */
149:            public void testTokenizeEscapedArgs() {
150:                // \j
151:                // [j]
152:                _assertTokenized("\\j", new String[] { "j" });
153:                // \"
154:                // ["]
155:                _assertTokenized("\\\"", new String[] { "\"" });
156:                // \\
157:                // [\]
158:                _assertTokenized("\\\\", new String[] { "\\" });
159:                // a\ b
160:                // [a b]
161:                _assertTokenized("a\\ b", new String[] { "a b" });
162:            }
163:
164:            /**
165:             * Tests that within a quote, everything is correctly escaped.
166:             * (Special characters are passed to the program correctly.)
167:             */
168:            public void testTokenizeQuotedEscapedArgs() {
169:                // "a \" b"
170:                // [a " b]
171:                _assertTokenized("\"a \\\" b\"", new String[] { "a \" b" });
172:                // "\'"
173:                // [\']
174:                _assertTokenized("\"'\"", new String[] { "'" });
175:                // "\\"
176:                // [\]
177:                _assertTokenized("\\\\", new String[] { "\\" });
178:                // "\" \d"
179:                // [" \d]
180:                _assertTokenized("\"\\\" \\d\"", new String[] { "\" \\d" });
181:                // "\n"
182:                // [\n]
183:                _assertTokenized("\"\\n\"", new String[] { "\\n" });
184:                // "\t"
185:                // [\t]
186:                _assertTokenized("\"\\t\"", new String[] { "\\t" });
187:                // "\r"
188:                // [\r]
189:                _assertTokenized("\"\\r\"", new String[] { "\\r" });
190:                // "\f"
191:                // [\f]
192:                _assertTokenized("\"\\f\"", new String[] { "\\f" });
193:                // "\b"
194:                // [\b]
195:                _assertTokenized("\"\\b\"", new String[] { "\\b" });
196:            }
197:
198:            /**
199:             * Tests that single quotes can be used as argument delimiters.
200:             * This is consistent with Unix, not with DOS.
201:             */
202:            public void testTokenizeSingleQuotedArgs() {
203:                // 'asdf'
204:                // [asdf]
205:                _assertTokenized("'asdf'", new String[] { "asdf" });
206:                // 'a b c'
207:                // [a b c]
208:                _assertTokenized("'a b c'", new String[] { "a b c" });
209:                // '\'
210:                // [\]
211:                _assertTokenized("'\\'", new String[] { "\\" });
212:            }
213:
214:            /**
215:             * Tests that arguments can be "stringified" properly.
216:             * (ie. formatted to be printed as a String)
217:             */
218:            public void testTokenizeAndStringify() {
219:                // a b c
220:                // ["a", "b", "c"]
221:                _assertTokenized("a b c", new String[] { "\"a\"", "\"b\"",
222:                        "\"c\"" }, true);
223:                // \\
224:                // ["\\"]
225:                _assertTokenized("\\", new String[] { "\"\\\\\"" }, true);
226:                // \"
227:                // ["\""]
228:                _assertTokenized("\\\"", new String[] { "\"\\\"\"" }, true);
229:                // "\n"
230:                // ["\\n"]
231:                _assertTokenized("\"\\n\"", new String[] { "\"\\\\n\"" }, true);
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.