1 33 34 package edu.rice.cs.util; 35 36 import edu.rice.cs.drjava.DrJavaTestCase; 37 38 import java.util.Arrays ; 39 import java.util.List ; 40 41 47 public class ArgumentTokenizerTest extends DrJavaTestCase { 48 49 52 public ArgumentTokenizerTest(String name) { 53 super(name); 54 } 55 56 62 protected void _assertTokenized(String typed, String [] expected) { 63 _assertTokenized(typed, expected, false); 64 } 65 66 74 protected void _assertTokenized(String typed, String [] expected, 75 boolean stringify) { 76 List <String > actual = ArgumentTokenizer.tokenize(typed, stringify); 77 List expectedList = Arrays.asList(expected); 78 assertEquals("tokenized argument list should match expected", 79 expectedList, actual); 80 } 81 82 85 public void testTokenizeArguments() { 86 _assertTokenized("a b c", 89 new String []{"a","b","c"}); 90 _assertTokenized("\"a b c\"", 93 new String []{"a b c"}); 94 95 _assertTokenized("\"a b\"c d", 100 new String []{"a bc","d"}); 101 102 _assertTokenized("'a b'c d", 107 new String []{"a bc","d"}); 108 109 _assertTokenized("a b\"c d\"", 114 new String []{"a","bc d"}); 115 116 _assertTokenized("a b'c d'", 121 new String []{"a","bc d"}); 122 123 _assertTokenized("a b'c d'\"e f\" g \"hi \"", 126 new String []{"a","bc de f","g","hi "}); 127 128 _assertTokenized("c:\\\\file.txt", 131 new String []{"c:\\file.txt"}); 132 133 _assertTokenized("/home/user/file", 136 new String []{"/home/user/file"}); 137 138 _assertTokenized("\"asdf", 141 new String []{"asdf"}); 142 } 143 144 152 public void testTokenizeEscapedArgs() { 153 _assertTokenized("\\j", 156 new String []{"j"}); 157 _assertTokenized("\\\"", 160 new String []{"\""}); 161 _assertTokenized("\\\\", 164 new String []{"\\"}); 165 _assertTokenized("a\\ b", 168 new String []{"a b"}); 169 } 170 171 175 public void testTokenizeQuotedEscapedArgs() { 176 _assertTokenized("\"a \\\" b\"", 179 new String []{"a \" b"}); 180 _assertTokenized("\"'\"", 183 new String []{"'"}); 184 _assertTokenized("\\\\", 187 new String []{"\\"}); 188 _assertTokenized("\"\\\" \\d\"", 191 new String []{"\" \\d"}); 192 _assertTokenized("\"\\n\"", 195 new String []{"\\n"}); 196 _assertTokenized("\"\\t\"", 199 new String []{"\\t"}); 200 _assertTokenized("\"\\r\"", 203 new String []{"\\r"}); 204 _assertTokenized("\"\\f\"", 207 new String []{"\\f"}); 208 _assertTokenized("\"\\b\"", 211 new String []{"\\b"}); 212 } 213 214 218 public void testTokenizeSingleQuotedArgs() { 219 _assertTokenized("'asdf'", 222 new String []{"asdf"}); 223 _assertTokenized("'a b c'", 226 new String []{"a b c"}); 227 _assertTokenized("'\\'", 230 new String []{"\\"}); 231 } 232 233 237 public void testTokenizeAndStringify() { 238 _assertTokenized("a b c", 241 new String []{"\"a\"", "\"b\"", "\"c\""}, 242 true); 243 _assertTokenized("\\", 246 new String []{"\"\\\\\""}, 247 true); 248 _assertTokenized("\\\"", 251 new String []{"\"\\\"\""}, 252 true); 253 _assertTokenized("\"\\n\"", 256 new String []{"\"\\\\n\""}, 257 true); 258 } 259 } 260 | Popular Tags |