| 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 'package:analyzer_experimental/src/generated/java_core.dart'; | 7 import 'package:analyzer_experimental/src/generated/java_core.dart'; |
| 8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; | 8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; |
| 9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; | 9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
| 10 import 'package:analyzer_experimental/src/generated/source.dart'; | 10 import 'package:analyzer_experimental/src/generated/source.dart'; |
| 11 import 'package:analyzer_experimental/src/generated/error.dart'; | 11 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 12 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 12 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 13 import 'package:analyzer_experimental/src/generated/element.dart' show Interface
Type, MethodElement, PropertyAccessorElement; | 13 import 'package:analyzer_experimental/src/generated/element.dart' show Interface
Type, MethodElement, PropertyAccessorElement; |
| 14 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo
ntext, AnalysisContextImpl; | 14 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo
ntext, AnalysisContextImpl, RecordingErrorListener; |
| 15 import 'package:unittest/unittest.dart' as _ut; | 15 import 'package:unittest/unittest.dart' as _ut; |
| 16 | 16 |
| 17 |
| 17 /** | 18 /** |
| 18 * Instances of the class {@code GatheringErrorListener} implement an error list
ener that collects | 19 * Instances of the class {@code GatheringErrorListener} implement an error list
ener that collects |
| 19 * all of the errors passed to it for later examination. | 20 * all of the errors passed to it for later examination. |
| 20 */ | 21 */ |
| 21 class GatheringErrorListener implements AnalysisErrorListener { | 22 class GatheringErrorListener implements AnalysisErrorListener { |
| 23 |
| 22 /** | 24 /** |
| 23 * The source being parsed. | 25 * The source being parsed. |
| 24 */ | 26 */ |
| 25 String _rawSource; | 27 String _rawSource; |
| 28 |
| 26 /** | 29 /** |
| 27 * The source being parsed after inserting a marker at the beginning and end o
f the range of the | 30 * The source being parsed after inserting a marker at the beginning and end o
f the range of the |
| 28 * most recent error. | 31 * most recent error. |
| 29 */ | 32 */ |
| 30 String _markedSource; | 33 String _markedSource; |
| 34 |
| 31 /** | 35 /** |
| 32 * A list containing the errors that were collected. | 36 * A list containing the errors that were collected. |
| 33 */ | 37 */ |
| 34 List<AnalysisError> _errors = new List<AnalysisError>(); | 38 List<AnalysisError> _errors = new List<AnalysisError>(); |
| 39 |
| 35 /** | 40 /** |
| 36 * A table mapping sources to the line information for the source. | 41 * A table mapping sources to the line information for the source. |
| 37 */ | 42 */ |
| 38 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); | 43 Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>(); |
| 44 |
| 39 /** | 45 /** |
| 40 * An empty array of errors used when no errors are expected. | 46 * An empty array of errors used when no errors are expected. |
| 41 */ | 47 */ |
| 42 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0); | 48 static List<AnalysisError> _NO_ERRORS = new List<AnalysisError>(0); |
| 49 |
| 43 /** | 50 /** |
| 44 * Initialize a newly created error listener to collect errors. | 51 * Initialize a newly created error listener to collect errors. |
| 45 */ | 52 */ |
| 46 GatheringErrorListener() : super() { | 53 GatheringErrorListener() : super() { |
| 47 _jtd_constructor_349_impl(); | 54 _jtd_constructor_357_impl(); |
| 48 } | 55 } |
| 49 _jtd_constructor_349_impl() { | 56 _jtd_constructor_357_impl() { |
| 50 } | 57 } |
| 58 |
| 51 /** | 59 /** |
| 52 * Initialize a newly created error listener to collect errors. | 60 * Initialize a newly created error listener to collect errors. |
| 53 */ | 61 */ |
| 54 GatheringErrorListener.con1(String rawSource2) { | 62 GatheringErrorListener.con1(String rawSource2) { |
| 55 _jtd_constructor_350_impl(rawSource2); | 63 _jtd_constructor_358_impl(rawSource2); |
| 56 } | 64 } |
| 57 _jtd_constructor_350_impl(String rawSource2) { | 65 _jtd_constructor_358_impl(String rawSource2) { |
| 58 this._rawSource = rawSource2; | 66 this._rawSource = rawSource2; |
| 59 this._markedSource = rawSource2; | 67 this._markedSource = rawSource2; |
| 60 } | 68 } |
| 69 |
| 70 /** |
| 71 * Add all of the errors recorded by the given listener to this listener. |
| 72 * @param listener the listener that has recorded the errors to be added |
| 73 */ |
| 74 void addAll(RecordingErrorListener listener) { |
| 75 for (AnalysisError error in listener.errors) { |
| 76 onError(error); |
| 77 } |
| 78 } |
| 79 |
| 61 /** | 80 /** |
| 62 * Assert that the number of errors that have been gathered matches the number
of errors that are | 81 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 63 * given and that they have the expected error codes and locations. The order
in which the errors | 82 * given and that they have the expected error codes and locations. The order
in which the errors |
| 64 * were gathered is ignored. | 83 * were gathered is ignored. |
| 65 * @param errorCodes the errors that should have been gathered | 84 * @param errorCodes the errors that should have been gathered |
| 66 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 85 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 67 * expected or if they do not have the same codes and locations | 86 * expected or if they do not have the same codes and locations |
| 68 */ | 87 */ |
| 69 void assertErrors(List<AnalysisError> expectedErrors) { | 88 void assertErrors(List<AnalysisError> expectedErrors) { |
| 70 if (_errors.length != expectedErrors.length) { | 89 if (_errors.length != expectedErrors.length) { |
| 71 fail(expectedErrors); | 90 fail(expectedErrors); |
| 72 } | 91 } |
| 73 List<AnalysisError> remainingErrors = new List<AnalysisError>(); | 92 List<AnalysisError> remainingErrors = new List<AnalysisError>(); |
| 74 for (AnalysisError error in expectedErrors) { | 93 for (AnalysisError error in expectedErrors) { |
| 75 remainingErrors.add(error); | 94 remainingErrors.add(error); |
| 76 } | 95 } |
| 77 for (AnalysisError error in _errors) { | 96 for (AnalysisError error in _errors) { |
| 78 if (!foundAndRemoved(remainingErrors, error)) { | 97 if (!foundAndRemoved(remainingErrors, error)) { |
| 79 fail(expectedErrors); | 98 fail(expectedErrors); |
| 80 } | 99 } |
| 81 } | 100 } |
| 82 } | 101 } |
| 102 |
| 83 /** | 103 /** |
| 84 * Assert that the number of errors that have been gathered matches the number
of errors that are | 104 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 85 * given and that they have the expected error codes. The order in which the e
rrors were gathered | 105 * given and that they have the expected error codes. The order in which the e
rrors were gathered |
| 86 * is ignored. | 106 * is ignored. |
| 87 * @param expectedErrorCodes the error codes of the errors that should have be
en gathered | 107 * @param expectedErrorCodes the error codes of the errors that should have be
en gathered |
| 88 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 108 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 89 * expected | 109 * expected |
| 90 */ | 110 */ |
| 91 void assertErrors2(List<ErrorCode> expectedErrorCodes) { | 111 void assertErrors2(List<ErrorCode> expectedErrorCodes) { |
| 92 JavaStringBuilder builder = new JavaStringBuilder(); | 112 JavaStringBuilder builder = new JavaStringBuilder(); |
| 113 for (ErrorCode errorCode in expectedErrorCodes) { |
| 114 JUnitTestCase.assertFalseMsg("Empty error code message", errorCode.message
.isEmpty); |
| 115 } |
| 93 Map<ErrorCode, int> expectedCounts = new Map<ErrorCode, int>(); | 116 Map<ErrorCode, int> expectedCounts = new Map<ErrorCode, int>(); |
| 94 for (ErrorCode code in expectedErrorCodes) { | 117 for (ErrorCode code in expectedErrorCodes) { |
| 95 int count = expectedCounts[code]; | 118 int count = expectedCounts[code]; |
| 96 if (count == null) { | 119 if (count == null) { |
| 97 count = 1; | 120 count = 1; |
| 98 } else { | 121 } else { |
| 99 count = count + 1; | 122 count = count + 1; |
| 100 } | 123 } |
| 101 expectedCounts[code] = count; | 124 expectedCounts[code] = count; |
| 102 } | 125 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 actualCount = list.length; | 144 actualCount = list.length; |
| 122 } | 145 } |
| 123 if (actualCount != expectedCount) { | 146 if (actualCount != expectedCount) { |
| 124 if (builder.length == 0) { | 147 if (builder.length == 0) { |
| 125 builder.append("Expected "); | 148 builder.append("Expected "); |
| 126 } else { | 149 } else { |
| 127 builder.append("; "); | 150 builder.append("; "); |
| 128 } | 151 } |
| 129 builder.append(expectedCount); | 152 builder.append(expectedCount); |
| 130 builder.append(" errors of type "); | 153 builder.append(" errors of type "); |
| 131 builder.append(code); | 154 builder.append("${code.runtimeType.toString()}.${code}"); |
| 132 builder.append(", found "); | 155 builder.append(", found "); |
| 133 builder.append(actualCount); | 156 builder.append(actualCount); |
| 134 } | 157 } |
| 135 } | 158 } |
| 136 for (MapEntry<ErrorCode, List<AnalysisError>> entry in getMapEntrySet(errors
ByCode)) { | 159 for (MapEntry<ErrorCode, List<AnalysisError>> entry in getMapEntrySet(errors
ByCode)) { |
| 137 ErrorCode code = entry.getKey(); | 160 ErrorCode code = entry.getKey(); |
| 138 List<AnalysisError> actualErrors = entry.getValue(); | 161 List<AnalysisError> actualErrors = entry.getValue(); |
| 139 int actualCount = actualErrors.length; | 162 int actualCount = actualErrors.length; |
| 140 if (builder.length == 0) { | 163 if (builder.length == 0) { |
| 141 builder.append("Expected "); | 164 builder.append("Expected "); |
| 142 } else { | 165 } else { |
| 143 builder.append("; "); | 166 builder.append("; "); |
| 144 } | 167 } |
| 145 builder.append("0 errors of type "); | 168 builder.append("0 errors of type "); |
| 146 builder.append(code); | 169 builder.append("${code.runtimeType.toString()}.${code}"); |
| 147 builder.append(", found "); | 170 builder.append(", found "); |
| 148 builder.append(actualCount); | 171 builder.append(actualCount); |
| 149 builder.append(" ("); | 172 builder.append(" ("); |
| 150 for (int i = 0; i < actualErrors.length; i++) { | 173 for (int i = 0; i < actualErrors.length; i++) { |
| 151 AnalysisError error = actualErrors[i]; | 174 AnalysisError error = actualErrors[i]; |
| 152 if (i > 0) { | 175 if (i > 0) { |
| 153 builder.append(", "); | 176 builder.append(", "); |
| 154 } | 177 } |
| 155 builder.append(error.offset); | 178 builder.append(error.offset); |
| 156 } | 179 } |
| 157 builder.append(")"); | 180 builder.append(")"); |
| 158 } | 181 } |
| 159 if (builder.length > 0) { | 182 if (builder.length > 0) { |
| 160 JUnitTestCase.fail(builder.toString()); | 183 JUnitTestCase.fail(builder.toString()); |
| 161 } | 184 } |
| 162 } | 185 } |
| 186 |
| 163 /** | 187 /** |
| 164 * Assert that the number of errors that have been gathered matches the number
of severities that | 188 * Assert that the number of errors that have been gathered matches the number
of severities that |
| 165 * are given and that there are the same number of errors and warnings as spec
ified by the | 189 * are given and that there are the same number of errors and warnings as spec
ified by the |
| 166 * argument. The order in which the errors were gathered is ignored. | 190 * argument. The order in which the errors were gathered is ignored. |
| 167 * @param expectedSeverities the severities of the errors that should have bee
n gathered | 191 * @param expectedSeverities the severities of the errors that should have bee
n gathered |
| 168 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 192 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 169 * expected | 193 * expected |
| 170 */ | 194 */ |
| 171 void assertErrors3(List<ErrorSeverity> expectedSeverities) { | 195 void assertErrors3(List<ErrorSeverity> expectedSeverities) { |
| 172 int expectedErrorCount = 0; | 196 int expectedErrorCount = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 184 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) { | 208 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) { |
| 185 actualErrorCount++; | 209 actualErrorCount++; |
| 186 } else { | 210 } else { |
| 187 actualWarningCount++; | 211 actualWarningCount++; |
| 188 } | 212 } |
| 189 } | 213 } |
| 190 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual
WarningCount) { | 214 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual
WarningCount) { |
| 191 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa
rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount}
warnings"); | 215 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa
rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount}
warnings"); |
| 192 } | 216 } |
| 193 } | 217 } |
| 218 |
| 194 /** | 219 /** |
| 195 * Assert that no errors have been gathered. | 220 * Assert that no errors have been gathered. |
| 196 * @throws AssertionFailedError if any errors have been gathered | 221 * @throws AssertionFailedError if any errors have been gathered |
| 197 */ | 222 */ |
| 198 void assertNoErrors() { | 223 void assertNoErrors() { |
| 199 assertErrors(_NO_ERRORS); | 224 assertErrors(_NO_ERRORS); |
| 200 } | 225 } |
| 226 |
| 201 /** | 227 /** |
| 202 * Return the errors that were collected. | 228 * Return the errors that were collected. |
| 203 * @return the errors that were collected | 229 * @return the errors that were collected |
| 204 */ | 230 */ |
| 205 List<AnalysisError> get errors => _errors; | 231 List<AnalysisError> get errors => _errors; |
| 232 |
| 206 /** | 233 /** |
| 207 * Return the line information associated with the given source, or {@code nul
l} if no line | 234 * Return the line information associated with the given source, or {@code nul
l} if no line |
| 208 * information has been associated with the source. | 235 * information has been associated with the source. |
| 209 * @param source the source with which the line information is associated | 236 * @param source the source with which the line information is associated |
| 210 * @return the line information associated with the source | 237 * @return the line information associated with the source |
| 211 */ | 238 */ |
| 212 LineInfo getLineInfo(Source source) => _lineInfoMap[source]; | 239 LineInfo getLineInfo(Source source) => _lineInfoMap[source]; |
| 240 |
| 213 /** | 241 /** |
| 214 * Return {@code true} if an error with the given error code has been gathered
. | 242 * Return {@code true} if an error with the given error code has been gathered
. |
| 215 * @param errorCode the error code being searched for | 243 * @param errorCode the error code being searched for |
| 216 * @return {@code true} if an error with the given error code has been gathere
d | 244 * @return {@code true} if an error with the given error code has been gathere
d |
| 217 */ | 245 */ |
| 218 bool hasError(ErrorCode errorCode2) { | 246 bool hasError(ErrorCode errorCode2) { |
| 219 for (AnalysisError error in _errors) { | 247 for (AnalysisError error in _errors) { |
| 220 if (identical(error.errorCode, errorCode2)) { | 248 if (identical(error.errorCode, errorCode2)) { |
| 221 return true; | 249 return true; |
| 222 } | 250 } |
| 223 } | 251 } |
| 224 return false; | 252 return false; |
| 225 } | 253 } |
| 254 |
| 226 /** | 255 /** |
| 227 * Return {@code true} if at least one error has been gathered. | 256 * Return {@code true} if at least one error has been gathered. |
| 228 * @return {@code true} if at least one error has been gathered | 257 * @return {@code true} if at least one error has been gathered |
| 229 */ | 258 */ |
| 230 bool hasErrors() => _errors.length > 0; | 259 bool hasErrors() => _errors.length > 0; |
| 231 void onError(AnalysisError error) { | 260 void onError(AnalysisError error) { |
| 232 if (_rawSource != null) { | 261 if (_rawSource != null) { |
| 233 int left = error.offset; | 262 int left = error.offset; |
| 234 int right = left + error.length - 1; | 263 int right = left + error.length - 1; |
| 235 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; | 264 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; |
| 236 } | 265 } |
| 237 _errors.add(error); | 266 _errors.add(error); |
| 238 } | 267 } |
| 268 |
| 239 /** | 269 /** |
| 240 * Set the line information associated with the given source to the given info
rmation. | 270 * Set the line information associated with the given source to the given info
rmation. |
| 241 * @param source the source with which the line information is associated | 271 * @param source the source with which the line information is associated |
| 242 * @param lineStarts the line start information to be associated with the sour
ce | 272 * @param lineStarts the line start information to be associated with the sour
ce |
| 243 */ | 273 */ |
| 244 void setLineInfo(Source source, List<int> lineStarts) { | 274 void setLineInfo(Source source, List<int> lineStarts) { |
| 245 _lineInfoMap[source] = new LineInfo(lineStarts); | 275 _lineInfoMap[source] = new LineInfo(lineStarts); |
| 246 } | 276 } |
| 277 |
| 247 /** | 278 /** |
| 248 * Set the line information associated with the given source to the given info
rmation. | 279 * Set the line information associated with the given source to the given info
rmation. |
| 249 * @param source the source with which the line information is associated | 280 * @param source the source with which the line information is associated |
| 250 * @param lineInfo the line information to be associated with the source | 281 * @param lineInfo the line information to be associated with the source |
| 251 */ | 282 */ |
| 252 void setLineInfo2(Source source, LineInfo lineInfo) { | 283 void setLineInfo2(Source source, LineInfo lineInfo) { |
| 253 _lineInfoMap[source] = lineInfo; | 284 _lineInfoMap[source] = lineInfo; |
| 254 } | 285 } |
| 286 |
| 255 /** | 287 /** |
| 256 * Return {@code true} if the two errors are equivalent. | 288 * Return {@code true} if the two errors are equivalent. |
| 257 * @param firstError the first error being compared | 289 * @param firstError the first error being compared |
| 258 * @param secondError the second error being compared | 290 * @param secondError the second error being compared |
| 259 * @return {@code true} if the two errors are equivalent | 291 * @return {@code true} if the two errors are equivalent |
| 260 */ | 292 */ |
| 261 bool equals3(AnalysisError firstError, AnalysisError secondError) => identical
(firstError.errorCode, secondError.errorCode) && firstError.offset == secondErro
r.offset && firstError.length == secondError.length && equals4(firstError.source
, secondError.source); | 293 bool equals3(AnalysisError firstError, AnalysisError secondError) => identical
(firstError.errorCode, secondError.errorCode) && firstError.offset == secondErro
r.offset && firstError.length == secondError.length && equals4(firstError.source
, secondError.source); |
| 294 |
| 262 /** | 295 /** |
| 263 * Return {@code true} if the two sources are equivalent. | 296 * Return {@code true} if the two sources are equivalent. |
| 264 * @param firstSource the first source being compared | 297 * @param firstSource the first source being compared |
| 265 * @param secondSource the second source being compared | 298 * @param secondSource the second source being compared |
| 266 * @return {@code true} if the two sources are equivalent | 299 * @return {@code true} if the two sources are equivalent |
| 267 */ | 300 */ |
| 268 bool equals4(Source firstSource, Source secondSource) { | 301 bool equals4(Source firstSource, Source secondSource) { |
| 269 if (firstSource == null) { | 302 if (firstSource == null) { |
| 270 return secondSource == null; | 303 return secondSource == null; |
| 271 } else if (secondSource == null) { | 304 } else if (secondSource == null) { |
| 272 return false; | 305 return false; |
| 273 } | 306 } |
| 274 return firstSource == secondSource; | 307 return firstSource == secondSource; |
| 275 } | 308 } |
| 309 |
| 276 /** | 310 /** |
| 277 * Assert that the number of errors that have been gathered matches the number
of errors that are | 311 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 278 * given and that they have the expected error codes. The order in which the e
rrors were gathered | 312 * given and that they have the expected error codes. The order in which the e
rrors were gathered |
| 279 * is ignored. | 313 * is ignored. |
| 280 * @param errorCodes the errors that should have been gathered | 314 * @param errorCodes the errors that should have been gathered |
| 281 * @throws AssertionFailedError with | 315 * @throws AssertionFailedError with |
| 282 */ | 316 */ |
| 283 void fail(List<AnalysisError> expectedErrors) { | 317 void fail(List<AnalysisError> expectedErrors) { |
| 284 PrintStringWriter writer = new PrintStringWriter(); | 318 PrintStringWriter writer = new PrintStringWriter(); |
| 285 writer.print("Expected "); | 319 writer.print("Expected "); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 308 if (lineInfo == null) { | 342 if (lineInfo == null) { |
| 309 int offset3 = error.offset; | 343 int offset3 = error.offset; |
| 310 writer.printf(" %s %s (%d..%d): %s", [source3 == null ? "" : source3.sh
ortName, error.errorCode, offset3, offset3 + error.length, error.message]); | 344 writer.printf(" %s %s (%d..%d): %s", [source3 == null ? "" : source3.sh
ortName, error.errorCode, offset3, offset3 + error.length, error.message]); |
| 311 } else { | 345 } else { |
| 312 LineInfo_Location location = lineInfo.getLocation(error.offset); | 346 LineInfo_Location location = lineInfo.getLocation(error.offset); |
| 313 writer.printf(" %s %s (%d, %d/%d): %s", [source3 == null ? "" : source3
.shortName, error.errorCode, location.lineNumber, location.columnNumber, error.l
ength, error.message]); | 347 writer.printf(" %s %s (%d, %d/%d): %s", [source3 == null ? "" : source3
.shortName, error.errorCode, location.lineNumber, location.columnNumber, error.l
ength, error.message]); |
| 314 } | 348 } |
| 315 } | 349 } |
| 316 JUnitTestCase.fail(writer.toString()); | 350 JUnitTestCase.fail(writer.toString()); |
| 317 } | 351 } |
| 352 |
| 318 /** | 353 /** |
| 319 * Search through the given list of errors for an error that is equal to the t
arget error. If one | 354 * Search through the given list of errors for an error that is equal to the t
arget error. If one |
| 320 * is found, remove it from the list and return {@code true}, otherwise return
{@code false}without modifying the list. | 355 * is found, remove it from the list and return {@code true}, otherwise return
{@code false}without modifying the list. |
| 321 * @param errors the errors through which we are searching | 356 * @param errors the errors through which we are searching |
| 322 * @param targetError the error being searched for | 357 * @param targetError the error being searched for |
| 323 * @return {@code true} if the error is found and removed from the list | 358 * @return {@code true} if the error is found and removed from the list |
| 324 */ | 359 */ |
| 325 bool foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) { | 360 bool foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) { |
| 326 for (AnalysisError error in errors) { | 361 for (AnalysisError error in errors) { |
| 327 if (equals3(error, targetError)) { | 362 if (equals3(error, targetError)) { |
| 328 errors.remove(error); | 363 errors.remove(error); |
| 329 return true; | 364 return true; |
| 330 } | 365 } |
| 331 } | 366 } |
| 332 return true; | 367 return true; |
| 333 } | 368 } |
| 334 } | 369 } |
| 370 |
| 335 /** | 371 /** |
| 336 * The class {@code EngineTestCase} defines utility methods for making assertion
s. | 372 * The class {@code EngineTestCase} defines utility methods for making assertion
s. |
| 337 */ | 373 */ |
| 338 class EngineTestCase extends JUnitTestCase { | 374 class EngineTestCase extends JUnitTestCase { |
| 339 static int _PRINT_RANGE = 6; | 375 static int _PRINT_RANGE = 6; |
| 376 |
| 340 /** | 377 /** |
| 341 * Assert that the tokens in the actual stream of tokens have the same types a
nd lexemes as the | 378 * Assert that the tokens in the actual stream of tokens have the same types a
nd lexemes as the |
| 342 * tokens in the expected stream of tokens. Note that this does not assert any
thing about the | 379 * tokens in the expected stream of tokens. Note that this does not assert any
thing about the |
| 343 * offsets of the tokens (although the lengths will be equal). | 380 * offsets of the tokens (although the lengths will be equal). |
| 344 * @param expectedStream the head of the stream of tokens that were expected | 381 * @param expectedStream the head of the stream of tokens that were expected |
| 345 * @param actualStream the head of the stream of tokens that were actually fou
nd | 382 * @param actualStream the head of the stream of tokens that were actually fou
nd |
| 346 * @throws AssertionFailedError if the two streams of tokens are not the same | 383 * @throws AssertionFailedError if the two streams of tokens are not the same |
| 347 */ | 384 */ |
| 348 static void assertAllMatch(Token expectedStream, Token actualStream) { | 385 static void assertAllMatch(Token expectedStream, Token actualStream) { |
| 349 Token left = expectedStream; | 386 Token left = expectedStream; |
| 350 Token right = actualStream; | 387 Token right = actualStream; |
| 351 while (left.type != TokenType.EOF && right.type != TokenType.EOF) { | 388 while (left.type != TokenType.EOF && right.type != TokenType.EOF) { |
| 352 assertMatches(left, right); | 389 assertMatches(left, right); |
| 353 left = left.next; | 390 left = left.next; |
| 354 right = right.next; | 391 right = right.next; |
| 355 } | 392 } |
| 356 } | 393 } |
| 394 |
| 357 /** | 395 /** |
| 358 * Assert that the array of actual values contain exactly the same values as t
hose in the array of | 396 * Assert that the array of actual values contain exactly the same values as t
hose in the array of |
| 359 * expected value, with the exception that the order of the elements is not re
quired to be the | 397 * expected value, with the exception that the order of the elements is not re
quired to be the |
| 360 * same. | 398 * same. |
| 361 * @param expectedValues the values that are expected to be found | 399 * @param expectedValues the values that are expected to be found |
| 362 * @param actualValues the actual values that are being compared against the e
xpected values | 400 * @param actualValues the actual values that are being compared against the e
xpected values |
| 363 */ | 401 */ |
| 364 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { | 402 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { |
| 365 JUnitTestCase.assertNotNull(actualValues); | 403 JUnitTestCase.assertNotNull(actualValues); |
| 366 int expectedLength = expectedValues.length; | 404 int expectedLength = expectedValues.length; |
| 367 JUnitTestCase.assertEquals(expectedLength, actualValues.length); | 405 JUnitTestCase.assertEquals(expectedLength, actualValues.length); |
| 368 List<bool> found = new List<bool>.filled(expectedLength, false); | 406 List<bool> found = new List<bool>.filled(expectedLength, false); |
| 369 for (int i = 0; i < expectedLength; i++) { | 407 for (int i = 0; i < expectedLength; i++) { |
| 370 found[i] = false; | 408 found[i] = false; |
| 371 } | 409 } |
| 372 for (Object actualValue in actualValues) { | 410 for (Object actualValue in actualValues) { |
| 373 bool wasExpected = false; | 411 bool wasExpected = false; |
| 374 for (int i = 0; i < expectedLength; i++) { | 412 for (int i = 0; i < expectedLength; i++) { |
| 375 if (!found[i] && expectedValues[i] == actualValue) { | 413 if (!found[i] && expectedValues[i] == actualValue) { |
| 376 found[i] = true; | 414 found[i] = true; |
| 377 wasExpected = true; | 415 wasExpected = true; |
| 378 break; | 416 break; |
| 379 } | 417 } |
| 380 } | 418 } |
| 381 if (!wasExpected) { | 419 if (!wasExpected) { |
| 382 JUnitTestCase.fail("The actual value ${actualValue} was not expected"); | 420 JUnitTestCase.fail("The actual value ${actualValue} was not expected"); |
| 383 } | 421 } |
| 384 } | 422 } |
| 385 } | 423 } |
| 424 |
| 386 /** | 425 /** |
| 387 * Assert that a given String is equal to an expected value. | 426 * Assert that a given String is equal to an expected value. |
| 388 * @param expected the expected String value | 427 * @param expected the expected String value |
| 389 * @param actual the actual String value | 428 * @param actual the actual String value |
| 390 */ | 429 */ |
| 391 static void assertEqualString(String expected, String actual) { | 430 static void assertEqualString(String expected, String actual) { |
| 392 if (actual == null || expected == null) { | 431 if (actual == null || expected == null) { |
| 393 if (identical(actual, expected)) { | 432 if (identical(actual, expected)) { |
| 394 return; | 433 return; |
| 395 } | 434 } |
| 396 if (actual == null) { | 435 if (actual == null) { |
| 397 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected
: ${expected}", false); | 436 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected
: ${expected}", false); |
| 398 } else { | 437 } else { |
| 399 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is
: ${actual}", false); | 438 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is
: ${actual}", false); |
| 400 } | 439 } |
| 401 } | 440 } |
| 402 int diffPos = getDiffPos(expected, actual); | 441 int diffPos = getDiffPos(expected, actual); |
| 403 if (diffPos != -1) { | 442 if (diffPos != -1) { |
| 404 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); | 443 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); |
| 405 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); | 444 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); |
| 406 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri
ng(diffPos, diffAfter)}"; | 445 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri
ng(diffPos, diffAfter)}"; |
| 407 String message = "Content not as expected: is\n${actual}\nDiffers at pos $
{diffPos}: ${diffStr}\nexpected:\n${expected}"; | 446 String message = "Content not as expected: is\n${actual}\nDiffers at pos $
{diffPos}: ${diffStr}\nexpected:\n${expected}"; |
| 408 JUnitTestCase.assertEqualsMsg(message, expected, actual); | 447 JUnitTestCase.assertEqualsMsg(message, expected, actual); |
| 409 } | 448 } |
| 410 } | 449 } |
| 450 |
| 411 /** | 451 /** |
| 412 * Assert that the given list is non-{@code null} and has exactly expected ele
ments. | 452 * Assert that the given list is non-{@code null} and has exactly expected ele
ments. |
| 413 * @param list the list being tested | 453 * @param list the list being tested |
| 414 * @param expectedElements the expected elements | 454 * @param expectedElements the expected elements |
| 415 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements | 455 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements |
| 416 */ | 456 */ |
| 417 static void assertExactElements(List<Object> list, List<Object> expectedElemen
ts) { | 457 static void assertExactElements(List<Object> list, List<Object> expectedElemen
ts) { |
| 418 int expectedSize = expectedElements.length; | 458 int expectedSize = expectedElements.length; |
| 419 if (list == null) { | 459 if (list == null) { |
| 420 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 460 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 421 } | 461 } |
| 422 if (list.length != expectedSize) { | 462 if (list.length != expectedSize) { |
| 423 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); | 463 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); |
| 424 } | 464 } |
| 425 for (int i = 0; i < expectedElements.length; i++) { | 465 for (int i = 0; i < expectedElements.length; i++) { |
| 426 Object element = list[i]; | 466 Object element = list[i]; |
| 427 Object expectedElement = expectedElements[i]; | 467 Object expectedElement = expectedElements[i]; |
| 428 if (!element == expectedElement) { | 468 if (!element == expectedElement) { |
| 429 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); | 469 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); |
| 430 } | 470 } |
| 431 } | 471 } |
| 432 } | 472 } |
| 473 |
| 433 /** | 474 /** |
| 434 * Assert that the given array is non-{@code null} and has exactly expected el
ements. | 475 * Assert that the given array is non-{@code null} and has exactly expected el
ements. |
| 435 * @param array the array being tested | 476 * @param array the array being tested |
| 436 * @param expectedElements the expected elements | 477 * @param expectedElements the expected elements |
| 437 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected | 478 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected |
| 438 * elements | 479 * elements |
| 439 */ | 480 */ |
| 440 static void assertExactElements2(List<Object> array, List<Object> expectedElem
ents) { | 481 static void assertExactElements2(List<Object> array, List<Object> expectedElem
ents) { |
| 441 int expectedSize = expectedElements.length; | 482 int expectedSize = expectedElements.length; |
| 442 if (array == null) { | 483 if (array == null) { |
| 443 JUnitTestCase.fail("Expected array of size ${expectedSize}; found null"); | 484 JUnitTestCase.fail("Expected array of size ${expectedSize}; found null"); |
| 444 } | 485 } |
| 445 if (array.length != expectedSize) { | 486 if (array.length != expectedSize) { |
| 446 JUnitTestCase.fail("Expected array of size ${expectedSize}; contained ${ar
ray.length} elements"); | 487 JUnitTestCase.fail("Expected array of size ${expectedSize}; contained ${ar
ray.length} elements"); |
| 447 } | 488 } |
| 448 for (int i = 0; i < expectedElements.length; i++) { | 489 for (int i = 0; i < expectedElements.length; i++) { |
| 449 Object element = array[0]; | 490 Object element = array[i]; |
| 450 Object expectedElement = expectedElements[i]; | 491 Object expectedElement = expectedElements[i]; |
| 451 if (!element == expectedElement) { | 492 if (!element == expectedElement) { |
| 452 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); | 493 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); |
| 453 } | 494 } |
| 454 } | 495 } |
| 455 } | 496 } |
| 497 |
| 456 /** | 498 /** |
| 457 * Assert that the given list is non-{@code null} and has exactly expected ele
ments. | 499 * Assert that the given list is non-{@code null} and has exactly expected ele
ments. |
| 458 * @param set the list being tested | 500 * @param set the list being tested |
| 459 * @param expectedElements the expected elements | 501 * @param expectedElements the expected elements |
| 460 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements | 502 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements |
| 461 */ | 503 */ |
| 462 static void assertExactElements3(Set<Object> set, List<Object> expectedElement
s) { | 504 static void assertExactElements3(Set<Object> set, List<Object> expectedElement
s) { |
| 463 int expectedSize = expectedElements.length; | 505 int expectedSize = expectedElements.length; |
| 464 if (set == null) { | 506 if (set == null) { |
| 465 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 507 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 466 } | 508 } |
| 467 if (set.length != expectedSize) { | 509 if (set.length != expectedSize) { |
| 468 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${set
.length} elements"); | 510 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${set
.length} elements"); |
| 469 } | 511 } |
| 470 for (int i = 0; i < expectedElements.length; i++) { | 512 for (int i = 0; i < expectedElements.length; i++) { |
| 471 Object expectedElement = expectedElements[i]; | 513 Object expectedElement = expectedElements[i]; |
| 472 if (!set.contains(expectedElement)) { | 514 if (!set.contains(expectedElement)) { |
| 473 JUnitTestCase.fail("Expected ${expectedElement} in set${set}"); | 515 JUnitTestCase.fail("Expected ${expectedElement} in set${set}"); |
| 474 } | 516 } |
| 475 } | 517 } |
| 476 } | 518 } |
| 519 |
| 477 /** | 520 /** |
| 478 * Assert that the given object is an instance of the expected class. | 521 * Assert that the given object is an instance of the expected class. |
| 479 * @param expectedClass the class that the object is expected to be an instanc
e of | 522 * @param expectedClass the class that the object is expected to be an instanc
e of |
| 480 * @param object the object being tested | 523 * @param object the object being tested |
| 481 * @return the object that was being tested | 524 * @return the object that was being tested |
| 482 * @throws Exception if the object is not an instance of the expected class | 525 * @throws Exception if the object is not an instance of the expected class |
| 483 */ | 526 */ |
| 484 static Object assertInstanceOf(Type expectedClass, Object object) { | 527 static Object assertInstanceOf(Type expectedClass, Object object) { |
| 485 if (!isInstanceOf(object, expectedClass)) { | 528 if (!isInstanceOf(object, expectedClass)) { |
| 486 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun
d ${(object == null ? "null" : object.runtimeType.toString())}"); | 529 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun
d ${(object == null ? "null" : object.runtimeType.toString())}"); |
| 487 } | 530 } |
| 488 return object as Object; | 531 return object as Object; |
| 489 } | 532 } |
| 533 |
| 490 /** | 534 /** |
| 491 * Assert that the given array is non-{@code null} and has the expected number
of elements. | 535 * Assert that the given array is non-{@code null} and has the expected number
of elements. |
| 492 * @param expectedLength the expected number of elements | 536 * @param expectedLength the expected number of elements |
| 493 * @param array the array being tested | 537 * @param array the array being tested |
| 494 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected number | 538 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected number |
| 495 * of elements | 539 * of elements |
| 496 */ | 540 */ |
| 497 static void assertLength(int expectedLength, List<Object> array) { | 541 static void assertLength(int expectedLength, List<Object> array) { |
| 498 if (array == null) { | 542 if (array == null) { |
| 499 JUnitTestCase.fail("Expected array of length ${expectedLength}; found null
"); | 543 JUnitTestCase.fail("Expected array of length ${expectedLength}; found null
"); |
| 500 } else if (array.length != expectedLength) { | 544 } else if (array.length != expectedLength) { |
| 501 JUnitTestCase.fail("Expected array of length ${expectedLength}; contained
${array.length} elements"); | 545 JUnitTestCase.fail("Expected array of length ${expectedLength}; contained
${array.length} elements"); |
| 502 } | 546 } |
| 503 } | 547 } |
| 548 |
| 504 /** | 549 /** |
| 505 * Assert that the actual token has the same type and lexeme as the expected t
oken. Note that this | 550 * Assert that the actual token has the same type and lexeme as the expected t
oken. Note that this |
| 506 * does not assert anything about the offsets of the tokens (although the leng
ths will be equal). | 551 * does not assert anything about the offsets of the tokens (although the leng
ths will be equal). |
| 507 * @param expectedToken the token that was expected | 552 * @param expectedToken the token that was expected |
| 508 * @param actualToken the token that was found | 553 * @param actualToken the token that was found |
| 509 * @throws AssertionFailedError if the two tokens are not the same | 554 * @throws AssertionFailedError if the two tokens are not the same |
| 510 */ | 555 */ |
| 511 static void assertMatches(Token expectedToken, Token actualToken) { | 556 static void assertMatches(Token expectedToken, Token actualToken) { |
| 512 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type); | 557 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type); |
| 513 if (expectedToken is KeywordToken) { | 558 if (expectedToken is KeywordToken) { |
| 514 assertInstanceOf(KeywordToken, actualToken); | 559 assertInstanceOf(KeywordToken, actualToken); |
| 515 JUnitTestCase.assertEquals(((expectedToken as KeywordToken)).keyword, ((ac
tualToken as KeywordToken)).keyword); | 560 JUnitTestCase.assertEquals(((expectedToken as KeywordToken)).keyword, ((ac
tualToken as KeywordToken)).keyword); |
| 516 } else if (expectedToken is StringToken) { | 561 } else if (expectedToken is StringToken) { |
| 517 assertInstanceOf(StringToken, actualToken); | 562 assertInstanceOf(StringToken, actualToken); |
| 518 JUnitTestCase.assertEquals(((expectedToken as StringToken)).lexeme, ((actu
alToken as StringToken)).lexeme); | 563 JUnitTestCase.assertEquals(((expectedToken as StringToken)).lexeme, ((actu
alToken as StringToken)).lexeme); |
| 519 } | 564 } |
| 520 } | 565 } |
| 566 |
| 521 /** | 567 /** |
| 522 * Assert that the given list is non-{@code null} and has the expected number
of elements. | 568 * Assert that the given list is non-{@code null} and has the expected number
of elements. |
| 523 * @param expectedSize the expected number of elements | 569 * @param expectedSize the expected number of elements |
| 524 * @param list the list being tested | 570 * @param list the list being tested |
| 525 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected number | 571 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected number |
| 526 * of elements | 572 * of elements |
| 527 */ | 573 */ |
| 528 static void assertSize(int expectedSize, List<Object> list) { | 574 static void assertSize(int expectedSize, List<Object> list) { |
| 529 if (list == null) { | 575 if (list == null) { |
| 530 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 576 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 531 } else if (list.length != expectedSize) { | 577 } else if (list.length != expectedSize) { |
| 532 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); | 578 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); |
| 533 } | 579 } |
| 534 } | 580 } |
| 581 |
| 535 /** | 582 /** |
| 536 * Assert that the given map is non-{@code null} and has the expected number o
f elements. | 583 * Assert that the given map is non-{@code null} and has the expected number o
f elements. |
| 537 * @param expectedSize the expected number of elements | 584 * @param expectedSize the expected number of elements |
| 538 * @param map the map being tested | 585 * @param map the map being tested |
| 539 * @throws AssertionFailedError if the map is {@code null} or does not have th
e expected number of | 586 * @throws AssertionFailedError if the map is {@code null} or does not have th
e expected number of |
| 540 * elements | 587 * elements |
| 541 */ | 588 */ |
| 542 static void assertSize2(int expectedSize, Map<Object, Object> map) { | 589 static void assertSize2(int expectedSize, Map<Object, Object> map) { |
| 543 if (map == null) { | 590 if (map == null) { |
| 544 JUnitTestCase.fail("Expected map of size ${expectedSize}; found null"); | 591 JUnitTestCase.fail("Expected map of size ${expectedSize}; found null"); |
| 545 } else if (map.length != expectedSize) { | 592 } else if (map.length != expectedSize) { |
| 546 JUnitTestCase.fail("Expected map of size ${expectedSize}; contained ${map.
length} elements"); | 593 JUnitTestCase.fail("Expected map of size ${expectedSize}; contained ${map.
length} elements"); |
| 547 } | 594 } |
| 548 } | 595 } |
| 596 |
| 549 /** | 597 /** |
| 550 * Assert that the given set is non-{@code null} and has the expected number o
f elements. | 598 * Assert that the given set is non-{@code null} and has the expected number o
f elements. |
| 551 * @param expectedSize the expected number of elements | 599 * @param expectedSize the expected number of elements |
| 552 * @param set the set being tested | 600 * @param set the set being tested |
| 553 * @throws AssertionFailedError if the set is {@code null} or does not have th
e expected number of | 601 * @throws AssertionFailedError if the set is {@code null} or does not have th
e expected number of |
| 554 * elements | 602 * elements |
| 555 */ | 603 */ |
| 556 static void assertSize3(int expectedSize, Set<Object> set) { | 604 static void assertSize3(int expectedSize, Set<Object> set) { |
| 557 if (set == null) { | 605 if (set == null) { |
| 558 JUnitTestCase.fail("Expected set of size ${expectedSize}; found null"); | 606 JUnitTestCase.fail("Expected set of size ${expectedSize}; found null"); |
| 559 } else if (set.length != expectedSize) { | 607 } else if (set.length != expectedSize) { |
| 560 JUnitTestCase.fail("Expected set of size ${expectedSize}; contained ${set.
length} elements"); | 608 JUnitTestCase.fail("Expected set of size ${expectedSize}; contained ${set.
length} elements"); |
| 561 } | 609 } |
| 562 } | 610 } |
| 611 |
| 563 /** | 612 /** |
| 564 * Convert the given array of lines into a single source string. | 613 * Convert the given array of lines into a single source string. |
| 565 * @param lines the lines to be merged into a single source string | 614 * @param lines the lines to be merged into a single source string |
| 566 * @return the source string composed of the given lines | 615 * @return the source string composed of the given lines |
| 567 */ | 616 */ |
| 568 static String createSource(List<String> lines) { | 617 static String createSource(List<String> lines) { |
| 569 PrintStringWriter writer = new PrintStringWriter(); | 618 PrintStringWriter writer = new PrintStringWriter(); |
| 570 for (String line in lines) { | 619 for (String line in lines) { |
| 571 writer.println(line); | 620 writer.println(line); |
| 572 } | 621 } |
| 573 return writer.toString(); | 622 return writer.toString(); |
| 574 } | 623 } |
| 624 |
| 575 /** | 625 /** |
| 576 * Calculate the offset where the given strings differ. | 626 * Calculate the offset where the given strings differ. |
| 577 * @param str1 the first String to compare | 627 * @param str1 the first String to compare |
| 578 * @param str2 the second String to compare | 628 * @param str2 the second String to compare |
| 579 * @return the offset at which the strings differ (or <code>-1</code> if they
do not) | 629 * @return the offset at which the strings differ (or <code>-1</code> if they
do not) |
| 580 */ | 630 */ |
| 581 static int getDiffPos(String str1, String str2) { | 631 static int getDiffPos(String str1, String str2) { |
| 582 int len1 = Math.min(str1.length, str2.length); | 632 int len1 = Math.min(str1.length, str2.length); |
| 583 int diffPos = -1; | 633 int diffPos = -1; |
| 584 for (int i = 0; i < len1; i++) { | 634 for (int i = 0; i < len1; i++) { |
| 585 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { | 635 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { |
| 586 diffPos = i; | 636 diffPos = i; |
| 587 break; | 637 break; |
| 588 } | 638 } |
| 589 } | 639 } |
| 590 if (diffPos == -1 && str1.length != str2.length) { | 640 if (diffPos == -1 && str1.length != str2.length) { |
| 591 diffPos = len1; | 641 diffPos = len1; |
| 592 } | 642 } |
| 593 return diffPos; | 643 return diffPos; |
| 594 } | 644 } |
| 595 AnalysisContextImpl createAnalysisContext() { | 645 AnalysisContextImpl createAnalysisContext() { |
| 596 AnalysisContextImpl context = new AnalysisContextImpl(); | 646 AnalysisContextImpl context = new AnalysisContextImpl(); |
| 597 context.sourceFactory = new SourceFactory.con2([]); | 647 context.sourceFactory = new SourceFactory.con2([]); |
| 598 return context; | 648 return context; |
| 599 } | 649 } |
| 650 |
| 600 /** | 651 /** |
| 601 * Return the getter in the given type with the given name. Inherited getters
are ignored. | 652 * Return the getter in the given type with the given name. Inherited getters
are ignored. |
| 602 * @param type the type in which the getter is declared | 653 * @param type the type in which the getter is declared |
| 603 * @param getterName the name of the getter to be returned | 654 * @param getterName the name of the getter to be returned |
| 604 * @return the property accessor element representing the getter with the give
n name | 655 * @return the property accessor element representing the getter with the give
n name |
| 605 */ | 656 */ |
| 606 PropertyAccessorElement getGetter(InterfaceType type, String getterName) { | 657 PropertyAccessorElement getGetter(InterfaceType type, String getterName) { |
| 607 for (PropertyAccessorElement accessor in type.element.accessors) { | 658 for (PropertyAccessorElement accessor in type.element.accessors) { |
| 608 if (accessor.isGetter() && accessor.name == getterName) { | 659 if (accessor.isGetter() && accessor.name == getterName) { |
| 609 return accessor; | 660 return accessor; |
| 610 } | 661 } |
| 611 } | 662 } |
| 612 JUnitTestCase.fail("Could not find getter named ${getterName} in ${type.name
}"); | 663 JUnitTestCase.fail("Could not find getter named ${getterName} in ${type.disp
layName}"); |
| 613 return null; | 664 return null; |
| 614 } | 665 } |
| 666 |
| 615 /** | 667 /** |
| 616 * Return the method in the given type with the given name. Inherited methods
are ignored. | 668 * Return the method in the given type with the given name. Inherited methods
are ignored. |
| 617 * @param type the type in which the method is declared | 669 * @param type the type in which the method is declared |
| 618 * @param methodName the name of the method to be returned | 670 * @param methodName the name of the method to be returned |
| 619 * @return the method element representing the method with the given name | 671 * @return the method element representing the method with the given name |
| 620 */ | 672 */ |
| 621 MethodElement getMethod(InterfaceType type, String methodName) { | 673 MethodElement getMethod(InterfaceType type, String methodName) { |
| 622 for (MethodElement method in type.element.methods) { | 674 for (MethodElement method in type.element.methods) { |
| 623 if (method.name == methodName) { | 675 if (method.name == methodName) { |
| 624 return method; | 676 return method; |
| 625 } | 677 } |
| 626 } | 678 } |
| 627 JUnitTestCase.fail("Could not find method named ${methodName} in ${type.name
}"); | 679 JUnitTestCase.fail("Could not find method named ${methodName} in ${type.disp
layName}"); |
| 628 return null; | 680 return null; |
| 629 } | 681 } |
| 630 static dartSuite() { | 682 static dartSuite() { |
| 631 _ut.group('EngineTestCase', () { | 683 _ut.group('EngineTestCase', () { |
| 632 }); | 684 }); |
| 633 } | 685 } |
| 634 } | 686 } |
| 635 main() { | 687 main() { |
| 636 } | 688 } |
| 637 | 689 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 return trampoline(target, arguments[0], arguments[1]); | 745 return trampoline(target, arguments[0], arguments[1]); |
| 694 case 3: | 746 case 3: |
| 695 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 747 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 696 case 4: | 748 case 4: |
| 697 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 749 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 698 default: | 750 default: |
| 699 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 751 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 700 } | 752 } |
| 701 } | 753 } |
| 702 } | 754 } |
| OLD | NEW |