| 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/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart'; | 8 import 'package:analyzer/src/generated/source.dart'; |
| 9 import 'package:analyzer/src/summary/base.dart'; | 9 import 'package:analyzer/src/summary/base.dart'; |
| 10 import 'package:analyzer/src/summary/format.dart'; | 10 import 'package:analyzer/src/summary/format.dart'; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } | 342 } |
| 343 | 343 |
| 344 void compareTopLevelVariableElements( | 344 void compareTopLevelVariableElements( |
| 345 TopLevelVariableElementImpl resynthesized, | 345 TopLevelVariableElementImpl resynthesized, |
| 346 TopLevelVariableElementImpl original, | 346 TopLevelVariableElementImpl original, |
| 347 String desc) { | 347 String desc) { |
| 348 comparePropertyInducingElements(resynthesized, original, desc); | 348 comparePropertyInducingElements(resynthesized, original, desc); |
| 349 // TODO(paulberry): test evaluationResult | 349 // TODO(paulberry): test evaluationResult |
| 350 } | 350 } |
| 351 | 351 |
| 352 void compareTypeImpls(TypeImpl resynthesized, TypeImpl original) { | 352 void compareTypeImpls( |
| 353 expect(resynthesized.element.location, original.element.location); | 353 TypeImpl resynthesized, TypeImpl original, String desc) { |
| 354 expect(resynthesized.name, original.name); | 354 expect(resynthesized.element.location, original.element.location, |
| 355 reason: desc); |
| 356 expect(resynthesized.name, original.name, reason: desc); |
| 355 } | 357 } |
| 356 | 358 |
| 357 void compareTypeParameterElements(TypeParameterElementImpl resynthesized, | 359 void compareTypeParameterElements(TypeParameterElementImpl resynthesized, |
| 358 TypeParameterElementImpl original, String desc) { | 360 TypeParameterElementImpl original, String desc) { |
| 359 compareElements(resynthesized, original, desc); | 361 compareElements(resynthesized, original, desc); |
| 360 compareTypes(resynthesized.type, original.type, desc); | 362 compareTypes(resynthesized.type, original.type, desc); |
| 361 compareTypes(resynthesized.bound, original.bound, '$desc bound'); | 363 compareTypes(resynthesized.bound, original.bound, '$desc bound'); |
| 362 } | 364 } |
| 363 | 365 |
| 364 void compareTypes(DartType resynthesized, DartType original, String desc) { | 366 void compareTypes(DartType resynthesized, DartType original, String desc) { |
| 365 if (original == null) { | 367 if (original == null) { |
| 366 expect(resynthesized, isNull, reason: desc); | 368 expect(resynthesized, isNull, reason: desc); |
| 367 } else if (resynthesized is InterfaceTypeImpl && | 369 } else if (resynthesized is InterfaceTypeImpl && |
| 368 original is InterfaceTypeImpl) { | 370 original is InterfaceTypeImpl) { |
| 369 compareTypeImpls(resynthesized, original); | 371 compareTypeImpls(resynthesized, original, desc); |
| 370 expect(resynthesized.typeArguments.length, original.typeArguments.length); | 372 expect(resynthesized.typeArguments.length, original.typeArguments.length); |
| 371 for (int i = 0; i < resynthesized.typeArguments.length; i++) { | 373 for (int i = 0; i < resynthesized.typeArguments.length; i++) { |
| 372 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i], | 374 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i], |
| 373 '$desc type argument ${original.typeArguments[i].name}'); | 375 '$desc type argument ${original.typeArguments[i].name}'); |
| 374 } | 376 } |
| 375 } else if (resynthesized is TypeParameterTypeImpl && | 377 } else if (resynthesized is TypeParameterTypeImpl && |
| 376 original is TypeParameterTypeImpl) { | 378 original is TypeParameterTypeImpl) { |
| 377 compareTypeImpls(resynthesized, original); | 379 compareTypeImpls(resynthesized, original, desc); |
| 378 } else if (resynthesized is DynamicTypeImpl && | 380 } else if (resynthesized is DynamicTypeImpl && |
| 379 original is DynamicTypeImpl) { | 381 original is DynamicTypeImpl) { |
| 380 expect(resynthesized, same(original)); | 382 expect(resynthesized, same(original)); |
| 381 } else if (resynthesized is UndefinedTypeImpl && | 383 } else if (resynthesized is UndefinedTypeImpl && |
| 382 original is UndefinedTypeImpl) { | 384 original is UndefinedTypeImpl) { |
| 383 expect(resynthesized, same(original)); | 385 expect(resynthesized, same(original)); |
| 384 } else if (resynthesized is FunctionTypeImpl && | 386 } else if (resynthesized is FunctionTypeImpl && |
| 385 original is FunctionTypeImpl) { | 387 original is FunctionTypeImpl) { |
| 386 compareTypeImpls(resynthesized, original); | 388 compareTypeImpls(resynthesized, original, desc); |
| 387 if (original.element.isSynthetic && | 389 if (original.element.isSynthetic && |
| 388 original.element is FunctionTypeAliasElementImpl && | 390 original.element is FunctionTypeAliasElementImpl && |
| 389 resynthesized.element is FunctionTypeAliasElementImpl) { | 391 resynthesized.element is FunctionTypeAliasElementImpl) { |
| 390 compareFunctionTypeAliasElements( | 392 compareFunctionTypeAliasElements( |
| 391 resynthesized.element, original.element, desc); | 393 resynthesized.element, original.element, desc); |
| 392 } | 394 } |
| 395 expect(resynthesized.typeArguments.length, original.typeArguments.length, |
| 396 reason: desc); |
| 393 for (int i = 0; i < resynthesized.typeArguments.length; i++) { | 397 for (int i = 0; i < resynthesized.typeArguments.length; i++) { |
| 394 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i], | 398 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i], |
| 395 '$desc type argument ${original.typeArguments[i].name}'); | 399 '$desc type argument ${original.typeArguments[i].name}'); |
| 396 } | 400 } |
| 401 if (original.typeParameters == null) { |
| 402 expect(resynthesized.typeParameters, isNull, reason: desc); |
| 403 } else { |
| 404 expect(resynthesized.typeParameters, isNotNull, reason: desc); |
| 405 expect( |
| 406 resynthesized.typeParameters.length, original.typeParameters.length, |
| 407 reason: desc); |
| 408 for (int i = 0; i < resynthesized.typeParameters.length; i++) { |
| 409 compareTypeParameterElements(resynthesized.typeParameters[i], |
| 410 original.typeParameters[i], '$desc type parameter $i'); |
| 411 } |
| 412 } |
| 413 expect(resynthesized.boundTypeParameters.length, |
| 414 original.boundTypeParameters.length, |
| 415 reason: desc); |
| 416 for (int i = 0; i < resynthesized.boundTypeParameters.length; i++) { |
| 417 compareTypeParameterElements(resynthesized.boundTypeParameters[i], |
| 418 original.boundTypeParameters[i], '$desc bound type parameter $i'); |
| 419 } |
| 397 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) { | 420 } else if (resynthesized is VoidTypeImpl && original is VoidTypeImpl) { |
| 398 expect(resynthesized, same(original)); | 421 expect(resynthesized, same(original)); |
| 399 } else if (resynthesized.runtimeType != original.runtimeType) { | 422 } else if (resynthesized.runtimeType != original.runtimeType) { |
| 400 fail( | 423 fail( |
| 401 'Type mismatch: expected ${original.runtimeType}, got ${resynthesized.
runtimeType}'); | 424 'Type mismatch: expected ${original.runtimeType}, got ${resynthesized.
runtimeType}'); |
| 402 } else { | 425 } else { |
| 403 fail('Unimplemented comparison for ${original.runtimeType}'); | 426 fail('Unimplemented comparison for ${original.runtimeType}'); |
| 404 } | 427 } |
| 405 } | 428 } |
| 406 | 429 |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 } | 1070 } |
| 1048 | 1071 |
| 1049 test_variable_const() { | 1072 test_variable_const() { |
| 1050 checkLibrary('const int i = 0;'); | 1073 checkLibrary('const int i = 0;'); |
| 1051 } | 1074 } |
| 1052 | 1075 |
| 1053 test_variables() { | 1076 test_variables() { |
| 1054 checkLibrary('int i; int j;'); | 1077 checkLibrary('int i; int j;'); |
| 1055 } | 1078 } |
| 1056 } | 1079 } |
| OLD | NEW |