| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } else if (o is StringLiteral && r is StringLiteral) { | 266 } else if (o is StringLiteral && r is StringLiteral) { |
| 267 // We don't keep all the tokens of AdjacentStrings. | 267 // We don't keep all the tokens of AdjacentStrings. |
| 268 // So, we can compare only their values. | 268 // So, we can compare only their values. |
| 269 expect(r.stringValue, o.stringValue, reason: desc); | 269 expect(r.stringValue, o.stringValue, reason: desc); |
| 270 } else if (o is SymbolLiteral && r is SymbolLiteral) { | 270 } else if (o is SymbolLiteral && r is SymbolLiteral) { |
| 271 // We don't keep all the tokens of symbol literals. | 271 // We don't keep all the tokens of symbol literals. |
| 272 // So, we can compare only their values. | 272 // So, we can compare only their values. |
| 273 expect(r.components.map((t) => t.lexeme).join('.'), | 273 expect(r.components.map((t) => t.lexeme).join('.'), |
| 274 o.components.map((t) => t.lexeme).join('.'), | 274 o.components.map((t) => t.lexeme).join('.'), |
| 275 reason: desc); | 275 reason: desc); |
| 276 } else if (o is NamedExpression && r is NamedExpression) { |
| 277 expect(r.name.label.name, o.name.label.name, reason: desc); |
| 278 compareConstantExpressions(r.expression, o.expression, desc); |
| 276 } else if (o is BinaryExpression && r is BinaryExpression) { | 279 } else if (o is BinaryExpression && r is BinaryExpression) { |
| 277 expect(r.operator.lexeme, o.operator.lexeme, reason: desc); | 280 expect(r.operator.lexeme, o.operator.lexeme, reason: desc); |
| 278 compareConstantExpressions(r.leftOperand, o.leftOperand, desc); | 281 compareConstantExpressions(r.leftOperand, o.leftOperand, desc); |
| 279 compareConstantExpressions(r.rightOperand, o.rightOperand, desc); | 282 compareConstantExpressions(r.rightOperand, o.rightOperand, desc); |
| 280 } else if (o is PrefixExpression && r is PrefixExpression) { | 283 } else if (o is PrefixExpression && r is PrefixExpression) { |
| 281 expect(r.operator.lexeme, o.operator.lexeme, reason: desc); | 284 expect(r.operator.lexeme, o.operator.lexeme, reason: desc); |
| 282 compareConstantExpressions(r.operand, o.operand, desc); | 285 compareConstantExpressions(r.operand, o.operand, desc); |
| 283 } else if (o is ConditionalExpression && r is ConditionalExpression) { | 286 } else if (o is ConditionalExpression && r is ConditionalExpression) { |
| 284 compareConstantExpressions(r.condition, o.condition, desc); | 287 compareConstantExpressions(r.condition, o.condition, desc); |
| 285 compareConstantExpressions(r.thenExpression, o.thenExpression, desc); | 288 compareConstantExpressions(r.thenExpression, o.thenExpression, desc); |
| 286 compareConstantExpressions(r.elseExpression, o.elseExpression, desc); | 289 compareConstantExpressions(r.elseExpression, o.elseExpression, desc); |
| 287 } else if (o is ListLiteral && r is ListLiteral) { | 290 } else if (o is ListLiteral && r is ListLiteral) { |
| 288 compareLists(r.typeArguments?.arguments, o.typeArguments?.arguments); | 291 compareLists(r.typeArguments?.arguments, o.typeArguments?.arguments); |
| 289 compareLists(r.elements, o.elements); | 292 compareLists(r.elements, o.elements); |
| 290 } else if (o is MapLiteral && r is MapLiteral) { | 293 } else if (o is MapLiteral && r is MapLiteral) { |
| 291 compareLists(r.typeArguments?.arguments, o.typeArguments?.arguments); | 294 compareLists(r.typeArguments?.arguments, o.typeArguments?.arguments); |
| 292 compareLists(r.entries, o.entries); | 295 compareLists(r.entries, o.entries); |
| 296 } else if (o is InstanceCreationExpression && |
| 297 r is InstanceCreationExpression) { |
| 298 compareElements(r.staticElement, o.staticElement, desc); |
| 299 ConstructorName oConstructor = o.constructorName; |
| 300 ConstructorName rConstructor = r.constructorName; |
| 301 expect(oConstructor, isNotNull, reason: desc); |
| 302 expect(rConstructor, isNotNull, reason: desc); |
| 303 compareElements( |
| 304 rConstructor.staticElement, oConstructor.staticElement, desc); |
| 305 TypeName oType = oConstructor.type; |
| 306 TypeName rType = rConstructor.type; |
| 307 expect(oType, isNotNull, reason: desc); |
| 308 expect(rType, isNotNull, reason: desc); |
| 309 compareConstantExpressions(rType.name, oType.name, desc); |
| 310 compareConstantExpressions(rConstructor.name, oConstructor.name, desc); |
| 311 compareLists(r.argumentList.arguments, o.argumentList.arguments); |
| 312 } else if (o is ConstructorName && r is ConstructorName) { |
| 313 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}'); |
| 293 } else { | 314 } else { |
| 294 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}'); | 315 fail('Not implemented for ${r.runtimeType} vs. ${o.runtimeType}'); |
| 295 } | 316 } |
| 296 } | 317 } |
| 297 } | 318 } |
| 298 | 319 |
| 299 void compareConstructorElements(ConstructorElementImpl resynthesized, | 320 void compareConstructorElements(ConstructorElementImpl resynthesized, |
| 300 ConstructorElementImpl original, String desc) { | 321 ConstructorElementImpl original, String desc) { |
| 301 compareExecutableElements(resynthesized, original, desc); | 322 compareExecutableElements(resynthesized, original, desc); |
| 302 // TODO(paulberry): test redirectedConstructor and constantInitializers | 323 // TODO(paulberry): test redirectedConstructor and constantInitializers |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 } | 1027 } |
| 1007 | 1028 |
| 1008 test_class_type_parameters_f_bound_simple() { | 1029 test_class_type_parameters_f_bound_simple() { |
| 1009 checkLibrary('class C<T extends U, U> {}'); | 1030 checkLibrary('class C<T extends U, U> {}'); |
| 1010 } | 1031 } |
| 1011 | 1032 |
| 1012 test_classes() { | 1033 test_classes() { |
| 1013 checkLibrary('class C {} class D {}'); | 1034 checkLibrary('class C {} class D {}'); |
| 1014 } | 1035 } |
| 1015 | 1036 |
| 1037 test_const_invokeConstructor_named() { |
| 1038 shouldCompareConstValues = true; |
| 1039 checkLibrary(r''' |
| 1040 class C { |
| 1041 const C.named(bool a, int b, int c, {String d, double e}); |
| 1042 } |
| 1043 const V = const C.named(true, 1, 2, d: 'ccc', e: 3.4); |
| 1044 '''); |
| 1045 } |
| 1046 |
| 1047 test_const_invokeConstructor_named_imported() { |
| 1048 shouldCompareConstValues = true; |
| 1049 addLibrarySource( |
| 1050 '/a.dart', |
| 1051 r''' |
| 1052 class C { |
| 1053 const C.named(); |
| 1054 } |
| 1055 '''); |
| 1056 checkLibrary(r''' |
| 1057 import 'a.dart'; |
| 1058 const V = const C.named(); |
| 1059 '''); |
| 1060 } |
| 1061 |
| 1062 test_const_invokeConstructor_named_imported_withPrefix() { |
| 1063 shouldCompareConstValues = true; |
| 1064 addLibrarySource( |
| 1065 '/a.dart', |
| 1066 r''' |
| 1067 class C { |
| 1068 const C.named(); |
| 1069 } |
| 1070 '''); |
| 1071 checkLibrary(r''' |
| 1072 import 'a.dart' as p; |
| 1073 const V = const p.C.named(); |
| 1074 '''); |
| 1075 } |
| 1076 |
| 1077 test_const_invokeConstructor_unnamed() { |
| 1078 shouldCompareConstValues = true; |
| 1079 checkLibrary(r''' |
| 1080 class C { |
| 1081 const C(); |
| 1082 } |
| 1083 const V = const C(); |
| 1084 '''); |
| 1085 } |
| 1086 |
| 1087 test_const_invokeConstructor_unnamed_imported() { |
| 1088 shouldCompareConstValues = true; |
| 1089 addLibrarySource( |
| 1090 '/a.dart', |
| 1091 r''' |
| 1092 class C { |
| 1093 const C(); |
| 1094 } |
| 1095 '''); |
| 1096 checkLibrary(r''' |
| 1097 import 'a.dart'; |
| 1098 const V = const C(); |
| 1099 '''); |
| 1100 } |
| 1101 |
| 1102 test_const_invokeConstructor_unnamed_imported_withPrefix() { |
| 1103 shouldCompareConstValues = true; |
| 1104 addLibrarySource( |
| 1105 '/a.dart', |
| 1106 r''' |
| 1107 class C { |
| 1108 const C(); |
| 1109 } |
| 1110 '''); |
| 1111 checkLibrary(r''' |
| 1112 import 'a.dart' as p; |
| 1113 const V = const p.C(); |
| 1114 '''); |
| 1115 } |
| 1116 |
| 1016 test_const_reference_staticField() { | 1117 test_const_reference_staticField() { |
| 1017 shouldCompareConstValues = true; | 1118 shouldCompareConstValues = true; |
| 1018 checkLibrary(r''' | 1119 checkLibrary(r''' |
| 1019 class C { | 1120 class C { |
| 1020 static const int F = 42; | 1121 static const int F = 42; |
| 1021 } | 1122 } |
| 1022 const V = C.F; | 1123 const V = C.F; |
| 1023 '''); | 1124 '''); |
| 1024 } | 1125 } |
| 1025 | 1126 |
| (...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2250 fail('Unexpectedly tried to get unlinked summary for $uri'); | 2351 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 2251 } | 2352 } |
| 2252 return serializedUnit; | 2353 return serializedUnit; |
| 2253 } | 2354 } |
| 2254 | 2355 |
| 2255 @override | 2356 @override |
| 2256 bool hasLibrarySummary(String uri) { | 2357 bool hasLibrarySummary(String uri) { |
| 2257 return true; | 2358 return true; |
| 2258 } | 2359 } |
| 2259 } | 2360 } |
| OLD | NEW |