Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: pkg/analyzer/test/generated/test_support.dart

Issue 186153005: New analzyer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use meaningful name instead of '_' in predicate. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.test_support; 8 library engine.test_support;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
11 import 'package:analyzer/src/generated/java_junit.dart'; 11 import 'package:analyzer/src/generated/java_junit.dart';
12 import 'package:analyzer/src/generated/java_engine.dart';
12 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analyzer/src/generated/error.dart'; 14 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/scanner.dart'; 15 import 'package:analyzer/src/generated/scanner.dart';
15 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator; 16 import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator;
16 import 'package:analyzer/src/generated/element.dart' show InterfaceType, MethodE lement, PropertyAccessorElement; 17 import 'package:analyzer/src/generated/element.dart' show InterfaceType, MethodE lement, PropertyAccessorElement;
17 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:unittest/unittest.dart' as _ut; 19 import 'package:unittest/unittest.dart' as _ut;
19 20
20 /** 21 /**
21 * Instances of the class `GatheringErrorListener` implement an error listener t hat collects 22 * Instances of the class `GatheringErrorListener` implement an error listener t hat collects
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 611 }
611 612
612 /** 613 /**
613 * Assert that the given object is an instance of the expected class. 614 * Assert that the given object is an instance of the expected class.
614 * 615 *
615 * @param expectedClass the class that the object is expected to be an instanc e of 616 * @param expectedClass the class that the object is expected to be an instanc e of
616 * @param object the object being tested 617 * @param object the object being tested
617 * @return the object that was being tested 618 * @return the object that was being tested
618 * @throws Exception if the object is not an instance of the expected class 619 * @throws Exception if the object is not an instance of the expected class
619 */ 620 */
620 static Object assertInstanceOf(Type expectedClass, Object object) { 621 static Object assertInstanceOf(Predicate<Object> predicate, Type expectedClass , Object object) {
621 if (!isInstanceOf(object, expectedClass)) { 622 if (!predicate(object)) {
622 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun d ${(object == null ? "null" : object.runtimeType.toString())}"); 623 JUnitTestCase.fail("Expected instance of ${expectedClass.toString()}, foun d ${(object == null ? "null" : object.runtimeType.toString())}");
623 } 624 }
624 return object; 625 return object;
625 } 626 }
626 627
627 /** 628 /**
628 * Assert that the given array is non-`null` and has the expected number of el ements. 629 * Assert that the given array is non-`null` and has the expected number of el ements.
629 * 630 *
630 * @param expectedLength the expected number of elements 631 * @param expectedLength the expected number of elements
631 * @param array the array being tested 632 * @param array the array being tested
(...skipping 12 matching lines...) Expand all
644 * Assert that the actual token has the same type and lexeme as the expected t oken. Note that this 645 * Assert that the actual token has the same type and lexeme as the expected t oken. Note that this
645 * does not assert anything about the offsets of the tokens (although the leng ths will be equal). 646 * does not assert anything about the offsets of the tokens (although the leng ths will be equal).
646 * 647 *
647 * @param expectedToken the token that was expected 648 * @param expectedToken the token that was expected
648 * @param actualToken the token that was found 649 * @param actualToken the token that was found
649 * @throws AssertionFailedError if the two tokens are not the same 650 * @throws AssertionFailedError if the two tokens are not the same
650 */ 651 */
651 static void assertMatches(Token expectedToken, Token actualToken) { 652 static void assertMatches(Token expectedToken, Token actualToken) {
652 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type); 653 JUnitTestCase.assertEquals(expectedToken.type, actualToken.type);
653 if (expectedToken is KeywordToken) { 654 if (expectedToken is KeywordToken) {
654 assertInstanceOf(KeywordToken, actualToken); 655 assertInstanceOf((obj) => obj is KeywordToken, KeywordToken, actualToken);
655 JUnitTestCase.assertEquals(expectedToken.keyword, (actualToken as KeywordT oken).keyword); 656 JUnitTestCase.assertEquals(expectedToken.keyword, (actualToken as KeywordT oken).keyword);
656 } else if (expectedToken is StringToken) { 657 } else if (expectedToken is StringToken) {
657 assertInstanceOf(StringToken, actualToken); 658 assertInstanceOf((obj) => obj is StringToken, StringToken, actualToken);
658 JUnitTestCase.assertEquals(expectedToken.lexeme, (actualToken as StringTok en).lexeme); 659 JUnitTestCase.assertEquals(expectedToken.lexeme, (actualToken as StringTok en).lexeme);
659 } 660 }
660 } 661 }
661 662
662 /** 663 /**
663 * Assert that the given list is non-`null` and has the expected number of ele ments. 664 * Assert that the given list is non-`null` and has the expected number of ele ments.
664 * 665 *
665 * @param expectedSize the expected number of elements 666 * @param expectedSize the expected number of elements
666 * @param list the list being tested 667 * @param list the list being tested
667 * @throws AssertionFailedError if the list is `null` or does not have the exp ected number 668 * @throws AssertionFailedError if the list is `null` or does not have the exp ected number
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 PrintStringWriter writer = new PrintStringWriter(); 718 PrintStringWriter writer = new PrintStringWriter();
718 for (String line in lines) { 719 for (String line in lines) {
719 writer.println(line); 720 writer.println(line);
720 } 721 }
721 return writer.toString(); 722 return writer.toString();
722 } 723 }
723 724
724 /** 725 /**
725 * @return the [AstNode] with requested type at offset of the "prefix". 726 * @return the [AstNode] with requested type at offset of the "prefix".
726 */ 727 */
727 static AstNode findNode(AstNode root, String code, String prefix, Type clazz) { 728 static AstNode findNode(AstNode root, String code, String prefix, Predicate<As tNode> predicate) {
728 int offset = code.indexOf(prefix); 729 int offset = code.indexOf(prefix);
729 if (offset == -1) { 730 if (offset == -1) {
730 throw new IllegalArgumentException("Not found '${prefix}'."); 731 throw new IllegalArgumentException("Not found '${prefix}'.");
731 } 732 }
732 AstNode node = new NodeLocator.con1(offset).searchWithin(root); 733 AstNode node = new NodeLocator.con1(offset).searchWithin(root);
733 return node.getAncestor(clazz); 734 return node.getAncestor(predicate);
734 } 735 }
735 736
736 static void assertContains2(List<Object> array, List<bool> found, Object eleme nt) { 737 static void assertContains2(List<Object> array, List<bool> found, Object eleme nt) {
737 if (element == null) { 738 if (element == null) {
738 for (int i = 0; i < array.length; i++) { 739 for (int i = 0; i < array.length; i++) {
739 if (!found[i]) { 740 if (!found[i]) {
740 if (array[i] == null) { 741 if (array[i] == null) {
741 found[i] = true; 742 found[i] = true;
742 return; 743 return;
743 } 744 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 return trampoline(target, arguments[0], arguments[1]); 890 return trampoline(target, arguments[0], arguments[1]);
890 case 3: 891 case 3:
891 return trampoline(target, arguments[0], arguments[1], arguments[2]); 892 return trampoline(target, arguments[0], arguments[1], arguments[2]);
892 case 4: 893 case 4:
893 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]); 894 return trampoline(target, arguments[0], arguments[1], arguments[2], argu ments[3]);
894 default: 895 default:
895 throw new IllegalArgumentException("Not implemented for > 4 arguments"); 896 throw new IllegalArgumentException("Not implemented for > 4 arguments");
896 } 897 }
897 } 898 }
898 } 899 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | pkg/code_transformers/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698