Chromium Code Reviews| 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 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 _assertCompilationUnitMatches(false, r''' | 259 _assertCompilationUnitMatches(false, r''' |
| 260 class A { | 260 class A { |
| 261 A(int p) {} | 261 A(int p) {} |
| 262 } | 262 } |
| 263 ''', r''' | 263 ''', r''' |
| 264 class A { | 264 class A { |
| 265 } | 265 } |
| 266 '''); | 266 '''); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void test_false_defaultFieldFormalParameterElement_wasSimple() { | |
| 270 _assertCompilationUnitMatches(false, r''' | |
| 271 class A { | |
| 272 int field; | |
| 273 A(int field); | |
| 274 } | |
| 275 ''', r''' | |
| 276 class A { | |
| 277 int field; | |
| 278 A([this.field = 0]); | |
| 279 } | |
| 280 '''); | |
| 281 } | |
| 282 | |
| 269 void test_false_enum_constants_add() { | 283 void test_false_enum_constants_add() { |
| 270 resetWithEnum(); | 284 resetWithEnum(); |
| 271 _assertCompilationUnitMatches(false, r''' | 285 _assertCompilationUnitMatches(false, r''' |
| 272 enum E {A, B} | 286 enum E {A, B} |
| 273 ''', r''' | 287 ''', r''' |
| 274 enum E {A, B, C} | 288 enum E {A, B, C} |
| 275 '''); | 289 '''); |
| 276 } | 290 } |
| 277 | 291 |
| 278 void test_false_enum_constants_remove() { | 292 void test_false_enum_constants_remove() { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 class T { | 487 class T { |
| 474 List<int> A; | 488 List<int> A; |
| 475 } | 489 } |
| 476 ''', r''' | 490 ''', r''' |
| 477 class T { | 491 class T { |
| 478 List<String> A; | 492 List<String> A; |
| 479 } | 493 } |
| 480 '''); | 494 '''); |
| 481 } | 495 } |
| 482 | 496 |
| 497 void test_false_fieldFormalParameterElement_wasSimple() { | |
| 498 _assertCompilationUnitMatches(false, r''' | |
| 499 class A { | |
| 500 int field; | |
| 501 A(int field); | |
| 502 } | |
| 503 ''', r''' | |
| 504 class A { | |
| 505 int field; | |
| 506 A(this.field); | |
| 507 } | |
| 508 '''); | |
| 509 } | |
| 510 | |
| 483 void test_false_final_type_different() { | 511 void test_false_final_type_different() { |
| 484 _assertCompilationUnitMatches(false, r''' | 512 _assertCompilationUnitMatches(false, r''' |
| 485 class T { | 513 class T { |
| 486 int A; | 514 int A; |
| 487 } | 515 } |
| 488 ''', r''' | 516 ''', r''' |
| 489 class T { | 517 class T { |
| 490 String A; | 518 String A; |
| 491 } | 519 } |
| 492 '''); | 520 '''); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1017 class A { | 1045 class A { |
| 1018 A(int p); | 1046 A(int p); |
| 1019 } | 1047 } |
| 1020 ''', r''' | 1048 ''', r''' |
| 1021 class A { | 1049 class A { |
| 1022 A(int p); | 1050 A(int p); |
| 1023 } | 1051 } |
| 1024 '''); | 1052 '''); |
| 1025 } | 1053 } |
| 1026 | 1054 |
| 1055 void test_true_defaultFieldFormalParameterElement() { | |
| 1056 _assertCompilationUnitMatches(true, r''' | |
| 1057 class A { | |
| 1058 int field; | |
| 1059 A([this.field = 0]); | |
| 1060 } | |
| 1061 ''', r''' | |
| 1062 class A { | |
| 1063 int field; | |
| 1064 A([this.field = 0]); | |
| 1065 } | |
| 1066 '''); | |
| 1067 } | |
| 1068 | |
| 1027 void test_true_enum_constants_reorder() { | 1069 void test_true_enum_constants_reorder() { |
| 1028 resetWithEnum(); | 1070 resetWithEnum(); |
| 1029 _assertCompilationUnitMatches(true, r''' | 1071 _assertCompilationUnitMatches(true, r''' |
| 1030 enum E {A, B, C} | 1072 enum E {A, B, C} |
| 1031 ''', r''' | 1073 ''', r''' |
| 1032 enum E {C, A, B} | 1074 enum E {C, A, B} |
| 1033 '''); | 1075 '''); |
| 1034 } | 1076 } |
| 1035 | 1077 |
| 1036 void test_true_enum_list_reorder() { | 1078 void test_true_enum_list_reorder() { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 } | 1196 } |
| 1155 ''', r''' | 1197 ''', r''' |
| 1156 class T { | 1198 class T { |
| 1157 int A = 1; | 1199 int A = 1; |
| 1158 int B = 2; | 1200 int B = 2; |
| 1159 int C = 3; | 1201 int C = 3; |
| 1160 } | 1202 } |
| 1161 '''); | 1203 '''); |
| 1162 } | 1204 } |
| 1163 | 1205 |
| 1206 void test_true_fieldFormalParameterElement() { | |
| 1207 _assertCompilationUnitMatches(true, r''' | |
| 1208 class A { | |
| 1209 int field; | |
| 1210 A(this.field); | |
| 1211 } | |
| 1212 ''', r''' | |
| 1213 class A { | |
| 1214 int field; | |
| 1215 A(this.field); | |
| 1216 } | |
| 1217 '''); | |
| 1218 } | |
| 1219 | |
| 1164 void test_true_implementsClause_same() { | 1220 void test_true_implementsClause_same() { |
| 1165 _assertCompilationUnitMatches(true, r''' | 1221 _assertCompilationUnitMatches(true, r''' |
| 1166 class A {} | 1222 class A {} |
| 1167 class B implements A {} | 1223 class B implements A {} |
| 1168 ''', r''' | 1224 ''', r''' |
| 1169 class A {} | 1225 class A {} |
| 1170 class B implements A {} | 1226 class B implements A {} |
| 1171 '''); | 1227 '''); |
| 1172 } | 1228 } |
| 1173 | 1229 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1384 } | 1440 } |
| 1385 | 1441 |
| 1386 void test_true_topLevelVariable_type_sameArgs() { | 1442 void test_true_topLevelVariable_type_sameArgs() { |
| 1387 _assertCompilationUnitMatches(true, r''' | 1443 _assertCompilationUnitMatches(true, r''' |
| 1388 Map<int, String> A; | 1444 Map<int, String> A; |
| 1389 ''', r''' | 1445 ''', r''' |
| 1390 Map<int, String> A; | 1446 Map<int, String> A; |
| 1391 '''); | 1447 '''); |
| 1392 } | 1448 } |
| 1393 | 1449 |
| 1450 void test_true_type_dynamic() { | |
| 1451 _assertCompilationUnitMatches(true, r''' | |
| 1452 dynamic a() {} | |
| 1453 ''', r''' | |
| 1454 dynamic a() {} | |
| 1455 '''); | |
| 1456 } | |
| 1457 | |
| 1458 void test_true_type_noTypeArguments_implyAllDynamic() { | |
|
Brian Wilkerson
2014/11/24 21:06:41
Perhaps test some false cases for types, such as
scheglov
2014/11/24 21:12:03
Thank you.
Added.
| |
| 1459 _assertCompilationUnitMatches(true, r''' | |
| 1460 class A<T> {} | |
| 1461 A main() { | |
| 1462 } | |
| 1463 ''', r''' | |
| 1464 class A<T> {} | |
| 1465 A main() { | |
| 1466 } | |
| 1467 '''); | |
| 1468 } | |
| 1469 | |
| 1470 void test_true_type_void() { | |
| 1471 _assertCompilationUnitMatches(true, r''' | |
| 1472 void a() {} | |
| 1473 ''', r''' | |
| 1474 void a() {} | |
| 1475 '''); | |
| 1476 } | |
| 1477 | |
| 1394 void test_true_withClause_same() { | 1478 void test_true_withClause_same() { |
| 1395 _assertCompilationUnitMatches(true, r''' | 1479 _assertCompilationUnitMatches(true, r''' |
| 1396 class A {} | 1480 class A {} |
| 1397 class B extends Object with A {} | 1481 class B extends Object with A {} |
| 1398 ''', r''' | 1482 ''', r''' |
| 1399 class A {} | 1483 class A {} |
| 1400 class B extends Object with A {} | 1484 class B extends Object with A {} |
| 1401 '''); | 1485 '''); |
| 1402 } | 1486 } |
| 1403 | 1487 |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1875 _resetWithIncremental(false); | 1959 _resetWithIncremental(false); |
| 1876 source = addSource(newCode); | 1960 source = addSource(newCode); |
| 1877 LibraryElement library = resolve(source); | 1961 LibraryElement library = resolve(source); |
| 1878 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); | 1962 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); |
| 1879 // Validate that "incremental" and "full" units have the same resolution. | 1963 // Validate that "incremental" and "full" units have the same resolution. |
| 1880 _SameResolutionValidator.assertSameResolution(newUnit, fullNewUnit); | 1964 _SameResolutionValidator.assertSameResolution(newUnit, fullNewUnit); |
| 1881 _assertEqualsTokens(newUnit, fullNewUnit); | 1965 _assertEqualsTokens(newUnit, fullNewUnit); |
| 1882 } | 1966 } |
| 1883 } | 1967 } |
| 1884 | 1968 |
| 1969 static void _assertEqualsToken(Token incrToken, Token fullToken) { | |
| 1970 expect(incrToken.type, fullToken.type); | |
| 1971 expect(incrToken.offset, fullToken.offset); | |
| 1972 expect(incrToken.length, fullToken.length); | |
| 1973 expect(incrToken.lexeme, fullToken.lexeme); | |
| 1974 } | |
| 1975 | |
| 1885 static void _assertEqualsTokens(CompilationUnit incrUnit, | 1976 static void _assertEqualsTokens(CompilationUnit incrUnit, |
| 1886 CompilationUnit fullUnit) { | 1977 CompilationUnit fullUnit) { |
| 1887 Token incrToken = incrUnit.beginToken; | 1978 Token incrToken = incrUnit.beginToken; |
| 1888 Token fullToken = fullUnit.beginToken; | 1979 Token fullToken = fullUnit.beginToken; |
| 1889 while (incrToken.type != TokenType.EOF && fullToken.type != TokenType.EOF) { | 1980 while (incrToken.type != TokenType.EOF && fullToken.type != TokenType.EOF) { |
| 1890 // print('$incrToken @ ${incrToken.offset}'); | 1981 // print('$incrToken @ ${incrToken.offset}'); |
| 1891 // print('$fullToken @ ${fullToken.offset}'); | 1982 // print('$fullToken @ ${fullToken.offset}'); |
| 1892 _assertEqualsToken(incrToken, fullToken); | 1983 _assertEqualsToken(incrToken, fullToken); |
| 1893 incrToken = incrToken.next; | 1984 incrToken = incrToken.next; |
| 1894 fullToken = fullToken.next; | 1985 fullToken = fullToken.next; |
| 1895 } | 1986 } |
| 1896 } | 1987 } |
| 1897 | |
| 1898 static void _assertEqualsToken(Token incrToken, Token fullToken) { | |
| 1899 expect(incrToken.type, fullToken.type); | |
| 1900 expect(incrToken.offset, fullToken.offset); | |
| 1901 expect(incrToken.length, fullToken.length); | |
| 1902 expect(incrToken.lexeme, fullToken.lexeme); | |
| 1903 } | |
| 1904 } | 1988 } |
| 1905 | 1989 |
| 1906 | 1990 |
| 1907 class ResolutionContextBuilderTest extends EngineTestCase { | 1991 class ResolutionContextBuilderTest extends EngineTestCase { |
| 1908 GatheringErrorListener listener = new GatheringErrorListener(); | 1992 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1909 | 1993 |
| 1910 void test_scopeFor_ClassDeclaration() { | 1994 void test_scopeFor_ClassDeclaration() { |
| 1911 Scope scope = _scopeFor(_createResolvedClassDeclaration()); | 1995 Scope scope = _scopeFor(_createResolvedClassDeclaration()); |
| 1912 EngineTestCase.assertInstanceOf( | 1996 EngineTestCase.assertInstanceOf( |
| 1913 (obj) => obj is LibraryScope, | 1997 (obj) => obj is LibraryScope, |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2963 _visitList(node.metadata, other.metadata); | 3047 _visitList(node.metadata, other.metadata); |
| 2964 _visitNode(node.identifier, other.identifier); | 3048 _visitNode(node.identifier, other.identifier); |
| 2965 } | 3049 } |
| 2966 | 3050 |
| 2967 static void assertSameResolution(CompilationUnit actual, | 3051 static void assertSameResolution(CompilationUnit actual, |
| 2968 CompilationUnit expected) { | 3052 CompilationUnit expected) { |
| 2969 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | 3053 _SameResolutionValidator validator = new _SameResolutionValidator(expected); |
| 2970 actual.accept(validator); | 3054 actual.accept(validator); |
| 2971 } | 3055 } |
| 2972 } | 3056 } |
| OLD | NEW |