| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.test_support; | 8 library engine.test_support; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 10 import 'package:analyzer/src/generated/java_core.dart'; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 * Assert that the number of errors that have been gathered matches the number
of errors that are | 100 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 101 * given and that they have the expected error codes. The order in which the e
rrors were gathered | 101 * given and that they have the expected error codes. The order in which the e
rrors were gathered |
| 102 * is ignored. | 102 * is ignored. |
| 103 * | 103 * |
| 104 * @param expectedErrorCodes the error codes of the errors that should have be
en gathered | 104 * @param expectedErrorCodes the error codes of the errors that should have be
en gathered |
| 105 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 105 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 106 * expected | 106 * expected |
| 107 */ | 107 */ |
| 108 void assertErrors2(List<ErrorCode> expectedErrorCodes) { | 108 void assertErrors2(List<ErrorCode> expectedErrorCodes) { |
| 109 JavaStringBuilder builder = new JavaStringBuilder(); | 109 JavaStringBuilder builder = new JavaStringBuilder(); |
| 110 // |
| 111 // Verify that the expected error codes have a non-empty message. |
| 112 // |
| 110 for (ErrorCode errorCode in expectedErrorCodes) { | 113 for (ErrorCode errorCode in expectedErrorCodes) { |
| 111 JUnitTestCase.assertFalseMsg("Empty error code message", errorCode.message
.isEmpty); | 114 JUnitTestCase.assertFalseMsg("Empty error code message", errorCode.message
.isEmpty); |
| 112 } | 115 } |
| 116 // |
| 117 // Compute the expected number of each type of error. |
| 118 // |
| 113 Map<ErrorCode, int> expectedCounts = new Map<ErrorCode, int>(); | 119 Map<ErrorCode, int> expectedCounts = new Map<ErrorCode, int>(); |
| 114 for (ErrorCode code in expectedErrorCodes) { | 120 for (ErrorCode code in expectedErrorCodes) { |
| 115 int count = expectedCounts[code]; | 121 int count = expectedCounts[code]; |
| 116 if (count == null) { | 122 if (count == null) { |
| 117 count = 1; | 123 count = 1; |
| 118 } else { | 124 } else { |
| 119 count = count + 1; | 125 count = count + 1; |
| 120 } | 126 } |
| 121 expectedCounts[code] = count; | 127 expectedCounts[code] = count; |
| 122 } | 128 } |
| 129 // |
| 130 // Compute the actual number of each type of error. |
| 131 // |
| 123 Map<ErrorCode, List<AnalysisError>> errorsByCode = new Map<ErrorCode, List<A
nalysisError>>(); | 132 Map<ErrorCode, List<AnalysisError>> errorsByCode = new Map<ErrorCode, List<A
nalysisError>>(); |
| 124 for (AnalysisError error in _errors) { | 133 for (AnalysisError error in _errors) { |
| 125 ErrorCode code = error.errorCode; | 134 ErrorCode code = error.errorCode; |
| 126 List<AnalysisError> list = errorsByCode[code]; | 135 List<AnalysisError> list = errorsByCode[code]; |
| 127 if (list == null) { | 136 if (list == null) { |
| 128 list = new List<AnalysisError>(); | 137 list = new List<AnalysisError>(); |
| 129 errorsByCode[code] = list; | 138 errorsByCode[code] = list; |
| 130 } | 139 } |
| 131 list.add(error); | 140 list.add(error); |
| 132 } | 141 } |
| 142 // |
| 143 // Compare the expected and actual number of each type of error. |
| 144 // |
| 133 for (MapEntry<ErrorCode, int> entry in getMapEntrySet(expectedCounts)) { | 145 for (MapEntry<ErrorCode, int> entry in getMapEntrySet(expectedCounts)) { |
| 134 ErrorCode code = entry.getKey(); | 146 ErrorCode code = entry.getKey(); |
| 135 int expectedCount = entry.getValue(); | 147 int expectedCount = entry.getValue(); |
| 136 int actualCount; | 148 int actualCount; |
| 137 List<AnalysisError> list = errorsByCode.remove(code); | 149 List<AnalysisError> list = errorsByCode.remove(code); |
| 138 if (list == null) { | 150 if (list == null) { |
| 139 actualCount = 0; | 151 actualCount = 0; |
| 140 } else { | 152 } else { |
| 141 actualCount = list.length; | 153 actualCount = list.length; |
| 142 } | 154 } |
| 143 if (actualCount != expectedCount) { | 155 if (actualCount != expectedCount) { |
| 144 if (builder.length == 0) { | 156 if (builder.length == 0) { |
| 145 builder.append("Expected "); | 157 builder.append("Expected "); |
| 146 } else { | 158 } else { |
| 147 builder.append("; "); | 159 builder.append("; "); |
| 148 } | 160 } |
| 149 builder.append(expectedCount); | 161 builder.append(expectedCount); |
| 150 builder.append(" errors of type "); | 162 builder.append(" errors of type "); |
| 151 builder.append("${code.runtimeType.toString()}.${code}"); | 163 builder.append("${code.runtimeType.toString()}.${code}"); |
| 152 builder.append(", found "); | 164 builder.append(", found "); |
| 153 builder.append(actualCount); | 165 builder.append(actualCount); |
| 154 } | 166 } |
| 155 } | 167 } |
| 168 // |
| 169 // Check that there are no more errors in the actual-errors map, otherwise,
record message. |
| 170 // |
| 156 for (MapEntry<ErrorCode, List<AnalysisError>> entry in getMapEntrySet(errors
ByCode)) { | 171 for (MapEntry<ErrorCode, List<AnalysisError>> entry in getMapEntrySet(errors
ByCode)) { |
| 157 ErrorCode code = entry.getKey(); | 172 ErrorCode code = entry.getKey(); |
| 158 List<AnalysisError> actualErrors = entry.getValue(); | 173 List<AnalysisError> actualErrors = entry.getValue(); |
| 159 int actualCount = actualErrors.length; | 174 int actualCount = actualErrors.length; |
| 160 if (builder.length == 0) { | 175 if (builder.length == 0) { |
| 161 builder.append("Expected "); | 176 builder.append("Expected "); |
| 162 } else { | 177 } else { |
| 163 builder.append("; "); | 178 builder.append("; "); |
| 164 } | 179 } |
| 165 builder.append("0 errors of type "); | 180 builder.append("0 errors of type "); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected
: ${expected}", false); | 524 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected
: ${expected}", false); |
| 510 } else { | 525 } else { |
| 511 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is
: ${actual}", false); | 526 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is
: ${actual}", false); |
| 512 } | 527 } |
| 513 } | 528 } |
| 514 int diffPos = getDiffPos(expected, actual); | 529 int diffPos = getDiffPos(expected, actual); |
| 515 if (diffPos != -1) { | 530 if (diffPos != -1) { |
| 516 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); | 531 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); |
| 517 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); | 532 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); |
| 518 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri
ng(diffPos, diffAfter)}"; | 533 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri
ng(diffPos, diffAfter)}"; |
| 534 // use detailed message |
| 519 String message = "Content not as expected: is\n${actual}\nDiffers at pos $
{diffPos}: ${diffStr}\nexpected:\n${expected}"; | 535 String message = "Content not as expected: is\n${actual}\nDiffers at pos $
{diffPos}: ${diffStr}\nexpected:\n${expected}"; |
| 520 JUnitTestCase.assertEqualsMsg(message, expected, actual); | 536 JUnitTestCase.assertEqualsMsg(message, expected, actual); |
| 521 } | 537 } |
| 522 } | 538 } |
| 523 | 539 |
| 524 /** | 540 /** |
| 525 * Assert that the given list is non-`null` and has exactly expected elements. | 541 * Assert that the given list is non-`null` and has exactly expected elements. |
| 526 * | 542 * |
| 527 * @param list the list being tested | 543 * @param list the list being tested |
| 528 * @param expectedElements the expected elements | 544 * @param expectedElements the expected elements |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 return trampoline(target, arguments[0], arguments[1]); | 886 return trampoline(target, arguments[0], arguments[1]); |
| 871 case 3: | 887 case 3: |
| 872 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 888 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 873 case 4: | 889 case 4: |
| 874 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 890 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 875 default: | 891 default: |
| 876 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 892 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 877 } | 893 } |
| 878 } | 894 } |
| 879 } | 895 } |
| OLD | NEW |