1 32 package net.sf.retrotranslator.runtime.java.lang; 33 34 import junit.framework.TestCase; 35 36 39 public class _CharacterTestCase extends TestCase { 40 41 public void testCharCount() throws Exception { 42 assertEquals(1, Character.charCount('a')); 43 assertEquals(2, Character.charCount(0x1D11E)); 44 } 45 46 public void testCodePointAt() throws Exception { 47 assertEquals('b', Character.codePointAt("abc", 1)); 48 assertEquals(0x20001, Character.codePointAt("a\uD840\uDC01c", 1)); 49 assertEquals(0xD840, Character.codePointAt("a\uD840", 1)); 50 assertEquals(0x1D11E, Character.codePointAt("\uD834\uDD1E".toCharArray(), 0)); 51 assertEquals(0xD834, Character.codePointAt("\uD834\uDD1Ex".toCharArray(), 0, 1)); 52 assertEquals(0xDD1E, Character.codePointAt("x\uDD1E".toCharArray(), 1)); 53 try { 54 Character.codePointAt("abc", -1); 55 fail(); 56 } catch (IndexOutOfBoundsException e) { 57 } 59 try { 60 Character.codePointAt("abc".toCharArray(), -1); 61 fail(); 62 } catch (IndexOutOfBoundsException e) { 63 } 65 try { 66 Character.codePointAt("abc", 10); 67 fail(); 68 } catch (IndexOutOfBoundsException e) { 69 } 71 try { 72 Character.codePointAt("abc".toCharArray(), 10); 73 fail(); 74 } catch (IndexOutOfBoundsException e) { 75 } 77 try { 78 Character.codePointAt("abc".toCharArray(), 2, 1); 79 fail(); 80 } catch (IndexOutOfBoundsException e) { 81 } 83 try { 84 Character.codePointAt("abc".toCharArray(), 0, -1); 85 fail(); 86 } catch (IndexOutOfBoundsException e) { 87 } 89 try { 90 Character.codePointAt("abc".toCharArray(), 0, 10); 91 fail(); 92 } catch (IndexOutOfBoundsException e) { 93 } 95 } 96 97 public void testCodePointBefore() throws Exception { 98 assertEquals('a', Character.codePointBefore("abc", 1)); 99 assertEquals('c', Character.codePointBefore("abc", 3)); 100 assertEquals(0x20001, Character.codePointBefore("a\uD840\uDC01c", 3)); 101 assertEquals(0xDC01, Character.codePointBefore("a\uDC01", 2)); 102 assertEquals(0x1D11E, Character.codePointBefore("\uD834\uDD1E".toCharArray(), 2)); 103 assertEquals(0xDD1E, Character.codePointBefore("\uD834\uDD1Ex".toCharArray(), 2, 1)); 104 assertEquals(0xDD1E, Character.codePointBefore("x\uDD1E", 2)); 105 try { 106 Character.codePointBefore("abc", 0); 107 fail(); 108 } catch (IndexOutOfBoundsException e) { 109 } 111 try { 112 Character.codePointBefore("abc".toCharArray(), 0); 113 fail(); 114 } catch (IndexOutOfBoundsException e) { 115 } 117 try { 118 Character.codePointBefore("abc", 4); 119 fail(); 120 } catch (IndexOutOfBoundsException e) { 121 } 123 try { 124 Character.codePointBefore("abc".toCharArray(), 4); 125 fail(); 126 } catch (IndexOutOfBoundsException e) { 127 } 129 try { 130 Character.codePointBefore("abc".toCharArray(), 1, 2); 131 fail(); 132 } catch (IndexOutOfBoundsException e) { 133 } 135 try { 136 Character.codePointBefore("abc".toCharArray(), 0, -1); 137 fail(); 138 } catch (IndexOutOfBoundsException e) { 139 } 141 try { 142 Character.codePointBefore("abc".toCharArray(), 0, 10); 143 fail(); 144 } catch (IndexOutOfBoundsException e) { 145 } 147 } 148 149 public void testCodePointCount() throws Exception { 150 assertEquals(4, Character.codePointCount("abcdef", 1, 5)); 151 assertEquals(3, Character.codePointCount("ab\uD834\uDD1Eef", 1, 5)); 152 assertEquals(5, Character.codePointCount("ab\uD834x\uDD1Eef", 1, 6)); 153 assertEquals(4, Character.codePointCount("abcdef".toCharArray(), 1, 4)); 154 assertEquals(3, Character.codePointCount("ab\uD834\uDD1Eef".toCharArray(), 1, 4)); 155 assertEquals(5, Character.codePointCount("ab\uD834x\uDD1Eef".toCharArray(), 1, 5)); 156 try { 157 Character.codePointCount("abc", -1, 2); 158 fail(); 159 } catch (IndexOutOfBoundsException e) { 160 } 162 try { 163 Character.codePointCount("abc", 1, 5); 164 fail(); 165 } catch (IndexOutOfBoundsException e) { 166 } 168 try { 169 Character.codePointCount("abc", 2, 1); 170 fail(); 171 } catch (IndexOutOfBoundsException e) { 172 } 174 try { 175 Character.codePointCount("abc".toCharArray(), -1, 2); 176 fail(); 177 } catch (IndexOutOfBoundsException e) { 178 } 180 try { 181 Character.codePointCount("abc".toCharArray(), 1, 3); 182 fail(); 183 } catch (IndexOutOfBoundsException e) { 184 } 186 try { 187 Character.codePointCount("abc".toCharArray(), 2, -1); 188 fail(); 189 } catch (IndexOutOfBoundsException e) { 190 } 192 } 193 194 public void testDigit() throws Exception { 195 assertEquals(5, Character.digit((int) '5', 10)); 196 assertEquals(-1, Character.digit((int) 'z', 10)); 197 } 198 199 public void testGetDirectionality() throws Exception { 200 assertEquals(Character.DIRECTIONALITY_EUROPEAN_NUMBER, Character.getDirectionality((int) '5')); 201 } 202 203 public void testGetNumericValue() throws Exception { 204 assertEquals(5, Character.getNumericValue((int) '5')); 205 } 206 207 public void testGetType() throws Exception { 208 assertEquals(Character.DECIMAL_DIGIT_NUMBER, Character.getType((int) '5')); 209 } 210 211 public void testIsDefined() throws Exception { 212 assertTrue(Character.isDefined((int) 'a')); 213 assertFalse(Character.isDefined(0x50000)); 214 } 215 216 public void testIsDigit() throws Exception { 217 assertTrue(Character.isDigit((int) '5')); 218 assertFalse(Character.isDigit((int) 'a')); 219 } 220 221 public void testIsHighSurrogate() throws Exception { 222 assertTrue(Character.isHighSurrogate('\uD834')); 223 assertFalse(Character.isHighSurrogate('a')); 224 } 225 226 public void testIsIdentifierIgnorable() throws Exception { 227 assertTrue(Character.isIdentifierIgnorable(0x0085)); 228 assertFalse(Character.isIdentifierIgnorable((int) 'a')); 229 } 230 231 public void testIsISOControl() throws Exception { 232 assertTrue(Character.isISOControl(9)); 233 assertFalse(Character.isISOControl((int) 'a')); 234 } 235 236 public void testIsJavaIdentifierPart() throws Exception { 237 assertTrue(Character.isJavaIdentifierPart((int) 'a')); 238 assertFalse(Character.isJavaIdentifierPart((int) '+')); 239 } 240 241 public void testIsJavaIdentifierStart() throws Exception { 242 assertTrue(Character.isJavaIdentifierStart((int) 'a')); 243 assertFalse(Character.isJavaIdentifierStart((int) '1')); 244 } 245 246 public void testIsLetter() throws Exception { 247 assertTrue(Character.isLetter((int) 'a')); 248 assertFalse(Character.isLetter((int) '1')); 249 } 250 251 public void testIsLetterOrDigit() throws Exception { 252 assertTrue(Character.isLetterOrDigit((int) 'a')); 253 assertTrue(Character.isLetterOrDigit((int) '5')); 254 assertFalse(Character.isLetterOrDigit((int) '.')); 255 } 256 257 public void testIsLowerCase() throws Exception { 258 assertTrue(Character.isLowerCase((int) 'a')); 259 assertFalse(Character.isLowerCase((int) 'A')); 260 } 261 262 public void testIsLowSurrogate() throws Exception { 263 assertTrue(Character.isLowSurrogate('\uDD1E')); 264 assertFalse(Character.isLowSurrogate('\uD834')); 265 assertFalse(Character.isLowSurrogate('a')); 266 } 267 268 public void testIsMirrored() throws Exception { 269 assertTrue(Character.isMirrored((int) '{')); 270 assertFalse(Character.isMirrored((int) 'z')); 271 } 272 273 public void testIsSpaceChar() throws Exception { 274 assertTrue(Character.isSpaceChar((int) ' ')); 275 assertFalse(Character.isSpaceChar((int) 'x')); 276 } 277 278 public void testIsSupplementaryCodePoint() throws Exception { 279 assertTrue(Character.isSupplementaryCodePoint(0x1D11E)); 280 assertFalse(Character.isSupplementaryCodePoint((int) 'a')); 281 assertFalse(Character.isSupplementaryCodePoint(-100)); 282 } 283 284 public void testIsSurrogatePair() throws Exception { 285 assertTrue(Character.isSurrogatePair('\uD834', '\uDD1E')); 286 assertFalse(Character.isSurrogatePair('\uDD1E', '\uD834')); 287 assertFalse(Character.isSurrogatePair('a', 'b')); 288 } 289 290 public void testIsTitleCase() throws Exception { 291 assertTrue(Character.isTitleCase(453)); 292 assertFalse(Character.isTitleCase((int) 'A')); 293 } 294 295 public void testIsUnicodeIdentifierPart() throws Exception { 296 assertTrue(Character.isUnicodeIdentifierPart((int) '_')); 297 assertFalse(Character.isUnicodeIdentifierPart((int) '.')); 298 } 299 300 public void testIsUnicodeIdentifierStart() throws Exception { 301 assertTrue(Character.isUnicodeIdentifierStart((int) 'a')); 302 assertFalse(Character.isUnicodeIdentifierStart((int) '.')); 303 } 304 305 public void testIsUpperCase() throws Exception { 306 assertTrue(Character.isUpperCase((int) 'A')); 307 assertFalse(Character.isUpperCase((int) 'a')); 308 } 309 310 public void testIsValidCodePoint() throws Exception { 311 assertTrue(Character.isValidCodePoint((int) 'A')); 312 assertFalse(Character.isValidCodePoint(0x1000000)); 313 assertFalse(Character.isValidCodePoint(-1)); 314 } 315 316 public void testIsWhitespace() throws Exception { 317 assertTrue(Character.isWhitespace(9)); 318 assertFalse(Character.isWhitespace((int) 'x')); 319 } 320 321 public void testOffsetByCodePoints() throws Exception { 322 assertEquals(5, Character.offsetByCodePoints("abcdef", 2, 3)); 323 assertEquals(6, Character.offsetByCodePoints("ab\uD834\uDD1Eef", 2, 3)); 324 assertEquals(2, Character.offsetByCodePoints("ab\uD834\uDD1Eef", 4, -1)); 325 assertEquals(0, Character.offsetByCodePoints("\uDD1Eef", 3, -3)); 326 assertEquals(3, Character.offsetByCodePoints("ab\uD834", 1, 2)); 327 assertEquals(3, Character.offsetByCodePoints("abcdef".toCharArray(), 1, 3, 2, 1)); 328 assertEquals(1, Character.offsetByCodePoints("abc".toCharArray(), 1, 1, 2, -1)); 329 assertEquals(1, Character.offsetByCodePoints("ab\uD834\uDD1Eef".toCharArray(), 1, 4, 5, -3)); 330 try { 331 Character.offsetByCodePoints("abc", -1, 3); 332 fail(); 333 } catch (IndexOutOfBoundsException e) { 334 } 336 try { 337 Character.offsetByCodePoints("abc", 5, 0); 338 fail(); 339 } catch (IndexOutOfBoundsException e) { 340 } 342 try { 343 Character.offsetByCodePoints("abc", 1, 3); 344 fail(); 345 } catch (IndexOutOfBoundsException e) { 346 } 348 try { 349 Character.offsetByCodePoints("abc", 1, -2); 350 fail(); 351 } catch (IndexOutOfBoundsException e) { 352 } 354 try { 355 Character.offsetByCodePoints("abc".toCharArray(), -1, 0, 1, 0); 356 fail(); 357 } catch (IndexOutOfBoundsException e) { 358 } 360 try { 361 Character.offsetByCodePoints("abc".toCharArray(), 1, -1, 1, 0); 362 fail(); 363 } catch (IndexOutOfBoundsException e) { 364 } 366 try { 367 Character.offsetByCodePoints("abc".toCharArray(), 1, 3, 1, 0); 368 fail(); 369 } catch (IndexOutOfBoundsException e) { 370 } 372 try { 373 Character.offsetByCodePoints("abc".toCharArray(), 1, 2, 0, 0); 374 fail(); 375 } catch (IndexOutOfBoundsException e) { 376 } 378 try { 379 Character.offsetByCodePoints("abc".toCharArray(), 1, 1, 1, 2); 380 fail(); 381 } catch (IndexOutOfBoundsException e) { 382 } 384 try { 385 Character.offsetByCodePoints("abc".toCharArray(), 1, 1, 3, 0); 386 fail(); 387 } catch (IndexOutOfBoundsException e) { 388 } 390 try { 391 Character.offsetByCodePoints("abc".toCharArray(), 1, 1, 2, -2); 392 fail(); 393 } catch (IndexOutOfBoundsException e) { 394 } 396 } 397 398 public void testReverseBytes() throws Exception { 399 assertEquals(0x3412, Character.reverseBytes((char) 0x1234)); 400 } 401 402 public void testToChars() throws Exception { 403 assertEquals("a", new String (Character.toChars('a'))); 404 assertEquals("\uD840\uDC01", new String (Character.toChars(0x20001))); 405 char[] chars = new char[10]; 406 assertEquals(1, Character.toChars('a', chars, 5)); 407 assertEquals('a', chars[5]); 408 assertEquals(2, Character.toChars(0x20001, chars, 7)); 409 assertEquals('\uD840', chars[7]); 410 assertEquals('\uDC01', chars[8]); 411 try { 412 Character.toChars(-100); 413 fail(); 414 } catch (IllegalArgumentException e) { 415 } 417 try { 418 Character.toChars(0x1000000, chars, 0); 419 fail(); 420 } catch (IllegalArgumentException e) { 421 } 423 } 424 425 public void testToCodePoint() throws Exception { 426 assertEquals(0x1D11E, Character.toCodePoint('\uD834', '\uDD1E')); 427 assertEquals(0x20001, Character.toCodePoint('\uD840', '\uDC01')); 428 } 429 430 public void testToLowerCase() throws Exception { 431 assertEquals('a', Character.toLowerCase((int) 'A')); 432 assertEquals('5', Character.toLowerCase((int) '5')); 433 } 434 435 public void testToTitleCase() throws Exception { 436 assertEquals('A', Character.toTitleCase((int) 'a')); 437 assertEquals('Z', Character.toTitleCase((int) 'Z')); 438 assertEquals('5', Character.toTitleCase((int) '5')); 439 assertEquals(453, Character.toTitleCase(454)); 440 } 441 442 public void testToUpperCase() throws Exception { 443 assertEquals('A', Character.toUpperCase((int) 'a')); 444 assertEquals('Z', Character.toUpperCase((int) 'Z')); 445 assertEquals(452, Character.toUpperCase(453)); 446 assertEquals(452, Character.toUpperCase(454)); 447 } 448 449 public void testValueOf() throws Exception { 450 Character character = 'a'; 451 assertEquals("a", String.valueOf(character)); 452 } 453 454 } | Popular Tags |