| 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 library engine.test_support; | 3 library engine.test_support; |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; | 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; |
| 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; | 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; |
| 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; | 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
| 8 import 'package:analyzer_experimental/src/generated/source.dart'; | 8 import 'package:analyzer_experimental/src/generated/source.dart'; |
| 9 import 'package:analyzer_experimental/src/generated/error.dart'; | 9 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 11 import 'package:analyzer_experimental/src/generated/ast.dart' show ASTNode, Node
Locator; |
| 11 import 'package:analyzer_experimental/src/generated/element.dart' show Interface
Type, MethodElement, PropertyAccessorElement; | 12 import 'package:analyzer_experimental/src/generated/element.dart' show Interface
Type, MethodElement, PropertyAccessorElement; |
| 12 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo
ntext, AnalysisContextImpl, RecordingErrorListener; | 13 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo
ntext, AnalysisContextImpl, RecordingErrorListener; |
| 13 import 'package:unittest/unittest.dart' as _ut; | 14 import 'package:unittest/unittest.dart' as _ut; |
| 14 /** | 15 /** |
| 15 * Instances of the class `GatheringErrorListener` implement an error listener t
hat collects | 16 * Instances of the class `GatheringErrorListener` implement an error listener t
hat collects |
| 16 * all of the errors passed to it for later examination. | 17 * all of the errors passed to it for later examination. |
| 17 */ | 18 */ |
| 18 class GatheringErrorListener implements AnalysisErrorListener { | 19 class GatheringErrorListener implements AnalysisErrorListener { |
| 19 | 20 |
| 20 /** | 21 /** |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 GatheringErrorListener.con1(String rawSource2) { | 59 GatheringErrorListener.con1(String rawSource2) { |
| 59 _jtd_constructor_360_impl(rawSource2); | 60 _jtd_constructor_360_impl(rawSource2); |
| 60 } | 61 } |
| 61 _jtd_constructor_360_impl(String rawSource2) { | 62 _jtd_constructor_360_impl(String rawSource2) { |
| 62 this._rawSource = rawSource2; | 63 this._rawSource = rawSource2; |
| 63 this._markedSource = rawSource2; | 64 this._markedSource = rawSource2; |
| 64 } | 65 } |
| 65 | 66 |
| 66 /** | 67 /** |
| 67 * Add all of the errors recorded by the given listener to this listener. | 68 * Add all of the errors recorded by the given listener to this listener. |
| 69 * |
| 68 * @param listener the listener that has recorded the errors to be added | 70 * @param listener the listener that has recorded the errors to be added |
| 69 */ | 71 */ |
| 70 void addAll(RecordingErrorListener listener) { | 72 void addAll(RecordingErrorListener listener) { |
| 71 for (AnalysisError error in listener.errors) { | 73 for (AnalysisError error in listener.errors) { |
| 72 onError(error); | 74 onError(error); |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 | 77 |
| 76 /** | 78 /** |
| 77 * Assert that the number of errors that have been gathered matches the number
of errors that are | 79 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 78 * given and that they have the expected error codes and locations. The order
in which the errors | 80 * given and that they have the expected error codes and locations. The order
in which the errors |
| 79 * were gathered is ignored. | 81 * were gathered is ignored. |
| 82 * |
| 80 * @param errorCodes the errors that should have been gathered | 83 * @param errorCodes the errors that should have been gathered |
| 81 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 84 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 82 * expected or if they do not have the same codes and locations | 85 * expected or if they do not have the same codes and locations |
| 83 */ | 86 */ |
| 84 void assertErrors(List<AnalysisError> expectedErrors) { | 87 void assertErrors(List<AnalysisError> expectedErrors) { |
| 85 if (_errors.length != expectedErrors.length) { | 88 if (_errors.length != expectedErrors.length) { |
| 86 fail(expectedErrors); | 89 fail(expectedErrors); |
| 87 } | 90 } |
| 88 List<AnalysisError> remainingErrors = new List<AnalysisError>(); | 91 List<AnalysisError> remainingErrors = new List<AnalysisError>(); |
| 89 for (AnalysisError error in expectedErrors) { | 92 for (AnalysisError error in expectedErrors) { |
| 90 remainingErrors.add(error); | 93 remainingErrors.add(error); |
| 91 } | 94 } |
| 92 for (AnalysisError error in _errors) { | 95 for (AnalysisError error in _errors) { |
| 93 if (!foundAndRemoved(remainingErrors, error)) { | 96 if (!foundAndRemoved(remainingErrors, error)) { |
| 94 fail(expectedErrors); | 97 fail(expectedErrors); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 } | 100 } |
| 98 | 101 |
| 99 /** | 102 /** |
| 100 * Assert that the number of errors that have been gathered matches the number
of errors that are | 103 * 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 | 104 * given and that they have the expected error codes. The order in which the e
rrors were gathered |
| 102 * is ignored. | 105 * is ignored. |
| 106 * |
| 103 * @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 |
| 104 * @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 |
| 105 * expected | 109 * expected |
| 106 */ | 110 */ |
| 107 void assertErrors2(List<ErrorCode> expectedErrorCodes) { | 111 void assertErrors2(List<ErrorCode> expectedErrorCodes) { |
| 108 JavaStringBuilder builder = new JavaStringBuilder(); | 112 JavaStringBuilder builder = new JavaStringBuilder(); |
| 109 for (ErrorCode errorCode in expectedErrorCodes) { | 113 for (ErrorCode errorCode in expectedErrorCodes) { |
| 110 JUnitTestCase.assertFalseMsg("Empty error code message", errorCode.message
.isEmpty); | 114 JUnitTestCase.assertFalseMsg("Empty error code message", errorCode.message
.isEmpty); |
| 111 } | 115 } |
| 112 Map<ErrorCode, int> expectedCounts = new Map<ErrorCode, int>(); | 116 Map<ErrorCode, int> expectedCounts = new Map<ErrorCode, int>(); |
| 113 for (ErrorCode code in expectedErrorCodes) { | 117 for (ErrorCode code in expectedErrorCodes) { |
| 114 int count = expectedCounts[code]; | 118 int count = expectedCounts[code]; |
| 115 if (count == null) { | 119 if (count == null) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 181 } |
| 178 if (builder.length > 0) { | 182 if (builder.length > 0) { |
| 179 JUnitTestCase.fail(builder.toString()); | 183 JUnitTestCase.fail(builder.toString()); |
| 180 } | 184 } |
| 181 } | 185 } |
| 182 | 186 |
| 183 /** | 187 /** |
| 184 * 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 |
| 185 * 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 |
| 186 * argument. The order in which the errors were gathered is ignored. | 190 * argument. The order in which the errors were gathered is ignored. |
| 191 * |
| 187 * @param expectedSeverities the severities of the errors that should have bee
n gathered | 192 * @param expectedSeverities the severities of the errors that should have bee
n gathered |
| 188 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 193 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 189 * expected | 194 * expected |
| 190 */ | 195 */ |
| 191 void assertErrors3(List<ErrorSeverity> expectedSeverities) { | 196 void assertErrors3(List<ErrorSeverity> expectedSeverities) { |
| 192 int expectedErrorCount = 0; | 197 int expectedErrorCount = 0; |
| 193 int expectedWarningCount = 0; | 198 int expectedWarningCount = 0; |
| 194 for (ErrorSeverity severity in expectedSeverities) { | 199 for (ErrorSeverity severity in expectedSeverities) { |
| 195 if (identical(severity, ErrorSeverity.ERROR)) { | 200 if (identical(severity, ErrorSeverity.ERROR)) { |
| 196 expectedErrorCount++; | 201 expectedErrorCount++; |
| 197 } else { | 202 } else { |
| 198 expectedWarningCount++; | 203 expectedWarningCount++; |
| 199 } | 204 } |
| 200 } | 205 } |
| 201 int actualErrorCount = 0; | 206 int actualErrorCount = 0; |
| 202 int actualWarningCount = 0; | 207 int actualWarningCount = 0; |
| 203 for (AnalysisError error in _errors) { | 208 for (AnalysisError error in _errors) { |
| 204 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) { | 209 if (identical(error.errorCode.errorSeverity, ErrorSeverity.ERROR)) { |
| 205 actualErrorCount++; | 210 actualErrorCount++; |
| 206 } else { | 211 } else { |
| 207 actualWarningCount++; | 212 actualWarningCount++; |
| 208 } | 213 } |
| 209 } | 214 } |
| 210 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual
WarningCount) { | 215 if (expectedErrorCount != actualErrorCount || expectedWarningCount != actual
WarningCount) { |
| 211 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa
rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount}
warnings"); | 216 JUnitTestCase.fail("Expected ${expectedErrorCount} errors and ${expectedWa
rningCount} warnings, found ${actualErrorCount} errors and ${actualWarningCount}
warnings"); |
| 212 } | 217 } |
| 213 } | 218 } |
| 214 | 219 |
| 215 /** | 220 /** |
| 216 * Assert that no errors have been gathered. | 221 * Assert that no errors have been gathered. |
| 222 * |
| 217 * @throws AssertionFailedError if any errors have been gathered | 223 * @throws AssertionFailedError if any errors have been gathered |
| 218 */ | 224 */ |
| 219 void assertNoErrors() { | 225 void assertNoErrors() { |
| 220 assertErrors(_NO_ERRORS); | 226 assertErrors(_NO_ERRORS); |
| 221 } | 227 } |
| 222 | 228 |
| 223 /** | 229 /** |
| 224 * Return the errors that were collected. | 230 * Return the errors that were collected. |
| 231 * |
| 225 * @return the errors that were collected | 232 * @return the errors that were collected |
| 226 */ | 233 */ |
| 227 List<AnalysisError> get errors => _errors; | 234 List<AnalysisError> get errors => _errors; |
| 228 | 235 |
| 229 /** | 236 /** |
| 230 * Return the line information associated with the given source, or `null` if
no line | 237 * Return the line information associated with the given source, or `null` if
no line |
| 231 * information has been associated with the source. | 238 * information has been associated with the source. |
| 239 * |
| 232 * @param source the source with which the line information is associated | 240 * @param source the source with which the line information is associated |
| 233 * @return the line information associated with the source | 241 * @return the line information associated with the source |
| 234 */ | 242 */ |
| 235 LineInfo getLineInfo(Source source) => _lineInfoMap[source]; | 243 LineInfo getLineInfo(Source source) => _lineInfoMap[source]; |
| 236 | 244 |
| 237 /** | 245 /** |
| 238 * Return `true` if an error with the given error code has been gathered. | 246 * Return `true` if an error with the given error code has been gathered. |
| 247 * |
| 239 * @param errorCode the error code being searched for | 248 * @param errorCode the error code being searched for |
| 240 * @return `true` if an error with the given error code has been gathered | 249 * @return `true` if an error with the given error code has been gathered |
| 241 */ | 250 */ |
| 242 bool hasError(ErrorCode errorCode2) { | 251 bool hasError(ErrorCode errorCode2) { |
| 243 for (AnalysisError error in _errors) { | 252 for (AnalysisError error in _errors) { |
| 244 if (identical(error.errorCode, errorCode2)) { | 253 if (identical(error.errorCode, errorCode2)) { |
| 245 return true; | 254 return true; |
| 246 } | 255 } |
| 247 } | 256 } |
| 248 return false; | 257 return false; |
| 249 } | 258 } |
| 250 | 259 |
| 251 /** | 260 /** |
| 252 * Return `true` if at least one error has been gathered. | 261 * Return `true` if at least one error has been gathered. |
| 262 * |
| 253 * @return `true` if at least one error has been gathered | 263 * @return `true` if at least one error has been gathered |
| 254 */ | 264 */ |
| 255 bool hasErrors() => _errors.length > 0; | 265 bool hasErrors() => _errors.length > 0; |
| 256 void onError(AnalysisError error) { | 266 void onError(AnalysisError error) { |
| 257 if (_rawSource != null) { | 267 if (_rawSource != null) { |
| 258 int left = error.offset; | 268 int left = error.offset; |
| 259 int right = left + error.length - 1; | 269 int right = left + error.length - 1; |
| 260 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; | 270 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; |
| 261 } | 271 } |
| 262 _errors.add(error); | 272 _errors.add(error); |
| 263 } | 273 } |
| 264 | 274 |
| 265 /** | 275 /** |
| 266 * Set the line information associated with the given source to the given info
rmation. | 276 * Set the line information associated with the given source to the given info
rmation. |
| 277 * |
| 267 * @param source the source with which the line information is associated | 278 * @param source the source with which the line information is associated |
| 268 * @param lineStarts the line start information to be associated with the sour
ce | 279 * @param lineStarts the line start information to be associated with the sour
ce |
| 269 */ | 280 */ |
| 270 void setLineInfo(Source source, List<int> lineStarts) { | 281 void setLineInfo(Source source, List<int> lineStarts) { |
| 271 _lineInfoMap[source] = new LineInfo(lineStarts); | 282 _lineInfoMap[source] = new LineInfo(lineStarts); |
| 272 } | 283 } |
| 273 | 284 |
| 274 /** | 285 /** |
| 275 * Set the line information associated with the given source to the given info
rmation. | 286 * Set the line information associated with the given source to the given info
rmation. |
| 287 * |
| 276 * @param source the source with which the line information is associated | 288 * @param source the source with which the line information is associated |
| 277 * @param lineInfo the line information to be associated with the source | 289 * @param lineInfo the line information to be associated with the source |
| 278 */ | 290 */ |
| 279 void setLineInfo2(Source source, LineInfo lineInfo) { | 291 void setLineInfo2(Source source, LineInfo lineInfo) { |
| 280 _lineInfoMap[source] = lineInfo; | 292 _lineInfoMap[source] = lineInfo; |
| 281 } | 293 } |
| 282 | 294 |
| 283 /** | 295 /** |
| 284 * Return `true` if the two errors are equivalent. | 296 * Return `true` if the two errors are equivalent. |
| 297 * |
| 285 * @param firstError the first error being compared | 298 * @param firstError the first error being compared |
| 286 * @param secondError the second error being compared | 299 * @param secondError the second error being compared |
| 287 * @return `true` if the two errors are equivalent | 300 * @return `true` if the two errors are equivalent |
| 288 */ | 301 */ |
| 289 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); | 302 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); |
| 290 | 303 |
| 291 /** | 304 /** |
| 292 * Return `true` if the two sources are equivalent. | 305 * Return `true` if the two sources are equivalent. |
| 306 * |
| 293 * @param firstSource the first source being compared | 307 * @param firstSource the first source being compared |
| 294 * @param secondSource the second source being compared | 308 * @param secondSource the second source being compared |
| 295 * @return `true` if the two sources are equivalent | 309 * @return `true` if the two sources are equivalent |
| 296 */ | 310 */ |
| 297 bool equals4(Source firstSource, Source secondSource) { | 311 bool equals4(Source firstSource, Source secondSource) { |
| 298 if (firstSource == null) { | 312 if (firstSource == null) { |
| 299 return secondSource == null; | 313 return secondSource == null; |
| 300 } else if (secondSource == null) { | 314 } else if (secondSource == null) { |
| 301 return false; | 315 return false; |
| 302 } | 316 } |
| 303 return firstSource == secondSource; | 317 return firstSource == secondSource; |
| 304 } | 318 } |
| 305 | 319 |
| 306 /** | 320 /** |
| 307 * Assert that the number of errors that have been gathered matches the number
of errors that are | 321 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 308 * given and that they have the expected error codes. The order in which the e
rrors were gathered | 322 * given and that they have the expected error codes. The order in which the e
rrors were gathered |
| 309 * is ignored. | 323 * is ignored. |
| 324 * |
| 310 * @param errorCodes the errors that should have been gathered | 325 * @param errorCodes the errors that should have been gathered |
| 311 * @throws AssertionFailedError with | 326 * @throws AssertionFailedError with |
| 312 */ | 327 */ |
| 313 void fail(List<AnalysisError> expectedErrors) { | 328 void fail(List<AnalysisError> expectedErrors) { |
| 314 PrintStringWriter writer = new PrintStringWriter(); | 329 PrintStringWriter writer = new PrintStringWriter(); |
| 315 writer.print("Expected "); | 330 writer.print("Expected "); |
| 316 writer.print(expectedErrors.length); | 331 writer.print(expectedErrors.length); |
| 317 writer.print(" errors:"); | 332 writer.print(" errors:"); |
| 318 for (AnalysisError error in expectedErrors) { | 333 for (AnalysisError error in expectedErrors) { |
| 319 Source source = error.source; | 334 Source source = error.source; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 341 } else { | 356 } else { |
| 342 LineInfo_Location location = lineInfo.getLocation(error.offset); | 357 LineInfo_Location location = lineInfo.getLocation(error.offset); |
| 343 writer.printf(" %s %s (%d, %d/%d): %s", [source == null ? "" : source.s
hortName, error.errorCode, location.lineNumber, location.columnNumber, error.len
gth, error.message]); | 358 writer.printf(" %s %s (%d, %d/%d): %s", [source == null ? "" : source.s
hortName, error.errorCode, location.lineNumber, location.columnNumber, error.len
gth, error.message]); |
| 344 } | 359 } |
| 345 } | 360 } |
| 346 JUnitTestCase.fail(writer.toString()); | 361 JUnitTestCase.fail(writer.toString()); |
| 347 } | 362 } |
| 348 | 363 |
| 349 /** | 364 /** |
| 350 * Search through the given list of errors for an error that is equal to the t
arget error. If one | 365 * Search through the given list of errors for an error that is equal to the t
arget error. If one |
| 351 * is found, remove it from the list and return `true`, otherwise return `fals
e`without modifying the list. | 366 * is found, remove it from the list and return `true`, otherwise return `fals
e` |
| 367 * without modifying the list. |
| 368 * |
| 352 * @param errors the errors through which we are searching | 369 * @param errors the errors through which we are searching |
| 353 * @param targetError the error being searched for | 370 * @param targetError the error being searched for |
| 354 * @return `true` if the error is found and removed from the list | 371 * @return `true` if the error is found and removed from the list |
| 355 */ | 372 */ |
| 356 bool foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) { | 373 bool foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) { |
| 357 for (AnalysisError error in errors) { | 374 for (AnalysisError error in errors) { |
| 358 if (equals3(error, targetError)) { | 375 if (equals3(error, targetError)) { |
| 359 errors.remove(error); | 376 errors.remove(error); |
| 360 return true; | 377 return true; |
| 361 } | 378 } |
| 362 } | 379 } |
| 363 return true; | 380 return true; |
| 364 } | 381 } |
| 365 } | 382 } |
| 366 /** | 383 /** |
| 367 * The class `EngineTestCase` defines utility methods for making assertions. | 384 * The class `EngineTestCase` defines utility methods for making assertions. |
| 368 */ | 385 */ |
| 369 class EngineTestCase extends JUnitTestCase { | 386 class EngineTestCase extends JUnitTestCase { |
| 370 static int _PRINT_RANGE = 6; | 387 static int _PRINT_RANGE = 6; |
| 371 | 388 |
| 372 /** | 389 /** |
| 373 * Assert that the tokens in the actual stream of tokens have the same types a
nd lexemes as the | 390 * Assert that the tokens in the actual stream of tokens have the same types a
nd lexemes as the |
| 374 * tokens in the expected stream of tokens. Note that this does not assert any
thing about the | 391 * tokens in the expected stream of tokens. Note that this does not assert any
thing about the |
| 375 * offsets of the tokens (although the lengths will be equal). | 392 * offsets of the tokens (although the lengths will be equal). |
| 393 * |
| 376 * @param expectedStream the head of the stream of tokens that were expected | 394 * @param expectedStream the head of the stream of tokens that were expected |
| 377 * @param actualStream the head of the stream of tokens that were actually fou
nd | 395 * @param actualStream the head of the stream of tokens that were actually fou
nd |
| 378 * @throws AssertionFailedError if the two streams of tokens are not the same | 396 * @throws AssertionFailedError if the two streams of tokens are not the same |
| 379 */ | 397 */ |
| 380 static void assertAllMatch(Token expectedStream, Token actualStream) { | 398 static void assertAllMatch(Token expectedStream, Token actualStream) { |
| 381 Token left = expectedStream; | 399 Token left = expectedStream; |
| 382 Token right = actualStream; | 400 Token right = actualStream; |
| 383 while (left.type != TokenType.EOF && right.type != TokenType.EOF) { | 401 while (left.type != TokenType.EOF && right.type != TokenType.EOF) { |
| 384 assertMatches(left, right); | 402 assertMatches(left, right); |
| 385 left = left.next; | 403 left = left.next; |
| 386 right = right.next; | 404 right = right.next; |
| 387 } | 405 } |
| 388 } | 406 } |
| 389 | 407 |
| 390 /** | 408 /** |
| 391 * Assert that the given array is non-`null` and contains the expected element
s. The | 409 * Assert that the given array is non-`null` and contains the expected element
s. The |
| 392 * elements can appear in any order. | 410 * elements can appear in any order. |
| 411 * |
| 393 * @param array the array being tested | 412 * @param array the array being tested |
| 394 * @param expectedElements the expected elements | 413 * @param expectedElements the expected elements |
| 395 * @throws AssertionFailedError if the array is `null` or does not contain the
expected | 414 * @throws AssertionFailedError if the array is `null` or does not contain the
expected |
| 396 * elements | 415 * elements |
| 397 */ | 416 */ |
| 398 static void assertContains(List<Object> array, List<Object> expectedElements)
{ | 417 static void assertContains(List<Object> array, List<Object> expectedElements)
{ |
| 399 int expectedSize = expectedElements.length; | 418 int expectedSize = expectedElements.length; |
| 400 if (array == null) { | 419 if (array == null) { |
| 401 JUnitTestCase.fail("Expected array of length ${expectedSize}; found null")
; | 420 JUnitTestCase.fail("Expected array of length ${expectedSize}; found null")
; |
| 402 } | 421 } |
| 403 if (array.length != expectedSize) { | 422 if (array.length != expectedSize) { |
| 404 JUnitTestCase.fail("Expected array of length ${expectedSize}; contained ${
array.length} elements"); | 423 JUnitTestCase.fail("Expected array of length ${expectedSize}; contained ${
array.length} elements"); |
| 405 } | 424 } |
| 406 List<bool> found = new List<bool>.filled(expectedSize, false); | 425 List<bool> found = new List<bool>.filled(expectedSize, false); |
| 407 for (int i = 0; i < expectedSize; i++) { | 426 for (int i = 0; i < expectedSize; i++) { |
| 408 assertContains2(array, found, expectedElements[i]); | 427 assertContains2(array, found, expectedElements[i]); |
| 409 } | 428 } |
| 410 } | 429 } |
| 411 | 430 |
| 412 /** | 431 /** |
| 413 * Assert that the array of actual values contain exactly the same values as t
hose in the array of | 432 * Assert that the array of actual values contain exactly the same values as t
hose in the array of |
| 414 * expected value, with the exception that the order of the elements is not re
quired to be the | 433 * expected value, with the exception that the order of the elements is not re
quired to be the |
| 415 * same. | 434 * same. |
| 435 * |
| 416 * @param expectedValues the values that are expected to be found | 436 * @param expectedValues the values that are expected to be found |
| 417 * @param actualValues the actual values that are being compared against the e
xpected values | 437 * @param actualValues the actual values that are being compared against the e
xpected values |
| 418 */ | 438 */ |
| 419 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { | 439 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { |
| 420 JUnitTestCase.assertNotNull(actualValues); | 440 JUnitTestCase.assertNotNull(actualValues); |
| 421 int expectedLength = expectedValues.length; | 441 int expectedLength = expectedValues.length; |
| 422 JUnitTestCase.assertEquals(expectedLength, actualValues.length); | 442 JUnitTestCase.assertEquals(expectedLength, actualValues.length); |
| 423 List<bool> found = new List<bool>.filled(expectedLength, false); | 443 List<bool> found = new List<bool>.filled(expectedLength, false); |
| 424 for (int i = 0; i < expectedLength; i++) { | 444 for (int i = 0; i < expectedLength; i++) { |
| 425 found[i] = false; | 445 found[i] = false; |
| 426 } | 446 } |
| 427 for (Object actualValue in actualValues) { | 447 for (Object actualValue in actualValues) { |
| 428 bool wasExpected = false; | 448 bool wasExpected = false; |
| 429 for (int i = 0; i < expectedLength; i++) { | 449 for (int i = 0; i < expectedLength; i++) { |
| 430 if (!found[i] && expectedValues[i] == actualValue) { | 450 if (!found[i] && expectedValues[i] == actualValue) { |
| 431 found[i] = true; | 451 found[i] = true; |
| 432 wasExpected = true; | 452 wasExpected = true; |
| 433 break; | 453 break; |
| 434 } | 454 } |
| 435 } | 455 } |
| 436 if (!wasExpected) { | 456 if (!wasExpected) { |
| 437 JUnitTestCase.fail("The actual value ${actualValue} was not expected"); | 457 JUnitTestCase.fail("The actual value ${actualValue} was not expected"); |
| 438 } | 458 } |
| 439 } | 459 } |
| 440 } | 460 } |
| 441 | 461 |
| 442 /** | 462 /** |
| 443 * Assert that a given String is equal to an expected value. | 463 * Assert that a given String is equal to an expected value. |
| 464 * |
| 444 * @param expected the expected String value | 465 * @param expected the expected String value |
| 445 * @param actual the actual String value | 466 * @param actual the actual String value |
| 446 */ | 467 */ |
| 447 static void assertEqualString(String expected, String actual) { | 468 static void assertEqualString(String expected, String actual) { |
| 448 if (actual == null || expected == null) { | 469 if (actual == null || expected == null) { |
| 449 if (identical(actual, expected)) { | 470 if (identical(actual, expected)) { |
| 450 return; | 471 return; |
| 451 } | 472 } |
| 452 if (actual == null) { | 473 if (actual == null) { |
| 453 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected
: ${expected}", false); | 474 JUnitTestCase.assertTrueMsg("Content not as expected: is 'null' expected
: ${expected}", false); |
| 454 } else { | 475 } else { |
| 455 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is
: ${actual}", false); | 476 JUnitTestCase.assertTrueMsg("Content not as expected: expected 'null' is
: ${actual}", false); |
| 456 } | 477 } |
| 457 } | 478 } |
| 458 int diffPos = getDiffPos(expected, actual); | 479 int diffPos = getDiffPos(expected, actual); |
| 459 if (diffPos != -1) { | 480 if (diffPos != -1) { |
| 460 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); | 481 int diffAhead = Math.max(0, diffPos - _PRINT_RANGE); |
| 461 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); | 482 int diffAfter = Math.min(actual.length, diffPos + _PRINT_RANGE); |
| 462 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri
ng(diffPos, diffAfter)}"; | 483 String diffStr = "${actual.substring(diffAhead, diffPos)}^${actual.substri
ng(diffPos, diffAfter)}"; |
| 463 String message = "Content not as expected: is\n${actual}\nDiffers at pos $
{diffPos}: ${diffStr}\nexpected:\n${expected}"; | 484 String message = "Content not as expected: is\n${actual}\nDiffers at pos $
{diffPos}: ${diffStr}\nexpected:\n${expected}"; |
| 464 JUnitTestCase.assertEqualsMsg(message, expected, actual); | 485 JUnitTestCase.assertEqualsMsg(message, expected, actual); |
| 465 } | 486 } |
| 466 } | 487 } |
| 467 | 488 |
| 468 /** | 489 /** |
| 469 * Assert that the given list is non-`null` and has exactly expected elements. | 490 * Assert that the given list is non-`null` and has exactly expected elements. |
| 491 * |
| 470 * @param list the list being tested | 492 * @param list the list being tested |
| 471 * @param expectedElements the expected elements | 493 * @param expectedElements the expected elements |
| 472 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected elements | 494 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected elements |
| 473 */ | 495 */ |
| 474 static void assertExactElements(List<Object> list, List<Object> expectedElemen
ts) { | 496 static void assertExactElements(List<Object> list, List<Object> expectedElemen
ts) { |
| 475 int expectedSize = expectedElements.length; | 497 int expectedSize = expectedElements.length; |
| 476 if (list == null) { | 498 if (list == null) { |
| 477 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 499 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 478 } | 500 } |
| 479 if (list.length != expectedSize) { | 501 if (list.length != expectedSize) { |
| 480 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); | 502 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); |
| 481 } | 503 } |
| 482 for (int i = 0; i < expectedSize; i++) { | 504 for (int i = 0; i < expectedSize; i++) { |
| 483 Object element = list[i]; | 505 Object element = list[i]; |
| 484 Object expectedElement = expectedElements[i]; | 506 Object expectedElement = expectedElements[i]; |
| 485 if (!element == expectedElement) { | 507 if (!element == expectedElement) { |
| 486 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); | 508 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); |
| 487 } | 509 } |
| 488 } | 510 } |
| 489 } | 511 } |
| 490 | 512 |
| 491 /** | 513 /** |
| 492 * Assert that the given array is non-`null` and has exactly expected elements
. | 514 * Assert that the given array is non-`null` and has exactly expected elements
. |
| 515 * |
| 493 * @param array the array being tested | 516 * @param array the array being tested |
| 494 * @param expectedElements the expected elements | 517 * @param expectedElements the expected elements |
| 495 * @throws AssertionFailedError if the array is `null` or does not have the ex
pected | 518 * @throws AssertionFailedError if the array is `null` or does not have the ex
pected |
| 496 * elements | 519 * elements |
| 497 */ | 520 */ |
| 498 static void assertExactElements2(List<Object> array, List<Object> expectedElem
ents) { | 521 static void assertExactElements2(List<Object> array, List<Object> expectedElem
ents) { |
| 499 int expectedSize = expectedElements.length; | 522 int expectedSize = expectedElements.length; |
| 500 if (array == null) { | 523 if (array == null) { |
| 501 JUnitTestCase.fail("Expected array of size ${expectedSize}; found null"); | 524 JUnitTestCase.fail("Expected array of size ${expectedSize}; found null"); |
| 502 } | 525 } |
| 503 if (array.length != expectedSize) { | 526 if (array.length != expectedSize) { |
| 504 JUnitTestCase.fail("Expected array of size ${expectedSize}; contained ${ar
ray.length} elements"); | 527 JUnitTestCase.fail("Expected array of size ${expectedSize}; contained ${ar
ray.length} elements"); |
| 505 } | 528 } |
| 506 for (int i = 0; i < expectedSize; i++) { | 529 for (int i = 0; i < expectedSize; i++) { |
| 507 Object element = array[i]; | 530 Object element = array[i]; |
| 508 Object expectedElement = expectedElements[i]; | 531 Object expectedElement = expectedElements[i]; |
| 509 if (!element == expectedElement) { | 532 if (!element == expectedElement) { |
| 510 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); | 533 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); |
| 511 } | 534 } |
| 512 } | 535 } |
| 513 } | 536 } |
| 514 | 537 |
| 515 /** | 538 /** |
| 516 * Assert that the given list is non-`null` and has exactly expected elements. | 539 * Assert that the given list is non-`null` and has exactly expected elements. |
| 540 * |
| 517 * @param set the list being tested | 541 * @param set the list being tested |
| 518 * @param expectedElements the expected elements | 542 * @param expectedElements the expected elements |
| 519 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected elements | 543 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected elements |
| 520 */ | 544 */ |
| 521 static void assertExactElements3(Set<Object> set, List<Object> expectedElement
s) { | 545 static void assertExactElements3(Set<Object> set, List<Object> expectedElement
s) { |
| 522 int expectedSize = expectedElements.length; | 546 int expectedSize = expectedElements.length; |
| 523 if (set == null) { | 547 if (set == null) { |
| 524 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 548 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 525 } | 549 } |
| 526 if (set.length != expectedSize) { | 550 if (set.length != expectedSize) { |
| 527 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${set
.length} elements"); | 551 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${set
.length} elements"); |
| 528 } | 552 } |
| 529 for (int i = 0; i < expectedSize; i++) { | 553 for (int i = 0; i < expectedSize; i++) { |
| 530 Object expectedElement = expectedElements[i]; | 554 Object expectedElement = expectedElements[i]; |
| 531 if (!set.contains(expectedElement)) { | 555 if (!set.contains(expectedElement)) { |
| 532 JUnitTestCase.fail("Expected ${expectedElement} in set${set}"); | 556 JUnitTestCase.fail("Expected ${expectedElement} in set${set}"); |
| 533 } | 557 } |
| 534 } | 558 } |
| 535 } | 559 } |
| 536 | 560 |
| 537 /** | 561 /** |
| 538 * Assert that the given object is an instance of the expected class. | 562 * Assert that the given object is an instance of the expected class. |
| 563 * |
| 539 * @param expectedClass the class that the object is expected to be an instanc
e of | 564 * @param expectedClass the class that the object is expected to be an instanc
e of |
| 540 * @param object the object being tested | 565 * @param object the object being tested |
| 541 * @return the object that was being tested | 566 * @return the object that was being tested |
| 542 * @throws Exception if the object is not an instance of the expected class | 567 * @throws Exception if the object is not an instance of the expected class |
| 543 */ | 568 */ |
| 544 static Object assertInstanceOf(Type expectedClass, Object object) { | 569 static Object assertInstanceOf(Type expectedClass, Object object) { |
| 545 if (!isInstanceOf(object, expectedClass)) { | 570 if (!isInstanceOf(object, expectedClass)) { |
| 546 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun
d ${(object == null ? "null" : object.runtimeType.toString())}"); | 571 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun
d ${(object == null ? "null" : object.runtimeType.toString())}"); |
| 547 } | 572 } |
| 548 return object as Object; | 573 return object as Object; |
| 549 } | 574 } |
| 550 | 575 |
| 551 /** | 576 /** |
| 552 * Assert that the given array is non-`null` and has the expected number of el
ements. | 577 * Assert that the given array is non-`null` and has the expected number of el
ements. |
| 578 * |
| 553 * @param expectedLength the expected number of elements | 579 * @param expectedLength the expected number of elements |
| 554 * @param array the array being tested | 580 * @param array the array being tested |
| 555 * @throws AssertionFailedError if the array is `null` or does not have the ex
pected number | 581 * @throws AssertionFailedError if the array is `null` or does not have the ex
pected number |
| 556 * of elements | 582 * of elements |
| 557 */ | 583 */ |
| 558 static void assertLength(int expectedLength, List<Object> array) { | 584 static void assertLength(int expectedLength, List<Object> array) { |
| 559 if (array == null) { | 585 if (array == null) { |
| 560 JUnitTestCase.fail("Expected array of length ${expectedLength}; found null
"); | 586 JUnitTestCase.fail("Expected array of length ${expectedLength}; found null
"); |
| 561 } else if (array.length != expectedLength) { | 587 } else if (array.length != expectedLength) { |
| 562 JUnitTestCase.fail("Expected array of length ${expectedLength}; contained
${array.length} elements"); | 588 JUnitTestCase.fail("Expected array of length ${expectedLength}; contained
${array.length} elements"); |
| 563 } | 589 } |
| 564 } | 590 } |
| 565 | 591 |
| 566 /** | 592 /** |
| 567 * Assert that the actual token has the same type and lexeme as the expected t
oken. Note that this | 593 * Assert that the actual token has the same type and lexeme as the expected t
oken. Note that this |
| 568 * does not assert anything about the offsets of the tokens (although the leng
ths will be equal). | 594 * does not assert anything about the offsets of the tokens (although the leng
ths will be equal). |
| 595 * |
| 569 * @param expectedToken the token that was expected | 596 * @param expectedToken the token that was expected |
| 570 * @param actualToken the token that was found | 597 * @param actualToken the token that was found |
| 571 * @throws AssertionFailedError if the two tokens are not the same | 598 * @throws AssertionFailedError if the two tokens are not the same |
| 572 */ | 599 */ |
| 573 static void assertMatches(Token expectedToken, Token actualToken) { | 600 static void assertMatches(Token expectedToken, Token actualToken) { |
| 574 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type); | 601 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type); |
| 575 if (expectedToken is KeywordToken) { | 602 if (expectedToken is KeywordToken) { |
| 576 assertInstanceOf(KeywordToken, actualToken); | 603 assertInstanceOf(KeywordToken, actualToken); |
| 577 JUnitTestCase.assertEquals(((expectedToken as KeywordToken)).keyword, ((ac
tualToken as KeywordToken)).keyword); | 604 JUnitTestCase.assertEquals(((expectedToken as KeywordToken)).keyword, ((ac
tualToken as KeywordToken)).keyword); |
| 578 } else if (expectedToken is StringToken) { | 605 } else if (expectedToken is StringToken) { |
| 579 assertInstanceOf(StringToken, actualToken); | 606 assertInstanceOf(StringToken, actualToken); |
| 580 JUnitTestCase.assertEquals(((expectedToken as StringToken)).lexeme, ((actu
alToken as StringToken)).lexeme); | 607 JUnitTestCase.assertEquals(((expectedToken as StringToken)).lexeme, ((actu
alToken as StringToken)).lexeme); |
| 581 } | 608 } |
| 582 } | 609 } |
| 583 | 610 |
| 584 /** | 611 /** |
| 585 * Assert that the given list is non-`null` and has the expected number of ele
ments. | 612 * Assert that the given list is non-`null` and has the expected number of ele
ments. |
| 613 * |
| 586 * @param expectedSize the expected number of elements | 614 * @param expectedSize the expected number of elements |
| 587 * @param list the list being tested | 615 * @param list the list being tested |
| 588 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected number | 616 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected number |
| 589 * of elements | 617 * of elements |
| 590 */ | 618 */ |
| 591 static void assertSize(int expectedSize, List<Object> list) { | 619 static void assertSize(int expectedSize, List<Object> list) { |
| 592 if (list == null) { | 620 if (list == null) { |
| 593 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 621 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 594 } else if (list.length != expectedSize) { | 622 } else if (list.length != expectedSize) { |
| 595 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); | 623 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); |
| 596 } | 624 } |
| 597 } | 625 } |
| 598 | 626 |
| 599 /** | 627 /** |
| 600 * Assert that the given map is non-`null` and has the expected number of elem
ents. | 628 * Assert that the given map is non-`null` and has the expected number of elem
ents. |
| 629 * |
| 601 * @param expectedSize the expected number of elements | 630 * @param expectedSize the expected number of elements |
| 602 * @param map the map being tested | 631 * @param map the map being tested |
| 603 * @throws AssertionFailedError if the map is `null` or does not have the expe
cted number of | 632 * @throws AssertionFailedError if the map is `null` or does not have the expe
cted number of |
| 604 * elements | 633 * elements |
| 605 */ | 634 */ |
| 606 static void assertSize2(int expectedSize, Map<Object, Object> map) { | 635 static void assertSize2(int expectedSize, Map<Object, Object> map) { |
| 607 if (map == null) { | 636 if (map == null) { |
| 608 JUnitTestCase.fail("Expected map of size ${expectedSize}; found null"); | 637 JUnitTestCase.fail("Expected map of size ${expectedSize}; found null"); |
| 609 } else if (map.length != expectedSize) { | 638 } else if (map.length != expectedSize) { |
| 610 JUnitTestCase.fail("Expected map of size ${expectedSize}; contained ${map.
length} elements"); | 639 JUnitTestCase.fail("Expected map of size ${expectedSize}; contained ${map.
length} elements"); |
| 611 } | 640 } |
| 612 } | 641 } |
| 613 | 642 |
| 614 /** | 643 /** |
| 615 * Assert that the given set is non-`null` and has the expected number of elem
ents. | 644 * Assert that the given set is non-`null` and has the expected number of elem
ents. |
| 645 * |
| 616 * @param expectedSize the expected number of elements | 646 * @param expectedSize the expected number of elements |
| 617 * @param set the set being tested | 647 * @param set the set being tested |
| 618 * @throws AssertionFailedError if the set is `null` or does not have the expe
cted number of | 648 * @throws AssertionFailedError if the set is `null` or does not have the expe
cted number of |
| 619 * elements | 649 * elements |
| 620 */ | 650 */ |
| 621 static void assertSize3(int expectedSize, Set<Object> set) { | 651 static void assertSize3(int expectedSize, Set<Object> set) { |
| 622 if (set == null) { | 652 if (set == null) { |
| 623 JUnitTestCase.fail("Expected set of size ${expectedSize}; found null"); | 653 JUnitTestCase.fail("Expected set of size ${expectedSize}; found null"); |
| 624 } else if (set.length != expectedSize) { | 654 } else if (set.length != expectedSize) { |
| 625 JUnitTestCase.fail("Expected set of size ${expectedSize}; contained ${set.
length} elements"); | 655 JUnitTestCase.fail("Expected set of size ${expectedSize}; contained ${set.
length} elements"); |
| 626 } | 656 } |
| 627 } | 657 } |
| 628 | 658 |
| 629 /** | 659 /** |
| 630 * Convert the given array of lines into a single source string. | 660 * Convert the given array of lines into a single source string. |
| 661 * |
| 631 * @param lines the lines to be merged into a single source string | 662 * @param lines the lines to be merged into a single source string |
| 632 * @return the source string composed of the given lines | 663 * @return the source string composed of the given lines |
| 633 */ | 664 */ |
| 634 static String createSource(List<String> lines) { | 665 static String createSource(List<String> lines) { |
| 635 PrintStringWriter writer = new PrintStringWriter(); | 666 PrintStringWriter writer = new PrintStringWriter(); |
| 636 for (String line in lines) { | 667 for (String line in lines) { |
| 637 writer.println(line); | 668 writer.println(line); |
| 638 } | 669 } |
| 639 return writer.toString(); | 670 return writer.toString(); |
| 640 } | 671 } |
| 672 |
| 673 /** |
| 674 * @return the [ASTNode] with requested type at offset of the "prefix". |
| 675 */ |
| 676 static ASTNode findNode(ASTNode root, String code, String prefix, Type clazz)
{ |
| 677 int offset = code.indexOf(prefix); |
| 678 if (offset == -1) { |
| 679 throw new IllegalArgumentException("Not found '${prefix}'."); |
| 680 } |
| 681 ASTNode node = new NodeLocator.con1(offset).searchWithin(root); |
| 682 return node.getAncestor(clazz); |
| 683 } |
| 641 static void assertContains2(List<Object> array, List<bool> found, Object eleme
nt) { | 684 static void assertContains2(List<Object> array, List<bool> found, Object eleme
nt) { |
| 642 if (element == null) { | 685 if (element == null) { |
| 643 for (int i = 0; i < array.length; i++) { | 686 for (int i = 0; i < array.length; i++) { |
| 644 if (!found[i]) { | 687 if (!found[i]) { |
| 645 if (array[i] == null) { | 688 if (array[i] == null) { |
| 646 found[i] = true; | 689 found[i] = true; |
| 647 return; | 690 return; |
| 648 } | 691 } |
| 649 } | 692 } |
| 650 } | 693 } |
| 651 JUnitTestCase.fail("Does not contain null"); | 694 JUnitTestCase.fail("Does not contain null"); |
| 652 } else { | 695 } else { |
| 653 for (int i = 0; i < array.length; i++) { | 696 for (int i = 0; i < array.length; i++) { |
| 654 if (!found[i]) { | 697 if (!found[i]) { |
| 655 if (element == array[i]) { | 698 if (element == array[i]) { |
| 656 found[i] = true; | 699 found[i] = true; |
| 657 return; | 700 return; |
| 658 } | 701 } |
| 659 } | 702 } |
| 660 } | 703 } |
| 661 JUnitTestCase.fail("Does not contain ${element}"); | 704 JUnitTestCase.fail("Does not contain ${element}"); |
| 662 } | 705 } |
| 663 } | 706 } |
| 664 | 707 |
| 665 /** | 708 /** |
| 666 * Calculate the offset where the given strings differ. | 709 * Calculate the offset where the given strings differ. |
| 710 * |
| 667 * @param str1 the first String to compare | 711 * @param str1 the first String to compare |
| 668 * @param str2 the second String to compare | 712 * @param str2 the second String to compare |
| 669 * @return the offset at which the strings differ (or <code>-1</code> if they
do not) | 713 * @return the offset at which the strings differ (or <code>-1</code> if they
do not) |
| 670 */ | 714 */ |
| 671 static int getDiffPos(String str1, String str2) { | 715 static int getDiffPos(String str1, String str2) { |
| 672 int len1 = Math.min(str1.length, str2.length); | 716 int len1 = Math.min(str1.length, str2.length); |
| 673 int diffPos = -1; | 717 int diffPos = -1; |
| 674 for (int i = 0; i < len1; i++) { | 718 for (int i = 0; i < len1; i++) { |
| 675 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { | 719 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { |
| 676 diffPos = i; | 720 diffPos = i; |
| 677 break; | 721 break; |
| 678 } | 722 } |
| 679 } | 723 } |
| 680 if (diffPos == -1 && str1.length != str2.length) { | 724 if (diffPos == -1 && str1.length != str2.length) { |
| 681 diffPos = len1; | 725 diffPos = len1; |
| 682 } | 726 } |
| 683 return diffPos; | 727 return diffPos; |
| 684 } | 728 } |
| 685 AnalysisContextImpl createAnalysisContext() { | 729 AnalysisContextImpl createAnalysisContext() { |
| 686 AnalysisContextImpl context = new AnalysisContextImpl(); | 730 AnalysisContextImpl context = new AnalysisContextImpl(); |
| 687 context.sourceFactory = new SourceFactory.con2([]); | 731 context.sourceFactory = new SourceFactory.con2([]); |
| 688 return context; | 732 return context; |
| 689 } | 733 } |
| 690 | 734 |
| 691 /** | 735 /** |
| 692 * Return the getter in the given type with the given name. Inherited getters
are ignored. | 736 * Return the getter in the given type with the given name. Inherited getters
are ignored. |
| 737 * |
| 693 * @param type the type in which the getter is declared | 738 * @param type the type in which the getter is declared |
| 694 * @param getterName the name of the getter to be returned | 739 * @param getterName the name of the getter to be returned |
| 695 * @return the property accessor element representing the getter with the give
n name | 740 * @return the property accessor element representing the getter with the give
n name |
| 696 */ | 741 */ |
| 697 PropertyAccessorElement getGetter(InterfaceType type, String getterName) { | 742 PropertyAccessorElement getGetter(InterfaceType type, String getterName) { |
| 698 for (PropertyAccessorElement accessor in type.element.accessors) { | 743 for (PropertyAccessorElement accessor in type.element.accessors) { |
| 699 if (accessor.isGetter && accessor.name == getterName) { | 744 if (accessor.isGetter && accessor.name == getterName) { |
| 700 return accessor; | 745 return accessor; |
| 701 } | 746 } |
| 702 } | 747 } |
| 703 JUnitTestCase.fail("Could not find getter named ${getterName} in ${type.disp
layName}"); | 748 JUnitTestCase.fail("Could not find getter named ${getterName} in ${type.disp
layName}"); |
| 704 return null; | 749 return null; |
| 705 } | 750 } |
| 706 | 751 |
| 707 /** | 752 /** |
| 708 * Return the method in the given type with the given name. Inherited methods
are ignored. | 753 * Return the method in the given type with the given name. Inherited methods
are ignored. |
| 754 * |
| 709 * @param type the type in which the method is declared | 755 * @param type the type in which the method is declared |
| 710 * @param methodName the name of the method to be returned | 756 * @param methodName the name of the method to be returned |
| 711 * @return the method element representing the method with the given name | 757 * @return the method element representing the method with the given name |
| 712 */ | 758 */ |
| 713 MethodElement getMethod(InterfaceType type, String methodName) { | 759 MethodElement getMethod(InterfaceType type, String methodName) { |
| 714 for (MethodElement method in type.element.methods) { | 760 for (MethodElement method in type.element.methods) { |
| 715 if (method.name == methodName) { | 761 if (method.name == methodName) { |
| 716 return method; | 762 return method; |
| 717 } | 763 } |
| 718 } | 764 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 return trampoline(target, arguments[0], arguments[1]); | 831 return trampoline(target, arguments[0], arguments[1]); |
| 786 case 3: | 832 case 3: |
| 787 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 833 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 788 case 4: | 834 case 4: |
| 789 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 835 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 790 default: | 836 default: |
| 791 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 837 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 792 } | 838 } |
| 793 } | 839 } |
| 794 } | 840 } |
| OLD | NEW |