Lines 19-31
Link Here
|
19 |
import junit.framework.Test; |
19 |
import junit.framework.Test; |
20 |
|
20 |
|
21 |
public class UtilTest extends AbstractRegressionTest { |
21 |
public class UtilTest extends AbstractRegressionTest { |
22 |
|
22 |
|
|
|
23 |
StringBuffer camelCaseErrors; |
24 |
|
23 |
public UtilTest(String name) { |
25 |
public UtilTest(String name) { |
24 |
super(name); |
26 |
super(name); |
25 |
} |
27 |
} |
|
|
28 |
static { |
29 |
// TESTS_RANGE = new int[] { 62, -1 }; |
30 |
} |
26 |
public static Test suite() { |
31 |
public static Test suite() { |
27 |
return buildAllCompliancesTestSuite(testClass()); |
32 |
return buildAllCompliancesTestSuite(testClass()); |
28 |
} |
33 |
} |
|
|
34 |
/** |
35 |
* Assert that a pattern and a name matches or not. |
36 |
* If result is invalid then store warning in buffer and display it. |
37 |
*/ |
38 |
void assertCamelCase(String pattern, String name, boolean match) { |
39 |
boolean camelCase = CharOperation.camelCaseMatch(pattern==null?null:pattern.toCharArray(), name==null?null:name.toCharArray()); |
40 |
if (match != camelCase) { |
41 |
StringBuffer line = new StringBuffer("'"); |
42 |
line.append(name); |
43 |
line.append("' SHOULD"); |
44 |
if (!match) line.append(" NOT"); |
45 |
line.append(" match pattern '"); |
46 |
line.append(pattern); |
47 |
line.append("'"); |
48 |
if (this.camelCaseErrors.length() == 0) { |
49 |
System.out.println("Invalid results in test "+getName()+":"); |
50 |
} |
51 |
System.out.println(" - "+line); |
52 |
this.camelCaseErrors.append('\n'); |
53 |
this.camelCaseErrors.append(line); |
54 |
} |
55 |
} |
56 |
/* (non-Javadoc) |
57 |
* @see org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest#setUp() |
58 |
*/ |
59 |
protected void setUp() throws Exception { |
60 |
super.setUp(); |
61 |
this.camelCaseErrors = new StringBuffer(); |
62 |
} |
63 |
|
29 |
public boolean checkPathMatch(char[] pattern, char[] path, boolean isCaseSensitive) { |
64 |
public boolean checkPathMatch(char[] pattern, char[] path, boolean isCaseSensitive) { |
30 |
|
65 |
|
31 |
CharOperation.replace(pattern, '/', File.separatorChar); |
66 |
CharOperation.replace(pattern, '/', File.separatorChar); |
Lines 430-499
Link Here
|
430 |
checkPathMatch("/P/src/**/CVS/".toCharArray(), "/P/src/CVS".toCharArray(), true)); |
465 |
checkPathMatch("/P/src/**/CVS/".toCharArray(), "/P/src/CVS".toCharArray(), true)); |
431 |
} |
466 |
} |
432 |
public void test62() { |
467 |
public void test62() { |
433 |
assertTrue("Camel pattern matching failure-1", |
468 |
assertCamelCase("NPE", "NullPointerException", true/* should match */); |
434 |
CharOperation.camelCaseMatch("NPE".toCharArray(), "NullPointerException".toCharArray())); |
469 |
assertCamelCase("NPExc", "NullPointerException", true/* should match */); |
435 |
assertTrue("Camel pattern matching failure-2", |
470 |
assertCamelCase("NPoE", "NullPointerException", true/* should match */); |
436 |
CharOperation.camelCaseMatch("NPExc".toCharArray(), "NullPointerException".toCharArray())); |
471 |
assertCamelCase("NuPExc", "NullPointerException", true/* should match */); |
437 |
assertTrue("Camel pattern matching failure-3", |
472 |
assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); |
438 |
!CharOperation.camelCaseMatch("NPoE".toCharArray(), "NullPointerException".toCharArray())); |
|
|
439 |
assertTrue("Camel pattern matching failure-4", |
440 |
!CharOperation.camelCaseMatch("NuPExc".toCharArray(), "NullPointerException".toCharArray())); |
441 |
} |
473 |
} |
442 |
public void test63() { |
474 |
public void test63() { |
443 |
assertTrue("Camel pattern matching failure-1", |
475 |
assertCamelCase("NPEX", "NullPointerException", false/* should not match */); |
444 |
!CharOperation.camelCaseMatch("NPEX".toCharArray(), "NullPointerException".toCharArray())); |
476 |
assertCamelCase("NPex", "NullPointerException", false/* should not match */); |
445 |
assertTrue("Camel pattern matching failure-2", |
477 |
assertCamelCase("npe", "NullPointerException", false/* should not match */); |
446 |
!CharOperation.camelCaseMatch("NPex".toCharArray(), "NullPointerException".toCharArray())); |
478 |
assertCamelCase("npe", "NPException", false/* should not match */); |
447 |
assertTrue("Camel pattern matching failure-3", |
479 |
assertCamelCase("NPointerE", "NullPointerException", true/* should match */); |
448 |
!CharOperation.camelCaseMatch("npe".toCharArray(), "NullPointerException".toCharArray())); |
480 |
assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); |
449 |
assertTrue("Camel pattern matching failure-4", |
|
|
450 |
!CharOperation.camelCaseMatch("npe".toCharArray(), "NPException".toCharArray())); |
451 |
assertTrue("Camel pattern matching failure-5", |
452 |
CharOperation.camelCaseMatch("NPointerE".toCharArray(), "NullPointerException".toCharArray())); |
453 |
} |
481 |
} |
454 |
public void test64() { |
482 |
public void test64() { |
455 |
assertTrue("Camel pattern matching failure-1", |
483 |
assertCamelCase("IAE", "IgnoreAllErrorHandler", true/* should match */); |
456 |
CharOperation.camelCaseMatch("IAE".toCharArray(), "IgnoreAllErrorHandler".toCharArray())); |
484 |
assertCamelCase("IAE", "IAnchorElement", true/* should match */); |
457 |
assertTrue("Camel pattern matching failure-2", |
485 |
assertCamelCase("IAnchorEleme", "IAnchorElement", true/* should match */); |
458 |
CharOperation.camelCaseMatch("IAE".toCharArray(), "IAnchorElement".toCharArray())); |
486 |
assertCamelCase("", "IAnchorElement", false/* should not match */); |
459 |
assertTrue("Camel pattern matching failure-3", |
487 |
assertCamelCase(null, "IAnchorElement", true/* should match */); |
460 |
CharOperation.camelCaseMatch("IAnchorEleme".toCharArray(), "IAnchorElement".toCharArray())); |
488 |
assertCamelCase("", "", true/* should match */); |
461 |
assertTrue("Camel pattern matching failure-4", |
489 |
assertCamelCase("IAnchor", null, false/* should not match */); |
462 |
!CharOperation.camelCaseMatch("".toCharArray(), "IAnchorElement".toCharArray())); |
490 |
assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); |
463 |
assertTrue("Camel pattern matching failure-5", |
|
|
464 |
CharOperation.camelCaseMatch(null, "IAnchorElement".toCharArray())); |
465 |
assertTrue("Camel pattern matching failure-6", |
466 |
CharOperation.camelCaseMatch("".toCharArray(), "".toCharArray())); |
467 |
assertTrue("Camel pattern matching failure-7", |
468 |
!CharOperation.camelCaseMatch("IAnchor".toCharArray(), null)); |
469 |
} |
491 |
} |
470 |
public void test65() { |
492 |
public void test65() { |
471 |
assertTrue("Camel pattern matching failure-1", |
493 |
assertCamelCase("iSCDCo", "invokeStringConcatenationDefaultConstructor", true/* should match */); |
472 |
CharOperation.camelCaseMatch("iSCDCo".toCharArray(), "invokeStringConcatenationDefaultConstructor".toCharArray())); |
494 |
assertCamelCase("inVOke", "invokeStringConcatenationDefaultConstructor", false/* should not match */); |
473 |
assertTrue("Camel pattern matching failure-2", |
495 |
assertCamelCase("i", "invokeStringConcatenationDefaultConstructor", true/* should match */); |
474 |
!CharOperation.camelCaseMatch("inVOke".toCharArray(), "invokeStringConcatenationDefaultConstructor".toCharArray())); |
496 |
assertCamelCase("I", "invokeStringConcatenationDefaultConstructor", false/* should not match */); |
475 |
assertTrue("Camel pattern matching failure-3", |
497 |
assertCamelCase("iStringCD", "invokeStringConcatenationDefaultConstructor", true/* should match */); |
476 |
CharOperation.camelCaseMatch("i".toCharArray(), "invokeStringConcatenationDefaultConstructor".toCharArray())); |
498 |
assertCamelCase("NPE", "NullPointerException/java.lang", true/* should match */); |
477 |
assertTrue("Camel pattern matching failure-4", |
499 |
assertCamelCase("NPE", "NullPointer/lang.Exception", false/* should not match */); |
478 |
!CharOperation.camelCaseMatch("I".toCharArray(), "invokeStringConcatenationDefaultConstructor".toCharArray())); |
500 |
assertCamelCase("NPE", "Null_Pointer$Exception", true/* should match */); |
479 |
assertTrue("Camel pattern matching failure-5", |
501 |
assertCamelCase("NPE", "Null1Pointer2Exception", true/* should match */); |
480 |
!CharOperation.camelCaseMatch("iStringCD".toCharArray(), "invokeStringConcatenationDefaultConstructor".toCharArray())); |
502 |
assertCamelCase("NPE", "Null.Pointer.Exception", false/* should not match */); |
481 |
assertTrue("Camel pattern matching failure-6", |
503 |
assertCamelCase("NPE", "aNullPointerException", false/* should not match */); |
482 |
CharOperation.camelCaseMatch("NPE".toCharArray(), "NullPointerException/java.lang".toCharArray())); |
504 |
assertCamelCase("nullP", "nullPointerException", true/* should match */); |
483 |
assertTrue("Camel pattern matching failure-7", |
505 |
assertCamelCase("nP", "nullPointerException", true/* should match */); |
484 |
!CharOperation.camelCaseMatch("NPE".toCharArray(), "NullPointer/lang.Exception".toCharArray())); |
506 |
assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); |
485 |
assertTrue("Camel pattern matching failure-8", |
507 |
} |
486 |
CharOperation.camelCaseMatch("NPE".toCharArray(), "Null_Pointer$Exception".toCharArray())); |
508 |
|
487 |
assertTrue("Camel pattern matching failure-9", |
509 |
/** |
488 |
CharOperation.camelCaseMatch("NPE".toCharArray(), "Null1Pointer2Exception".toCharArray())); |
510 |
* Bug 130390: CamelCase algorithm cleanup and improvement |
489 |
assertTrue("Camel pattern matching failure-10", |
511 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=130390" |
490 |
!CharOperation.camelCaseMatch("NPE".toCharArray(), "Null.Pointer.Exception".toCharArray())); |
512 |
* |
491 |
assertTrue("Camel pattern matching failure-11", |
513 |
*/ |
492 |
!CharOperation.camelCaseMatch("NPE".toCharArray(), "aNullPointerException".toCharArray())); |
514 |
public void test66() { |
493 |
assertTrue("Camel pattern matching failure-12", |
515 |
String[][] MATCHES = { |
494 |
CharOperation.camelCaseMatch("nullP".toCharArray(), "nullPointerException".toCharArray())); |
516 |
{"TZ","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
495 |
assertTrue("Camel pattern matching failure-13", |
517 |
{"TiZ","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
496 |
CharOperation.camelCaseMatch("nP".toCharArray(), "nullPointerException".toCharArray())); |
518 |
{"TiZon","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
|
|
519 |
{"TZon","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
520 |
{"TZone","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
521 |
{"TimeZone","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
522 |
{"TimeZ","TimeZ"}, //$NON-NLS-1$//$NON-NLS-2$ |
523 |
{"TZ","TimeZ"}, //$NON-NLS-1$//$NON-NLS-2$ |
524 |
{"T","TimeZ"}, //$NON-NLS-1$//$NON-NLS-2$ |
525 |
{"T","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
526 |
{"TZ","TZ"}, //$NON-NLS-1$//$NON-NLS-2$ |
527 |
{"aT","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
528 |
{"aTi","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
529 |
{"aTiZ","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
530 |
{"aTZ","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
531 |
{"aT","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
532 |
{"aTi","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
533 |
{"aTiZ","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
534 |
{"aTZ","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
535 |
}; |
536 |
|
537 |
for (int i = 0; i<MATCHES.length ; i++) { |
538 |
String[] match = MATCHES[i]; |
539 |
assertCamelCase(match[0], match[1], true/*should match*/); |
540 |
} |
541 |
|
542 |
String[][] MIS_MATCHES = { |
543 |
{"TZ","Timezone"}, //$NON-NLS-1$//$NON-NLS-2$ |
544 |
{"aTZ","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
545 |
{"aTZ","TZ"}, //$NON-NLS-1$//$NON-NLS-2$ |
546 |
{"arT","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
547 |
{"arTi","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
548 |
{"arTiZ","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
549 |
{"arTZ","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
550 |
{"aT","atimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ |
551 |
}; |
552 |
|
553 |
for (int i = 0; i<MIS_MATCHES.length ; i++) { |
554 |
String[] match = MIS_MATCHES[i]; |
555 |
assertCamelCase(match[0], match[1], false/*should not match*/); |
556 |
} |
557 |
assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); |
497 |
} |
558 |
} |
498 |
public static Class testClass() { |
559 |
public static Class testClass() { |
499 |
return UtilTest.class; |
560 |
return UtilTest.class; |