| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.test_support; | 8 library engine.test_support; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| 11 | 11 |
| 12 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator; | 12 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator; |
| 13 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 15 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/java_core.dart'; | 16 import 'package:analyzer/src/generated/java_core.dart'; |
| 17 import 'package:analyzer/src/generated/java_engine.dart'; | 17 import 'package:analyzer/src/generated/java_engine.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
| 20 | 20 |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * The class `EngineTestCase` defines utility methods for making assertions. | 23 * The class `EngineTestCase` defines utility methods for making assertions. |
| 24 */ | 24 */ |
| 25 class EngineTestCase { | 25 class EngineTestCase { |
| 26 void setUp() {} | |
| 27 | |
| 28 void tearDown() {} | |
| 29 | |
| 30 /** | 26 /** |
| 31 * Assert that the given collection has the same number of elements as the num
ber of specified | 27 * Assert that the given collection has the same number of elements as the num
ber of specified |
| 32 * names, and that for each specified name, a corresponding element can be fou
nd in the given | 28 * names, and that for each specified name, a corresponding element can be fou
nd in the given |
| 33 * collection with that name. | 29 * collection with that name. |
| 34 * | 30 * |
| 35 * @param elements the elements | 31 * @param elements the elements |
| 36 * @param names the names | 32 * @param names the names |
| 37 */ | 33 */ |
| 38 void assertNamedElements(List<Element> elements, List<String> names) { | 34 void assertNamedElements(List<Element> elements, List<String> names) { |
| 39 for (String elemName in names) { | 35 for (String elemName in names) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 MethodElement getMethod(InterfaceType type, String methodName) { | 88 MethodElement getMethod(InterfaceType type, String methodName) { |
| 93 for (MethodElement method in type.element.methods) { | 89 for (MethodElement method in type.element.methods) { |
| 94 if (method.name == methodName) { | 90 if (method.name == methodName) { |
| 95 return method; | 91 return method; |
| 96 } | 92 } |
| 97 } | 93 } |
| 98 fail("Could not find method named $methodName in ${type.displayName}"); | 94 fail("Could not find method named $methodName in ${type.displayName}"); |
| 99 return null; | 95 return null; |
| 100 } | 96 } |
| 101 | 97 |
| 98 void setUp() {} |
| 99 |
| 100 void tearDown() {} |
| 101 |
| 102 /** | 102 /** |
| 103 * Assert that the given object is an instance of the expected class. | 103 * Assert that the given object is an instance of the expected class. |
| 104 * | 104 * |
| 105 * @param expectedClass the class that the object is expected to be an instanc
e of | 105 * @param expectedClass the class that the object is expected to be an instanc
e of |
| 106 * @param object the object being tested | 106 * @param object the object being tested |
| 107 * @return the object that was being tested | 107 * @return the object that was being tested |
| 108 * @throws Exception if the object is not an instance of the expected class | 108 * @throws Exception if the object is not an instance of the expected class |
| 109 */ | 109 */ |
| 110 static Object assertInstanceOf(Predicate<Object> predicate, | 110 static Object assertInstanceOf(Predicate<Object> predicate, |
| 111 Type expectedClass, Object object) { | 111 Type expectedClass, Object object) { |
| 112 if (!predicate(object)) { | 112 if (!predicate(object)) { |
| 113 fail("Expected instance of $expectedClass, found ${object == null ? "null"
: object.runtimeType}"); | 113 fail( |
| 114 "Expected instance of $expectedClass, found ${object == null ? "null"
: object.runtimeType}"); |
| 114 } | 115 } |
| 115 return object; | 116 return object; |
| 116 } | 117 } |
| 117 | 118 |
| 118 /** | 119 /** |
| 119 * @return the [AstNode] with requested type at offset of the "prefix". | 120 * @return the [AstNode] with requested type at offset of the "prefix". |
| 120 */ | 121 */ |
| 121 static AstNode findNode(AstNode root, String code, String prefix, | 122 static AstNode findNode(AstNode root, String code, String prefix, |
| 122 Predicate<AstNode> predicate) { | 123 Predicate<AstNode> predicate) { |
| 123 int offset = code.indexOf(prefix); | 124 int offset = code.indexOf(prefix); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 215 |
| 215 /** | 216 /** |
| 216 * Assert that the number of errors that have been gathered matches the number
of errors that are | 217 * Assert that the number of errors that have been gathered matches the number
of errors that are |
| 217 * given and that they have the expected error codes. The order in which the e
rrors were gathered | 218 * given and that they have the expected error codes. The order in which the e
rrors were gathered |
| 218 * is ignored. | 219 * is ignored. |
| 219 * | 220 * |
| 220 * @param expectedErrorCodes the error codes of the errors that should have be
en gathered | 221 * @param expectedErrorCodes the error codes of the errors that should have be
en gathered |
| 221 * @throws AssertionFailedError if a different number of errors have been gath
ered than were | 222 * @throws AssertionFailedError if a different number of errors have been gath
ered than were |
| 222 * expected | 223 * expected |
| 223 */ | 224 */ |
| 224 void assertErrorsWithCodes([List<ErrorCode> expectedErrorCodes = ErrorCode.EMP
TY_LIST]) { | 225 void assertErrorsWithCodes([List<ErrorCode> expectedErrorCodes = |
| 226 ErrorCode.EMPTY_LIST]) { |
| 225 StringBuffer buffer = new StringBuffer(); | 227 StringBuffer buffer = new StringBuffer(); |
| 226 // | 228 // |
| 227 // Verify that the expected error codes have a non-empty message. | 229 // Verify that the expected error codes have a non-empty message. |
| 228 // | 230 // |
| 229 for (ErrorCode errorCode in expectedErrorCodes) { | 231 for (ErrorCode errorCode in expectedErrorCodes) { |
| 230 expect(errorCode.message.isEmpty, isFalse, reason: "Empty error code messa
ge"); | 232 expect( |
| 233 errorCode.message.isEmpty, |
| 234 isFalse, |
| 235 reason: "Empty error code message"); |
| 231 } | 236 } |
| 232 // | 237 // |
| 233 // Compute the expected number of each type of error. | 238 // Compute the expected number of each type of error. |
| 234 // | 239 // |
| 235 HashMap<ErrorCode, int> expectedCounts = new HashMap<ErrorCode, int>(); | 240 HashMap<ErrorCode, int> expectedCounts = new HashMap<ErrorCode, int>(); |
| 236 for (ErrorCode code in expectedErrorCodes) { | 241 for (ErrorCode code in expectedErrorCodes) { |
| 237 int count = expectedCounts[code]; | 242 int count = expectedCounts[code]; |
| 238 if (count == null) { | 243 if (count == null) { |
| 239 count = 1; | 244 count = 1; |
| 240 } else { | 245 } else { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 int actualWarningCount = 0; | 338 int actualWarningCount = 0; |
| 334 for (AnalysisError error in _errors) { | 339 for (AnalysisError error in _errors) { |
| 335 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) { | 340 if (error.errorCode.errorSeverity == ErrorSeverity.ERROR) { |
| 336 actualErrorCount++; | 341 actualErrorCount++; |
| 337 } else { | 342 } else { |
| 338 actualWarningCount++; | 343 actualWarningCount++; |
| 339 } | 344 } |
| 340 } | 345 } |
| 341 if (expectedErrorCount != actualErrorCount || | 346 if (expectedErrorCount != actualErrorCount || |
| 342 expectedWarningCount != actualWarningCount) { | 347 expectedWarningCount != actualWarningCount) { |
| 343 fail("Expected $expectedErrorCount errors and $expectedWarningCount warnin
gs, found $actualErrorCount errors and $actualWarningCount warnings"); | 348 fail( |
| 349 "Expected $expectedErrorCount errors and $expectedWarningCount warning
s, found $actualErrorCount errors and $actualWarningCount warnings"); |
| 344 } | 350 } |
| 345 } | 351 } |
| 346 | 352 |
| 347 /** | 353 /** |
| 348 * Assert that no errors have been gathered. | 354 * Assert that no errors have been gathered. |
| 349 * | 355 * |
| 350 * @throws AssertionFailedError if any errors have been gathered | 356 * @throws AssertionFailedError if any errors have been gathered |
| 351 */ | 357 */ |
| 352 void assertNoErrors() { | 358 void assertNoErrors() { |
| 353 assertErrors(_NO_ERRORS); | 359 assertErrors(_NO_ERRORS); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 TestSource([this._name = '/test.dart', this._contents]); | 580 TestSource([this._name = '/test.dart', this._contents]); |
| 575 | 581 |
| 576 TimestampedData<String> get contents { | 582 TimestampedData<String> get contents { |
| 577 readCount++; | 583 readCount++; |
| 578 if (generateExceptionOnRead) { | 584 if (generateExceptionOnRead) { |
| 579 String msg = "I/O Exception while getting the contents of " + _name; | 585 String msg = "I/O Exception while getting the contents of " + _name; |
| 580 throw new Exception(msg); | 586 throw new Exception(msg); |
| 581 } | 587 } |
| 582 return new TimestampedData<String>(0, _contents); | 588 return new TimestampedData<String>(0, _contents); |
| 583 } | 589 } |
| 584 void setContents(String value) { | |
| 585 modificationStamp = new DateTime.now().millisecondsSinceEpoch; | |
| 586 _contents = value; | |
| 587 } | |
| 588 String get encoding { | 590 String get encoding { |
| 589 throw new UnsupportedOperationException(); | 591 throw new UnsupportedOperationException(); |
| 590 } | 592 } |
| 591 String get fullName { | 593 String get fullName { |
| 592 return _name; | 594 return _name; |
| 593 } | 595 } |
| 594 int get hashCode => 0; | 596 int get hashCode => 0; |
| 595 bool get isInSystemLibrary { | 597 bool get isInSystemLibrary { |
| 596 return false; | 598 return false; |
| 597 } | 599 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 613 bool exists() => exists2; | 615 bool exists() => exists2; |
| 614 void getContentsToReceiver(Source_ContentReceiver receiver) { | 616 void getContentsToReceiver(Source_ContentReceiver receiver) { |
| 615 throw new UnsupportedOperationException(); | 617 throw new UnsupportedOperationException(); |
| 616 } | 618 } |
| 617 Source resolve(String uri) { | 619 Source resolve(String uri) { |
| 618 throw new UnsupportedOperationException(); | 620 throw new UnsupportedOperationException(); |
| 619 } | 621 } |
| 620 Uri resolveRelativeUri(Uri uri) { | 622 Uri resolveRelativeUri(Uri uri) { |
| 621 return new Uri(scheme: 'file', path: _name).resolveUri(uri); | 623 return new Uri(scheme: 'file', path: _name).resolveUri(uri); |
| 622 } | 624 } |
| 625 void setContents(String value) { |
| 626 modificationStamp = new DateTime.now().millisecondsSinceEpoch; |
| 627 _contents = value; |
| 628 } |
| 623 } | 629 } |
| OLD | NEW |