| 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 library engine.test_support; | 4 library engine.test_support; |
| 5 |
| 4 import 'package:analyzer/src/generated/java_core.dart'; | 6 import 'package:analyzer/src/generated/java_core.dart'; |
| 5 import 'package:analyzer/src/generated/java_junit.dart'; | 7 import 'package:analyzer/src/generated/java_junit.dart'; |
| 6 import 'package:analyzer/src/generated/source.dart'; | 8 import 'package:analyzer/src/generated/source.dart'; |
| 7 import 'package:analyzer/src/generated/error.dart'; | 9 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| 9 import 'package:analyzer/src/generated/ast.dart' show ASTNode, NodeLocator; | 11 import 'package:analyzer/src/generated/ast.dart' show ASTNode, NodeLocator; |
| 10 import 'package:analyzer/src/generated/element.dart' show InterfaceType, MethodE
lement, PropertyAccessorElement; | 12 import 'package:analyzer/src/generated/element.dart' show InterfaceType, MethodE
lement, PropertyAccessorElement; |
| 11 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext, Analys
isContextImpl, RecordingErrorListener; | 13 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext, Analys
isContextImpl, RecordingErrorListener; |
| 12 import 'package:unittest/unittest.dart' as _ut; | 14 import 'package:unittest/unittest.dart' as _ut; |
| 15 |
| 13 /** | 16 /** |
| 14 * Instances of the class `GatheringErrorListener` implement an error listener t
hat collects | 17 * Instances of the class `GatheringErrorListener` implement an error listener t
hat collects |
| 15 * all of the errors passed to it for later examination. | 18 * all of the errors passed to it for later examination. |
| 16 */ | 19 */ |
| 17 class GatheringErrorListener implements AnalysisErrorListener { | 20 class GatheringErrorListener implements AnalysisErrorListener { |
| 18 | |
| 19 /** | 21 /** |
| 20 * The source being parsed. | 22 * The source being parsed. |
| 21 */ | 23 */ |
| 22 String _rawSource; | 24 String _rawSource; |
| 23 | 25 |
| 24 /** | 26 /** |
| 25 * The source being parsed after inserting a marker at the beginning and end o
f the range of the | 27 * The source being parsed after inserting a marker at the beginning and end o
f the range of the |
| 26 * most recent error. | 28 * most recent error. |
| 27 */ | 29 */ |
| 28 String _markedSource; | 30 String _markedSource; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 242 } |
| 241 return false; | 243 return false; |
| 242 } | 244 } |
| 243 | 245 |
| 244 /** | 246 /** |
| 245 * Return `true` if at least one error has been gathered. | 247 * Return `true` if at least one error has been gathered. |
| 246 * | 248 * |
| 247 * @return `true` if at least one error has been gathered | 249 * @return `true` if at least one error has been gathered |
| 248 */ | 250 */ |
| 249 bool hasErrors() => errors.length > 0; | 251 bool hasErrors() => errors.length > 0; |
| 252 |
| 250 void onError(AnalysisError error) { | 253 void onError(AnalysisError error) { |
| 251 if (_rawSource != null) { | 254 if (_rawSource != null) { |
| 252 int left = error.offset; | 255 int left = error.offset; |
| 253 int right = left + error.length - 1; | 256 int right = left + error.length - 1; |
| 254 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; | 257 _markedSource = "${_rawSource.substring(0, left)}^${_rawSource.substring(l
eft, right)}^${_rawSource.substring(right)}"; |
| 255 } | 258 } |
| 256 errors.add(error); | 259 errors.add(error); |
| 257 } | 260 } |
| 258 | 261 |
| 259 /** | 262 /** |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 bool foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) { | 380 bool foundAndRemoved(List<AnalysisError> errors, AnalysisError targetError) { |
| 378 for (AnalysisError error in errors) { | 381 for (AnalysisError error in errors) { |
| 379 if (equals4(error, targetError)) { | 382 if (equals4(error, targetError)) { |
| 380 errors.remove(error); | 383 errors.remove(error); |
| 381 return true; | 384 return true; |
| 382 } | 385 } |
| 383 } | 386 } |
| 384 return true; | 387 return true; |
| 385 } | 388 } |
| 386 } | 389 } |
| 390 |
| 387 /** | 391 /** |
| 388 * The class `EngineTestCase` defines utility methods for making assertions. | 392 * The class `EngineTestCase` defines utility methods for making assertions. |
| 389 */ | 393 */ |
| 390 class EngineTestCase extends JUnitTestCase { | 394 class EngineTestCase extends JUnitTestCase { |
| 391 static int _PRINT_RANGE = 6; | 395 static int _PRINT_RANGE = 6; |
| 392 | 396 |
| 393 /** | 397 /** |
| 394 * Assert that the tokens in the actual stream of tokens have the same types a
nd lexemes as the | 398 * Assert that the tokens in the actual stream of tokens have the same types a
nd lexemes as the |
| 395 * tokens in the expected stream of tokens. Note that this does not assert any
thing about the | 399 * tokens in the expected stream of tokens. Note that this does not assert any
thing about the |
| 396 * offsets of the tokens (although the lengths will be equal). | 400 * offsets of the tokens (although the lengths will be equal). |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 * does not assert anything about the offsets of the tokens (although the leng
ths will be equal). | 602 * does not assert anything about the offsets of the tokens (although the leng
ths will be equal). |
| 599 * | 603 * |
| 600 * @param expectedToken the token that was expected | 604 * @param expectedToken the token that was expected |
| 601 * @param actualToken the token that was found | 605 * @param actualToken the token that was found |
| 602 * @throws AssertionFailedError if the two tokens are not the same | 606 * @throws AssertionFailedError if the two tokens are not the same |
| 603 */ | 607 */ |
| 604 static void assertMatches(Token expectedToken, Token actualToken) { | 608 static void assertMatches(Token expectedToken, Token actualToken) { |
| 605 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type); | 609 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type); |
| 606 if (expectedToken is KeywordToken) { | 610 if (expectedToken is KeywordToken) { |
| 607 assertInstanceOf(KeywordToken, actualToken); | 611 assertInstanceOf(KeywordToken, actualToken); |
| 608 JUnitTestCase.assertEquals(((expectedToken as KeywordToken)).keyword, ((ac
tualToken as KeywordToken)).keyword); | 612 JUnitTestCase.assertEquals((expectedToken as KeywordToken).keyword, (actua
lToken as KeywordToken).keyword); |
| 609 } else if (expectedToken is StringToken) { | 613 } else if (expectedToken is StringToken) { |
| 610 assertInstanceOf(StringToken, actualToken); | 614 assertInstanceOf(StringToken, actualToken); |
| 611 JUnitTestCase.assertEquals(((expectedToken as StringToken)).lexeme, ((actu
alToken as StringToken)).lexeme); | 615 JUnitTestCase.assertEquals((expectedToken as StringToken).lexeme, (actualT
oken as StringToken).lexeme); |
| 612 } | 616 } |
| 613 } | 617 } |
| 614 | 618 |
| 615 /** | 619 /** |
| 616 * Assert that the given collection is non-`null` and has the expected number
of elements. | 620 * Assert that the given collection is non-`null` and has the expected number
of elements. |
| 617 * | 621 * |
| 618 * @param expectedSize the expected number of elements | 622 * @param expectedSize the expected number of elements |
| 619 * @param c the collection being tested | 623 * @param c the collection being tested |
| 620 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected number | 624 * @throws AssertionFailedError if the list is `null` or does not have the exp
ected number |
| 621 * of elements | 625 * of elements |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 * @return the [ASTNode] with requested type at offset of the "prefix". | 698 * @return the [ASTNode] with requested type at offset of the "prefix". |
| 695 */ | 699 */ |
| 696 static ASTNode findNode(ASTNode root, String code, String prefix, Type clazz)
{ | 700 static ASTNode findNode(ASTNode root, String code, String prefix, Type clazz)
{ |
| 697 int offset = code.indexOf(prefix); | 701 int offset = code.indexOf(prefix); |
| 698 if (offset == -1) { | 702 if (offset == -1) { |
| 699 throw new IllegalArgumentException("Not found '${prefix}'."); | 703 throw new IllegalArgumentException("Not found '${prefix}'."); |
| 700 } | 704 } |
| 701 ASTNode node = new NodeLocator.con1(offset).searchWithin(root); | 705 ASTNode node = new NodeLocator.con1(offset).searchWithin(root); |
| 702 return node.getAncestor(clazz); | 706 return node.getAncestor(clazz); |
| 703 } | 707 } |
| 708 |
| 704 static void assertContains2(List<Object> array, List<bool> found, Object eleme
nt) { | 709 static void assertContains2(List<Object> array, List<bool> found, Object eleme
nt) { |
| 705 if (element == null) { | 710 if (element == null) { |
| 706 for (int i = 0; i < array.length; i++) { | 711 for (int i = 0; i < array.length; i++) { |
| 707 if (!found[i]) { | 712 if (!found[i]) { |
| 708 if (array[i] == null) { | 713 if (array[i] == null) { |
| 709 found[i] = true; | 714 found[i] = true; |
| 710 return; | 715 return; |
| 711 } | 716 } |
| 712 } | 717 } |
| 713 } | 718 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 739 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { | 744 if (str1.codeUnitAt(i) != str2.codeUnitAt(i)) { |
| 740 diffPos = i; | 745 diffPos = i; |
| 741 break; | 746 break; |
| 742 } | 747 } |
| 743 } | 748 } |
| 744 if (diffPos == -1 && str1.length != str2.length) { | 749 if (diffPos == -1 && str1.length != str2.length) { |
| 745 diffPos = len1; | 750 diffPos = len1; |
| 746 } | 751 } |
| 747 return diffPos; | 752 return diffPos; |
| 748 } | 753 } |
| 754 |
| 749 AnalysisContextImpl createAnalysisContext() { | 755 AnalysisContextImpl createAnalysisContext() { |
| 750 AnalysisContextImpl context = new AnalysisContextImpl(); | 756 AnalysisContextImpl context = new AnalysisContextImpl(); |
| 751 context.sourceFactory = new SourceFactory.con2([]); | 757 context.sourceFactory = new SourceFactory.con2([]); |
| 752 return context; | 758 return context; |
| 753 } | 759 } |
| 754 | 760 |
| 755 /** | 761 /** |
| 756 * Return the getter in the given type with the given name. Inherited getters
are ignored. | 762 * Return the getter in the given type with the given name. Inherited getters
are ignored. |
| 757 * | 763 * |
| 758 * @param type the type in which the getter is declared | 764 * @param type the type in which the getter is declared |
| (...skipping 19 matching lines...) Expand all Loading... |
| 778 */ | 784 */ |
| 779 MethodElement getMethod(InterfaceType type, String methodName) { | 785 MethodElement getMethod(InterfaceType type, String methodName) { |
| 780 for (MethodElement method in type.element.methods) { | 786 for (MethodElement method in type.element.methods) { |
| 781 if (method.name == methodName) { | 787 if (method.name == methodName) { |
| 782 return method; | 788 return method; |
| 783 } | 789 } |
| 784 } | 790 } |
| 785 JUnitTestCase.fail("Could not find method named ${methodName} in ${type.disp
layName}"); | 791 JUnitTestCase.fail("Could not find method named ${methodName} in ${type.disp
layName}"); |
| 786 return null; | 792 return null; |
| 787 } | 793 } |
| 794 |
| 788 static dartSuite() { | 795 static dartSuite() { |
| 789 _ut.group('EngineTestCase', () { | 796 _ut.group('EngineTestCase', () { |
| 790 }); | 797 }); |
| 791 } | 798 } |
| 792 } | 799 } |
| 800 |
| 793 main() { | 801 main() { |
| 794 } | 802 } |
| 795 | 803 |
| 796 class TestSource implements Source { | 804 class TestSource implements Source { |
| 797 int get hashCode => 0; | 805 int get hashCode => 0; |
| 798 bool operator ==(Object object) { | 806 bool operator ==(Object object) { |
| 799 return object is TestSource; | 807 return object is TestSource; |
| 800 } | 808 } |
| 801 AnalysisContext get context { | 809 AnalysisContext get context { |
| 802 throw new UnsupportedOperationException(); | 810 throw new UnsupportedOperationException(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 return trampoline(target, arguments[0], arguments[1]); | 859 return trampoline(target, arguments[0], arguments[1]); |
| 852 case 3: | 860 case 3: |
| 853 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 861 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 854 case 4: | 862 case 4: |
| 855 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 863 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 856 default: | 864 default: |
| 857 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 865 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 858 } | 866 } |
| 859 } | 867 } |
| 860 } | 868 } |
| OLD | NEW |