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

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

Issue 750083002: Matching for import/export/part directives. (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
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 void test_false_enum_constants_remove() { 218 void test_false_enum_constants_remove() {
219 resetWithEnum(); 219 resetWithEnum();
220 _assertCompilationUnitMatches(false, r''' 220 _assertCompilationUnitMatches(false, r'''
221 enum E {A, B, C} 221 enum E {A, B, C}
222 ''', r''' 222 ''', r'''
223 enum E {A, B} 223 enum E {A, B}
224 '''); 224 ''');
225 } 225 }
226 226
227 void test_false_export_list_add() {
228 _assertCompilationUnitMatches(false, r'''
229 export 'dart:async';
230 ''', r'''
231 export 'dart:async';
232 export 'dart:math';
233 ''');
234 }
235
236 void test_false_export_list_remove() {
237 _assertCompilationUnitMatches(false, r'''
238 export 'dart:async';
239 export 'dart:math';
240 ''', r'''
241 export 'dart:async';
242 ''');
243 }
244
227 void test_false_extendsClause_add() { 245 void test_false_extendsClause_add() {
228 _assertCompilationUnitMatches(false, r''' 246 _assertCompilationUnitMatches(false, r'''
229 class A {} 247 class A {}
230 class B {} 248 class B {}
231 ''', r''' 249 ''', r'''
232 class A {} 250 class A {}
233 class B extends A {} 251 class B extends A {}
234 '''); 252 ''');
235 } 253 }
236 254
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 class A {} 425 class A {}
408 class B {} 426 class B {}
409 class C implements A, B {} 427 class C implements A, B {}
410 ''', r''' 428 ''', r'''
411 class A {} 429 class A {}
412 class B {} 430 class B {}
413 class C implements B, A {} 431 class C implements B, A {}
414 '''); 432 ''');
415 } 433 }
416 434
435 void test_false_import_hide_add() {
436 _assertCompilationUnitMatches(false, r'''
437 import 'dart:async' hide Future;
438 ''', r'''
439 import 'dart:async' hide Future, Stream;
440 ''');
441 }
442
443 void test_false_import_hide_remove() {
444 _assertCompilationUnitMatches(false, r'''
445 import 'dart:async' hide Future, Stream;
446 ''', r'''
447 import 'dart:async' hide Future;
448 ''');
449 }
450
451 void test_false_import_list_add() {
452 _assertCompilationUnitMatches(false, r'''
453 import 'dart:async';
454 ''', r'''
455 import 'dart:async';
456 import 'dart:math';
457 ''');
458 }
459
460 void test_false_import_list_remove() {
461 _assertCompilationUnitMatches(false, r'''
462 import 'dart:async';
463 import 'dart:math';
464 ''', r'''
465 import 'dart:async';
466 ''');
467 }
468
469 void test_false_import_prefix_add() {
470 _assertCompilationUnitMatches(false, r'''
471 import 'dart:async';
472 ''', r'''
473 import 'dart:async' as async;
474 ''');
475 }
476
477 void test_false_import_prefix_edit() {
478 _assertCompilationUnitMatches(false, r'''
479 import 'dart:async' as oldPrefix;
480 ''', r'''
481 import 'dart:async' as newPrefix;
482 ''');
483 }
484
485 void test_false_import_prefix_remove() {
486 _assertCompilationUnitMatches(false, r'''
487 import 'dart:async' as async;
488 ''', r'''
489 import 'dart:async';
490 ''');
491 }
492
493 void test_false_import_show_add() {
494 _assertCompilationUnitMatches(false, r'''
495 import 'dart:async' show Future;
496 ''', r'''
497 import 'dart:async' show Future, Stream;
498 ''');
499 }
500
501 void test_false_import_show_remove() {
502 _assertCompilationUnitMatches(false, r'''
503 import 'dart:async' show Future, Stream;
504 ''', r'''
505 import 'dart:async' show Future;
506 ''');
507 }
508
509 void test_false_part_list_add() {
510 addNamedSource('/unitA.dart', 'part of lib; class A {}');
511 addNamedSource('/unitB.dart', 'part of lib; class B {}');
512 _assertCompilationUnitMatches(false, r'''
513 library lib;
514 part 'unitA.dart';
515 ''', r'''
516 library lib;
517 part 'unitA.dart';
518 part 'unitB.dart';
519 ''');
520 }
521
522 void test_false_part_list_remove() {
523 addNamedSource('/unitA.dart', 'part of lib; class A {}');
524 addNamedSource('/unitB.dart', 'part of lib; class B {}');
525 _assertCompilationUnitMatches(false, r'''
526 library lib;
527 part 'unitA.dart';
528 part 'unitB.dart';
529 ''', r'''
530 library lib;
531 part 'unitA.dart';
532 ''');
533 }
534
417 void test_false_topLevelVariable_list_add() { 535 void test_false_topLevelVariable_list_add() {
418 _assertCompilationUnitMatches(false, r''' 536 _assertCompilationUnitMatches(false, r'''
419 const int A = 1; 537 const int A = 1;
420 const int C = 3; 538 const int C = 3;
421 ''', r''' 539 ''', r'''
422 const int A = 1; 540 const int A = 1;
423 const int B = 2; 541 const int B = 2;
424 const int C = 3; 542 const int C = 3;
425 '''); 543 ''');
426 } 544 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 main() { 812 main() {
695 int a = 42; 813 int a = 42;
696 } 814 }
697 ''', r''' 815 ''', r'''
698 main() { 816 main() {
699 int a = 42; 817 int a = 42;
700 } 818 }
701 '''); 819 ''');
702 } 820 }
703 821
822 void test_true_export_list_reorder() {
823 _assertCompilationUnitMatches(true, r'''
824 export 'dart:async';
825 export 'dart:math';
826 ''', r'''
827 export 'dart:math';
828 export 'dart:async';
829 ''');
830 }
831
832 void test_true_export_list_same() {
833 _assertCompilationUnitMatches(true, r'''
834 export 'dart:async';
835 export 'dart:math';
836 ''', r'''
837 export 'dart:async';
838 export 'dart:math';
839 ''');
840 }
841
704 void test_true_extendsClause_same() { 842 void test_true_extendsClause_same() {
705 _assertCompilationUnitMatches(true, r''' 843 _assertCompilationUnitMatches(true, r'''
706 class A {} 844 class A {}
707 class B extends A {} 845 class B extends A {}
708 ''', r''' 846 ''', r'''
709 class A {} 847 class A {}
710 class B extends A {} 848 class B extends A {}
711 '''); 849 ''');
712 } 850 }
713 851
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 void test_true_implementsClause_same() { 884 void test_true_implementsClause_same() {
747 _assertCompilationUnitMatches(true, r''' 885 _assertCompilationUnitMatches(true, r'''
748 class A {} 886 class A {}
749 class B implements A {} 887 class B implements A {}
750 ''', r''' 888 ''', r'''
751 class A {} 889 class A {}
752 class B implements A {} 890 class B implements A {}
753 '''); 891 ''');
754 } 892 }
755 893
894 void test_true_import_hide_reorder() {
895 _assertCompilationUnitMatches(true, r'''
896 import 'dart:async' hide Future, Stream;
897 ''', r'''
898 import 'dart:async' hide Stream, Future;
899 ''');
900 }
901
902 void test_true_import_list_reorder() {
903 _assertCompilationUnitMatches(true, r'''
904 import 'dart:async';
905 import 'dart:math';
906 ''', r'''
907 import 'dart:math';
908 import 'dart:async';
909 ''');
910 }
911
912 void test_true_import_list_same() {
913 _assertCompilationUnitMatches(true, r'''
914 import 'dart:async';
915 import 'dart:math';
916 ''', r'''
917 import 'dart:async';
918 import 'dart:math';
919 ''');
920 }
921
922 void test_true_import_prefix() {
923 _assertCompilationUnitMatches(true, r'''
924 import 'dart:async' as async;
925 ''', r'''
926 import 'dart:async' as async;
927 ''');
928 }
929
930 void test_true_import_show_reorder() {
931 _assertCompilationUnitMatches(true, r'''
932 import 'dart:async' show Future, Stream;
933 ''', r'''
934 import 'dart:async' show Stream, Future;
935 ''');
936 }
937
938 void test_true_part_list_reorder() {
939 addNamedSource('/unitA.dart', 'part of lib; class A {}');
940 addNamedSource('/unitB.dart', 'part of lib; class B {}');
941 _assertCompilationUnitMatches(true, r'''
942 library lib;
943 part 'unitA.dart';
944 part 'unitB.dart';
945 ''', r'''
946 library lib;
947 part 'unitB.dart';
948 part 'unitA.dart';
949 ''');
950 }
951
952 void test_true_part_list_same() {
953 addNamedSource('/unitA.dart', 'part of lib; class A {}');
954 addNamedSource('/unitB.dart', 'part of lib; class B {}');
955 _assertCompilationUnitMatches(true, r'''
956 library lib;
957 part 'unitA.dart';
958 part 'unitB.dart';
959 ''', r'''
960 library lib;
961 part 'unitA.dart';
962 part 'unitB.dart';
963 ''');
964 }
965
756 void test_true_topLevelVariable_list_reorder() { 966 void test_true_topLevelVariable_list_reorder() {
757 _assertCompilationUnitMatches(true, r''' 967 _assertCompilationUnitMatches(true, r'''
758 const int A = 1; 968 const int A = 1;
759 const int B = 2; 969 const int B = 2;
760 const int C = 3; 970 const int C = 3;
761 ''', r''' 971 ''', r'''
762 const int C = 3; 972 const int C = 3;
763 const int A = 1; 973 const int A = 1;
764 const int B = 2; 974 const int B = 2;
765 '''); 975 ''');
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } 1035 }
826 } 1036 }
827 1037
828 1038
829 class IncrementalResolverTest extends ResolverTestCase { 1039 class IncrementalResolverTest extends ResolverTestCase {
830 Source source; 1040 Source source;
831 String code; 1041 String code;
832 LibraryElement library; 1042 LibraryElement library;
833 CompilationUnit unit; 1043 CompilationUnit unit;
834 1044
1045 void fail_test_constructor_fieldInitializer_add() {
1046 // TODO(scheglov) resolver uses "enclosingClass", which we don't set yet
1047 _resolveUnit(r'''
1048 class A {
1049 int f;
1050 A(int a, int b);
1051 }''');
1052 _resolve(_editString(');', ') : f = a + b;'), _isClassMember);
1053 }
1054
835 void fail_test_functionBody_addLocalVariable() { 1055 void fail_test_functionBody_addLocalVariable() {
836 // TODO(scheglov) this test fails, because we don't create element models 1056 // TODO(scheglov) this test fails, because we don't create element models
837 // for new local variables 1057 // for new local variables
838 _resolveUnit(r''' 1058 _resolveUnit(r'''
839 main(int a, int b) { 1059 main(int a, int b) {
840 return a + b; 1060 return a + b;
841 } 1061 }
842 '''); 1062 ''');
843 _resolve(_editString(' return a + b;', r''' 1063 _resolve(_editString(' return a + b;', r'''
844 int res = a + b; 1064 int res = a + b;
(...skipping 16 matching lines...) Expand all
861 _resolveUnit(r''' 1081 _resolveUnit(r'''
862 class A { 1082 class A {
863 int f; 1083 int f;
864 A(int a, int b) : f = a + b { 1084 A(int a, int b) : f = a + b {
865 int a = 42; 1085 int a = 42;
866 } 1086 }
867 }'''); 1087 }''');
868 _resolve(_editString('+', '*'), _isExpression); 1088 _resolve(_editString('+', '*'), _isExpression);
869 } 1089 }
870 1090
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() { 1091 void test_constructor_superConstructorInvocation() {
882 _resolveUnit(r''' 1092 _resolveUnit(r'''
883 class A { 1093 class A {
884 A(int p); 1094 A(int p);
885 } 1095 }
886 class A { 1096 class A {
887 A(int a, int b) : super(a + b); 1097 A(int a, int b) : super(a + b);
888 } 1098 }
889 '''); 1099 ''');
890 _resolve(_editString('+', '*'), _isExpression); 1100 _resolve(_editString('+', '*'), _isExpression);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 1221
1012 static AstNode _findNodeAt(CompilationUnit oldUnit, int offset, 1222 static AstNode _findNodeAt(CompilationUnit oldUnit, int offset,
1013 Predicate<AstNode> predicate) { 1223 Predicate<AstNode> predicate) {
1014 NodeLocator locator = new NodeLocator.con1(offset); 1224 NodeLocator locator = new NodeLocator.con1(offset);
1015 AstNode node = locator.searchWithin(oldUnit); 1225 AstNode node = locator.searchWithin(oldUnit);
1016 return node.getAncestor(predicate); 1226 return node.getAncestor(predicate);
1017 } 1227 }
1018 1228
1019 static bool _isBlock(AstNode node) => node is Block; 1229 static bool _isBlock(AstNode node) => node is Block;
1020 1230
1231 static bool _isClassMember(AstNode node) => node is ClassMember;
1232
1021 static bool _isExpression(AstNode node) => node is Expression; 1233 static bool _isExpression(AstNode node) => node is Expression;
1022 1234
1023 static bool _isClassMember(AstNode node) => node is ClassMember;
1024
1025 static bool _isFunctionBody(AstNode node) => node is FunctionBody; 1235 static bool _isFunctionBody(AstNode node) => node is FunctionBody;
1026 1236
1027 static bool _isStatement(AstNode node) => node is Statement; 1237 static bool _isStatement(AstNode node) => node is Statement;
1028 1238
1029 static CompilationUnit _parseUnit(String code) { 1239 static CompilationUnit _parseUnit(String code) {
1030 var errorListener = new BooleanErrorListener(); 1240 var errorListener = new BooleanErrorListener();
1031 var reader = new CharSequenceReader(code); 1241 var reader = new CharSequenceReader(code);
1032 var scanner = new Scanner(null, reader, errorListener); 1242 var scanner = new Scanner(null, reader, errorListener);
1033 var token = scanner.tokenize(); 1243 var token = scanner.tokenize();
1034 var parser = new Parser(null, errorListener); 1244 var parser = new Parser(null, errorListener);
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 _visitList(node.metadata, other.metadata); 2324 _visitList(node.metadata, other.metadata);
2115 _visitNode(node.identifier, other.identifier); 2325 _visitNode(node.identifier, other.identifier);
2116 } 2326 }
2117 2327
2118 static void assertSameResolution(CompilationUnit actual, 2328 static void assertSameResolution(CompilationUnit actual,
2119 CompilationUnit expected) { 2329 CompilationUnit expected) {
2120 _SameResolutionValidator validator = new _SameResolutionValidator(expected); 2330 _SameResolutionValidator validator = new _SameResolutionValidator(expected);
2121 actual.accept(validator); 2331 actual.accept(validator);
2122 } 2332 }
2123 } 2333 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698