| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 | 3 |
| 4 library engine.test_support; | 4 library engine.test_support; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:uri'; |
| 7 import 'package:analyzer-experimental/src/generated/java_core.dart'; | 8 import 'package:analyzer-experimental/src/generated/java_core.dart'; |
| 8 import 'package:analyzer-experimental/src/generated/java_engine.dart'; | 9 import 'package:analyzer-experimental/src/generated/java_engine.dart'; |
| 9 import 'package:analyzer-experimental/src/generated/java_junit.dart'; | 10 import 'package:analyzer-experimental/src/generated/java_junit.dart'; |
| 10 import 'package:analyzer-experimental/src/generated/source.dart'; | 11 import 'package:analyzer-experimental/src/generated/source.dart'; |
| 11 import 'package:analyzer-experimental/src/generated/error.dart'; | 12 import 'package:analyzer-experimental/src/generated/error.dart'; |
| 12 import 'package:analyzer-experimental/src/generated/scanner.dart'; | 13 import 'package:analyzer-experimental/src/generated/scanner.dart'; |
| 14 import 'package:analyzer-experimental/src/generated/element.dart' show Interface
Type, MethodElement, PropertyAccessorElement; |
| 13 import 'package:unittest/unittest.dart' as _ut; | 15 import 'package:unittest/unittest.dart' as _ut; |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Instances of the class {@code GatheringErrorListener} implement an error list
ener that collects | 18 * Instances of the class {@code GatheringErrorListener} implement an error list
ener that collects |
| 17 * all of the errors passed to it for later examination. | 19 * all of the errors passed to it for later examination. |
| 18 */ | 20 */ |
| 19 class GatheringErrorListener implements AnalysisErrorListener { | 21 class GatheringErrorListener implements AnalysisErrorListener { |
| 20 /** | 22 /** |
| 21 * The source being parsed. | 23 * The source being parsed. |
| 22 */ | 24 */ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 */ | 37 */ |
| 36 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); | 38 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); |
| 37 /** | 39 /** |
| 38 * An empty array of errors used when no errors are expected. | 40 * An empty array of errors used when no errors are expected. |
| 39 */ | 41 */ |
| 40 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0); | 42 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0); |
| 41 /** | 43 /** |
| 42 * Initialize a newly created error listener to collect errors. | 44 * Initialize a newly created error listener to collect errors. |
| 43 */ | 45 */ |
| 44 GatheringErrorListener() : super() { | 46 GatheringErrorListener() : super() { |
| 45 _jtd_constructor_258_impl(); | 47 _jtd_constructor_297_impl(); |
| 46 } | 48 } |
| 47 _jtd_constructor_258_impl() { | 49 _jtd_constructor_297_impl() { |
| 48 } | 50 } |
| 49 /** | 51 /** |
| 50 * Initialize a newly created error listener to collect errors. | 52 * Initialize a newly created error listener to collect errors. |
| 51 */ | 53 */ |
| 52 GatheringErrorListener.con1(String rawSource2) { | 54 GatheringErrorListener.con1(String rawSource2) { |
| 53 _jtd_constructor_259_impl(rawSource2); | 55 _jtd_constructor_298_impl(rawSource2); |
| 54 } | 56 } |
| 55 _jtd_constructor_259_impl(String rawSource2) { | 57 _jtd_constructor_298_impl(String rawSource2) { |
| 56 this._rawSource = rawSource2; | 58 this._rawSource = rawSource2; |
| 57 this._markedSource = rawSource2; | 59 this._markedSource = rawSource2; |
| 58 } | 60 } |
| 59 /** | 61 /** |
| 60 * Assert that the number of errors that have been gathered matches the number
of errors that are | 62 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 61 * given and that they have the expected error codes and locations. The order
in which the errors | 63 * given and that they have the expected error codes and locations. The order
in which the errors |
| 62 * were gathered is ignored. | 64 * were gathered is ignored. |
| 63 * @param errorCodes the errors that should have been gathered | 65 * @param errorCodes the errors that should have been gathered |
| 64 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 66 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 65 * expected or if they do not have the same codes and locations | 67 * expected or if they do not have the same codes and locations |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 int expectedCount = entry.getValue(); | 115 int expectedCount = entry.getValue(); |
| 114 int actualCount; | 116 int actualCount; |
| 115 List<AnalysisError> list = errorsByCode.remove(code); | 117 List<AnalysisError> list = errorsByCode.remove(code); |
| 116 if (list == null) { | 118 if (list == null) { |
| 117 actualCount = 0; | 119 actualCount = 0; |
| 118 } else { | 120 } else { |
| 119 actualCount = list.length; | 121 actualCount = list.length; |
| 120 } | 122 } |
| 121 if (actualCount != expectedCount) { | 123 if (actualCount != expectedCount) { |
| 122 if (builder.length == 0) { | 124 if (builder.length == 0) { |
| 123 builder.add("Expected "); | 125 builder.write("Expected "); |
| 124 } else { | 126 } else { |
| 125 builder.add("; "); | 127 builder.write("; "); |
| 126 } | 128 } |
| 127 builder.add(expectedCount); | 129 builder.write(expectedCount); |
| 128 builder.add(" errors of type "); | 130 builder.write(" errors of type "); |
| 129 builder.add(code); | 131 builder.write(code); |
| 130 builder.add(", found "); | 132 builder.write(", found "); |
| 131 builder.add(actualCount); | 133 builder.write(actualCount); |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 for (MapEntry<ErrorCode, List<AnalysisError>> entry in getMapEntrySet(errors
ByCode)) { | 136 for (MapEntry<ErrorCode, List<AnalysisError>> entry in getMapEntrySet(errors
ByCode)) { |
| 135 ErrorCode code = entry.getKey(); | 137 ErrorCode code = entry.getKey(); |
| 136 List<AnalysisError> actualErrors = entry.getValue(); | 138 List<AnalysisError> actualErrors = entry.getValue(); |
| 137 int actualCount = actualErrors.length; | 139 int actualCount = actualErrors.length; |
| 138 if (builder.length == 0) { | 140 if (builder.length == 0) { |
| 139 builder.add("Expected "); | 141 builder.write("Expected "); |
| 140 } else { | 142 } else { |
| 141 builder.add("; "); | 143 builder.write("; "); |
| 142 } | 144 } |
| 143 builder.add("0 errors of type "); | 145 builder.write("0 errors of type "); |
| 144 builder.add(code); | 146 builder.write(code); |
| 145 builder.add(", found "); | 147 builder.write(", found "); |
| 146 builder.add(actualCount); | 148 builder.write(actualCount); |
| 147 builder.add(" ("); | 149 builder.write(" ("); |
| 148 for (int i = 0; i < actualErrors.length; i++) { | 150 for (int i = 0; i < actualErrors.length; i++) { |
| 149 AnalysisError error = actualErrors[i]; | 151 AnalysisError error = actualErrors[i]; |
| 150 if (i > 0) { | 152 if (i > 0) { |
| 151 builder.add(", "); | 153 builder.write(", "); |
| 152 } | 154 } |
| 153 builder.add(error.offset); | 155 builder.write(error.offset); |
| 154 } | 156 } |
| 155 builder.add(")"); | 157 builder.write(")"); |
| 156 } | 158 } |
| 157 if (builder.length > 0) { | 159 if (builder.length > 0) { |
| 158 JUnitTestCase.fail(builder.toString()); | 160 JUnitTestCase.fail(builder.toString()); |
| 159 } | 161 } |
| 160 } | 162 } |
| 161 /** | 163 /** |
| 162 * Assert that the number of errors that have been gathered matches the number
of severities that | 164 * Assert that the number of errors that have been gathered matches the number
of severities that |
| 163 * are given and that there are the same number of errors and warnings as spec
ified by the | 165 * are given and that there are the same number of errors and warnings as spec
ified by the |
| 164 * argument. The order in which the errors were gathered is ignored. | 166 * argument. The order in which the errors were gathered is ignored. |
| 165 * @param expectedSeverities the severities of the errors that should have bee
n gathered | 167 * @param expectedSeverities the severities of the errors that should have bee
n gathered |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 * is ignored. | 267 * is ignored. |
| 266 * @param errorCodes the errors that should have been gathered | 268 * @param errorCodes the errors that should have been gathered |
| 267 * @throws AssertionFailedError with | 269 * @throws AssertionFailedError with |
| 268 */ | 270 */ |
| 269 void fail(List<AnalysisError> expectedErrors) { | 271 void fail(List<AnalysisError> expectedErrors) { |
| 270 PrintStringWriter writer = new PrintStringWriter(); | 272 PrintStringWriter writer = new PrintStringWriter(); |
| 271 writer.print("Expected "); | 273 writer.print("Expected "); |
| 272 writer.print(expectedErrors.length); | 274 writer.print(expectedErrors.length); |
| 273 writer.print(" errors:"); | 275 writer.print(" errors:"); |
| 274 for (AnalysisError error in expectedErrors) { | 276 for (AnalysisError error in expectedErrors) { |
| 275 Source source9 = error.source; | 277 Source source11 = error.source; |
| 276 LineInfo lineInfo = _lineInfoMap[source9]; | 278 LineInfo lineInfo = _lineInfoMap[source11]; |
| 277 writer.println(); | 279 writer.println(); |
| 278 if (lineInfo == null) { | 280 if (lineInfo == null) { |
| 279 int offset9 = error.offset; | 281 int offset10 = error.offset; |
| 280 writer.printf(" %s %s (%d..%d)", [source9 == null ? "" : source9.shortN
ame, error.errorCode, offset9, offset9 + error.length]); | 282 writer.printf(" %s %s (%d..%d)", [source11 == null ? "" : source11.shor
tName, error.errorCode, offset10, offset10 + error.length]); |
| 281 } else { | 283 } else { |
| 282 LineInfo_Location location = lineInfo.getLocation(error.offset); | 284 LineInfo_Location location = lineInfo.getLocation(error.offset); |
| 283 writer.printf(" %s %s (%d, %d/%d)", [source9 == null ? "" : source9.sho
rtName, error.errorCode, location.lineNumber, location.columnNumber, error.lengt
h]); | 285 writer.printf(" %s %s (%d, %d/%d)", [source11 == null ? "" : source11.s
hortName, error.errorCode, location.lineNumber, location.columnNumber, error.len
gth]); |
| 284 } | 286 } |
| 285 } | 287 } |
| 286 writer.println(); | 288 writer.println(); |
| 287 writer.print("found "); | 289 writer.print("found "); |
| 288 writer.print(_errors.length); | 290 writer.print(_errors.length); |
| 289 writer.print(" errors:"); | 291 writer.print(" errors:"); |
| 290 for (AnalysisError error in _errors) { | 292 for (AnalysisError error in _errors) { |
| 291 Source source10 = error.source; | 293 Source source12 = error.source; |
| 292 LineInfo lineInfo = _lineInfoMap[source10]; | 294 LineInfo lineInfo = _lineInfoMap[source12]; |
| 293 writer.println(); | 295 writer.println(); |
| 294 if (lineInfo == null) { | 296 if (lineInfo == null) { |
| 295 int offset10 = error.offset; | 297 int offset11 = error.offset; |
| 296 writer.printf(" %s %s (%d..%d): %s", [source10 == null ? "" : source10.
shortName, error.errorCode, offset10, offset10 + error.length, error.message]); | 298 writer.printf(" %s %s (%d..%d): %s", [source12 == null ? "" : source12.
shortName, error.errorCode, offset11, offset11 + error.length, error.message]); |
| 297 } else { | 299 } else { |
| 298 LineInfo_Location location = lineInfo.getLocation(error.offset); | 300 LineInfo_Location location = lineInfo.getLocation(error.offset); |
| 299 writer.printf(" %s %s (%d, %d/%d): %s", [source10 == null ? "" : source
10.shortName, error.errorCode, location.lineNumber, location.columnNumber, error
.length, error.message]); | 301 writer.printf(" %s %s (%d, %d/%d): %s", [source12 == null ? "" : source
12.shortName, error.errorCode, location.lineNumber, location.columnNumber, error
.length, error.message]); |
| 300 } | 302 } |
| 301 } | 303 } |
| 302 JUnitTestCase.fail(writer.toString()); | 304 JUnitTestCase.fail(writer.toString()); |
| 303 } | 305 } |
| 304 /** | 306 /** |
| 305 * Search through the given list of errors for an error that is equal to the t
arget error. If one | 307 * Search through the given list of errors for an error that is equal to the t
arget error. If one |
| 306 * is found, remove it from the list and return {@code true}, otherwise return
{@code false}without modifying the list. | 308 * is found, remove it from the list and return {@code true}, otherwise return
{@code false}without modifying the list. |
| 307 * @param errors the errors through which we are searching | 309 * @param errors the errors through which we are searching |
| 308 * @param targetError the error being searched for | 310 * @param targetError the error being searched for |
| 309 * @return {@code true} if the error is found and removed from the list | 311 * @return {@code true} if the error is found and removed from the list |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 * Assert that the array of actual values contain exactly the same values as t
hose in the array of | 346 * Assert that the array of actual values contain exactly the same values as t
hose in the array of |
| 345 * expected value, with the exception that the order of the elements is not re
quired to be the | 347 * expected value, with the exception that the order of the elements is not re
quired to be the |
| 346 * same. | 348 * same. |
| 347 * @param expectedValues the values that are expected to be found | 349 * @param expectedValues the values that are expected to be found |
| 348 * @param actualValues the actual values that are being compared against the e
xpected values | 350 * @param actualValues the actual values that are being compared against the e
xpected values |
| 349 */ | 351 */ |
| 350 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { | 352 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { |
| 351 JUnitTestCase.assertNotNull(actualValues); | 353 JUnitTestCase.assertNotNull(actualValues); |
| 352 int expectedLength = expectedValues.length; | 354 int expectedLength = expectedValues.length; |
| 353 JUnitTestCase.assertEquals(expectedLength, actualValues.length); | 355 JUnitTestCase.assertEquals(expectedLength, actualValues.length); |
| 354 List<bool> found = new List<bool>(expectedLength); | 356 List<bool> found = new List<bool>.filled(expectedLength, false); |
| 355 for (int i = 0; i < expectedLength; i++) { | 357 for (int i = 0; i < expectedLength; i++) { |
| 356 found[i] = false; | 358 found[i] = false; |
| 357 } | 359 } |
| 358 for (Object actualValue in actualValues) { | 360 for (Object actualValue in actualValues) { |
| 359 bool wasExpected = false; | 361 bool wasExpected = false; |
| 360 for (int i = 0; i < expectedLength; i++) { | 362 for (int i = 0; i < expectedLength; i++) { |
| 361 if (!found[i] && expectedValues[i] == actualValue) { | 363 if (!found[i] && expectedValues[i] == actualValue) { |
| 362 found[i] = true; | 364 found[i] = true; |
| 363 wasExpected = true; | 365 wasExpected = true; |
| 364 break; | 366 break; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 * Assert that the given object is an instance of the expected class. | 466 * Assert that the given object is an instance of the expected class. |
| 465 * @param expectedClass the class that the object is expected to be an instanc
e of | 467 * @param expectedClass the class that the object is expected to be an instanc
e of |
| 466 * @param object the object being tested | 468 * @param object the object being tested |
| 467 * @return the object that was being tested | 469 * @return the object that was being tested |
| 468 * @throws Exception if the object is not an instance of the expected class | 470 * @throws Exception if the object is not an instance of the expected class |
| 469 */ | 471 */ |
| 470 static Object assertInstanceOf(Type expectedClass, Object object) { | 472 static Object assertInstanceOf(Type expectedClass, Object object) { |
| 471 if (!isInstanceOf(object, expectedClass)) { | 473 if (!isInstanceOf(object, expectedClass)) { |
| 472 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun
d ${(object == null ? "null" : object.runtimeType.toString())}"); | 474 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun
d ${(object == null ? "null" : object.runtimeType.toString())}"); |
| 473 } | 475 } |
| 474 return (object as Object); | 476 return object as Object; |
| 475 } | 477 } |
| 476 /** | 478 /** |
| 477 * Assert that the given array is non-{@code null} and has the expected number
of elements. | 479 * Assert that the given array is non-{@code null} and has the expected number
of elements. |
| 478 * @param expectedLength the expected number of elements | 480 * @param expectedLength the expected number of elements |
| 479 * @param array the array being tested | 481 * @param array the array being tested |
| 480 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected number | 482 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected number |
| 481 * of elements | 483 * of elements |
| 482 */ | 484 */ |
| 483 static void assertLength(int expectedLength, List<Object> array) { | 485 static void assertLength(int expectedLength, List<Object> array) { |
| 484 if (array == null) { | 486 if (array == null) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { | 559 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { |
| 558 diffPos = i; | 560 diffPos = i; |
| 559 break; | 561 break; |
| 560 } | 562 } |
| 561 } | 563 } |
| 562 if (diffPos == -1 && str1.length != str2.length) { | 564 if (diffPos == -1 && str1.length != str2.length) { |
| 563 diffPos = len1; | 565 diffPos = len1; |
| 564 } | 566 } |
| 565 return diffPos; | 567 return diffPos; |
| 566 } | 568 } |
| 569 /** |
| 570 * Return the getter in the given type with the given name. Inherited getters
are ignored. |
| 571 * @param type the type in which the getter is declared |
| 572 * @param getterName the name of the getter to be returned |
| 573 * @return the property accessor element representing the getter with the give
n name |
| 574 */ |
| 575 PropertyAccessorElement getGetter(InterfaceType type, String getterName) { |
| 576 for (PropertyAccessorElement accessor in type.element.accessors) { |
| 577 if (accessor.isGetter() && accessor.name == getterName) { |
| 578 return accessor; |
| 579 } |
| 580 } |
| 581 JUnitTestCase.fail("Could not find getter named ${getterName} in ${type.name
}"); |
| 582 return null; |
| 583 } |
| 584 /** |
| 585 * Return the method in the given type with the given name. Inherited methods
are ignored. |
| 586 * @param type the type in which the method is declared |
| 587 * @param methodName the name of the method to be returned |
| 588 * @return the method element representing the method with the given name |
| 589 */ |
| 590 MethodElement getMethod(InterfaceType type, String methodName) { |
| 591 for (MethodElement method in type.element.methods) { |
| 592 if (method.name == methodName) { |
| 593 return method; |
| 594 } |
| 595 } |
| 596 JUnitTestCase.fail("Could not find method named ${methodName} in ${type.name
}"); |
| 597 return null; |
| 598 } |
| 567 static dartSuite() { | 599 static dartSuite() { |
| 568 _ut.group('EngineTestCase', () { | 600 _ut.group('EngineTestCase', () { |
| 569 }); | 601 }); |
| 570 } | 602 } |
| 571 } | 603 } |
| 572 main() { | 604 main() { |
| 573 } | 605 } |
| 574 | 606 |
| 575 class TestSource implements Source { | 607 class TestSource implements Source { |
| 576 bool operator ==(Object object) { | 608 bool operator ==(Object object) { |
| 577 return this == object; | 609 return this == object; |
| 578 } | 610 } |
| 579 void getContents(Source_ContentReceiver receiver) { | 611 void getContents(Source_ContentReceiver receiver) { |
| 580 throw new UnsupportedOperationException(); | 612 throw new UnsupportedOperationException(); |
| 581 } | 613 } |
| 582 String get fullName { | 614 String get fullName { |
| 583 throw new UnsupportedOperationException(); | 615 throw new UnsupportedOperationException(); |
| 584 } | 616 } |
| 585 String get shortName { | 617 String get shortName { |
| 586 throw new UnsupportedOperationException(); | 618 throw new UnsupportedOperationException(); |
| 587 } | 619 } |
| 620 String get encoding { |
| 621 throw new UnsupportedOperationException(); |
| 622 } |
| 623 bool exists() => true; |
| 588 bool isInSystemLibrary() { | 624 bool isInSystemLibrary() { |
| 589 throw new UnsupportedOperationException(); | 625 throw new UnsupportedOperationException(); |
| 590 } | 626 } |
| 591 Source resolve(String uri) { | 627 Source resolve(String uri) { |
| 592 throw new UnsupportedOperationException(); | 628 throw new UnsupportedOperationException(); |
| 593 } | 629 } |
| 630 Source resolveRelative(Uri uri) { |
| 631 throw new UnsupportedOperationException(); |
| 632 } |
| 594 } | 633 } |
| 595 | 634 |
| 596 /** | 635 /** |
| 597 * Wrapper around [Function] which should be called with [target] and [arguments
]. | 636 * Wrapper around [Function] which should be called with [target] and [arguments
]. |
| 598 */ | 637 */ |
| 599 class MethodTrampoline { | 638 class MethodTrampoline { |
| 600 int parameterCount; | 639 int parameterCount; |
| 601 Function trampoline; | 640 Function trampoline; |
| 602 MethodTrampoline(this.parameterCount, this.trampoline); | 641 MethodTrampoline(this.parameterCount, this.trampoline); |
| 603 Object invoke(target, List arguments) { | 642 Object invoke(target, List arguments) { |
| 604 if (arguments.length != parameterCount) { | 643 if (arguments.length != parameterCount) { |
| 605 throw new IllegalArgumentException("${arguments.length} != $parameterCount
"); | 644 throw new IllegalArgumentException("${arguments.length} != $parameterCount
"); |
| 606 } | 645 } |
| 607 switch (parameterCount) { | 646 switch (parameterCount) { |
| 608 case 0: | 647 case 0: |
| 609 return trampoline(target); | 648 return trampoline(target); |
| 610 case 1: | 649 case 1: |
| 611 return trampoline(target, arguments[0]); | 650 return trampoline(target, arguments[0]); |
| 612 case 2: | 651 case 2: |
| 613 return trampoline(target, arguments[0], arguments[1]); | 652 return trampoline(target, arguments[0], arguments[1]); |
| 614 case 3: | 653 case 3: |
| 615 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 654 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 616 case 4: | 655 case 4: |
| 617 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 656 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 618 default: | 657 default: |
| 619 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 658 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 620 } | 659 } |
| 621 } | 660 } |
| 622 } | 661 } |
| OLD | NEW |