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

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

Issue 752483002: More tests for expressions inside methods, constructors, initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | « no previous file | no next file » | 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 library engine.incremental_resolver_test; 5 library engine.incremental_resolver_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 main(int a, int b) { 839 main(int a, int b) {
840 return a + b; 840 return a + b;
841 } 841 }
842 '''); 842 ''');
843 _resolve(_editString(' return a + b;', r''' 843 _resolve(_editString(' return a + b;', r'''
844 int res = a + b; 844 int res = a + b;
845 return res; 845 return res;
846 '''), _isBlock); 846 '''), _isBlock);
847 } 847 }
848 848
849 void test_constructor_body() {
850 _resolveUnit(r'''
851 class A {
852 int f;
853 A(int a, int b) {
854 f = a + b;
855 }
856 }''');
857 _resolve(_editString('+', '*'), _isFunctionBody);
858 }
859
860 void test_constructor_fieldInitializer_edit() {
861 _resolveUnit(r'''
862 class A {
863 int f;
864 A(int a, int b) : f = a + b {
865 int a = 42;
866 }
867 }''');
868 _resolve(_editString('+', '*'), _isExpression);
869 }
870
871 void fail_test_constructor_fieldInitializer_add() {
872 // TODO(scheglov) resolver uses "enclosingClass", which we don't set yet
873 _resolveUnit(r'''
874 class A {
875 int f;
876 A(int a, int b);
877 }''');
878 _resolve(_editString(');', ') : f = a + b;'), _isClassMember);
879 }
880
881 void test_constructor_superConstructorInvocation() {
882 _resolveUnit(r'''
883 class A {
884 A(int p);
885 }
886 class A {
887 A(int a, int b) : super(a + b);
888 }
889 ''');
890 _resolve(_editString('+', '*'), _isExpression);
891 }
892
849 void test_functionBody_body() { 893 void test_functionBody_body() {
850 _resolveUnit(r''' 894 _resolveUnit(r'''
851 main(int a, int b) { 895 main(int a, int b) {
852 return a + b; 896 return a + b;
853 }'''); 897 }''');
854 _resolve(_editString('+', '*'), _isFunctionBody); 898 _resolve(_editString('+', '*'), _isFunctionBody);
855 } 899 }
856 900
901 void test_functionBody_expression() {
902 _resolveUnit(r'''
903 main(int a, int b) => a + b;
904 ''');
905 _resolve(_editString('+', '*'), _isExpression);
906 }
907
857 void test_functionBody_statement() { 908 void test_functionBody_statement() {
858 _resolveUnit(r''' 909 _resolveUnit(r'''
859 main(int a, int b) { 910 main(int a, int b) {
860 return a + b; 911 return a + b;
861 }'''); 912 }''');
862 _resolve(_editString('+', '*'), _isStatement); 913 _resolve(_editString('+', '*'), _isStatement);
863 } 914 }
864 915
916 void test_method_body() {
917 _resolveUnit(r'''
918 class A {
919 m(int a, int b) {
920 return a + b;
921 }
922 }''');
923 _resolve(_editString('+', '*'), _isFunctionBody);
924 }
925
926 void test_topLevelVariable_initializer() {
927 _resolveUnit(r'''
928 int C = 1 + 2;
929 ''');
930 _resolve(_editString('+', '*'), _isExpression);
931 }
932
865 void test_updateElementOffset() { 933 void test_updateElementOffset() {
866 _resolveUnit(r''' 934 _resolveUnit(r'''
867 class A { 935 class A {
868 int am(String ap) { 936 int am(String ap) {
869 int av = 1; 937 int av = 1;
870 return av; 938 return av;
871 } 939 }
872 } 940 }
873 main(int a, int b) { 941 main(int a, int b) {
874 return a + b; 942 return a + b;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 1011
944 static AstNode _findNodeAt(CompilationUnit oldUnit, int offset, 1012 static AstNode _findNodeAt(CompilationUnit oldUnit, int offset,
945 Predicate<AstNode> predicate) { 1013 Predicate<AstNode> predicate) {
946 NodeLocator locator = new NodeLocator.con1(offset); 1014 NodeLocator locator = new NodeLocator.con1(offset);
947 AstNode node = locator.searchWithin(oldUnit); 1015 AstNode node = locator.searchWithin(oldUnit);
948 return node.getAncestor(predicate); 1016 return node.getAncestor(predicate);
949 } 1017 }
950 1018
951 static bool _isBlock(AstNode node) => node is Block; 1019 static bool _isBlock(AstNode node) => node is Block;
952 1020
1021 static bool _isExpression(AstNode node) => node is Expression;
1022
1023 static bool _isClassMember(AstNode node) => node is ClassMember;
1024
953 static bool _isFunctionBody(AstNode node) => node is FunctionBody; 1025 static bool _isFunctionBody(AstNode node) => node is FunctionBody;
954 1026
955 static bool _isStatement(AstNode node) => node is Statement; 1027 static bool _isStatement(AstNode node) => node is Statement;
956 1028
957 static CompilationUnit _parseUnit(String code) { 1029 static CompilationUnit _parseUnit(String code) {
958 var errorListener = new BooleanErrorListener(); 1030 var errorListener = new BooleanErrorListener();
959 var reader = new CharSequenceReader(code); 1031 var reader = new CharSequenceReader(code);
960 var scanner = new Scanner(null, reader, errorListener); 1032 var scanner = new Scanner(null, reader, errorListener);
961 var token = scanner.tokenize(); 1033 var token = scanner.tokenize();
962 var parser = new Parser(null, errorListener); 1034 var parser = new Parser(null, errorListener);
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
2042 _visitList(node.metadata, other.metadata); 2114 _visitList(node.metadata, other.metadata);
2043 _visitNode(node.identifier, other.identifier); 2115 _visitNode(node.identifier, other.identifier);
2044 } 2116 }
2045 2117
2046 static void assertSameResolution(CompilationUnit actual, 2118 static void assertSameResolution(CompilationUnit actual,
2047 CompilationUnit expected) { 2119 CompilationUnit expected) {
2048 _SameResolutionValidator validator = new _SameResolutionValidator(expected); 2120 _SameResolutionValidator validator = new _SameResolutionValidator(expected);
2049 actual.accept(validator); 2121 actual.accept(validator);
2050 } 2122 }
2051 } 2123 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698