| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 expect(resynthesized.enclosingElement, isNull); | 48 expect(resynthesized.enclosingElement, isNull); |
| 49 compareCompilationUnitElements(resynthesized.definingCompilationUnit, | 49 compareCompilationUnitElements(resynthesized.definingCompilationUnit, |
| 50 original.definingCompilationUnit); | 50 original.definingCompilationUnit); |
| 51 expect(resynthesized.parts.length, original.parts.length); | 51 expect(resynthesized.parts.length, original.parts.length); |
| 52 for (int i = 0; i < resynthesized.parts.length; i++) { | 52 for (int i = 0; i < resynthesized.parts.length; i++) { |
| 53 compareCompilationUnitElements(resynthesized.parts[i], original.parts[i]); | 53 compareCompilationUnitElements(resynthesized.parts[i], original.parts[i]); |
| 54 } | 54 } |
| 55 expect(resynthesized.imports.length, original.imports.length); | 55 expect(resynthesized.imports.length, original.imports.length); |
| 56 for (int i = 0; i < resynthesized.imports.length; i++) { | 56 for (int i = 0; i < resynthesized.imports.length; i++) { |
| 57 compareImportElements(resynthesized.imports[i], original.imports[i], | 57 compareImportElements(resynthesized.imports[i], original.imports[i], |
| 58 'import ${original.imports[i].name}'); | 58 'import ${original.imports[i].uri}'); |
| 59 } | 59 } |
| 60 expect(resynthesized.exports.length, original.exports.length); | 60 expect(resynthesized.exports.length, original.exports.length); |
| 61 for (int i = 0; i < resynthesized.exports.length; i++) { | 61 for (int i = 0; i < resynthesized.exports.length; i++) { |
| 62 compareExportElements(resynthesized.exports[i], original.exports[i], | 62 compareExportElements(resynthesized.exports[i], original.exports[i], |
| 63 'export ${original.exports[i].name}'); | 63 'export ${original.exports[i].name}'); |
| 64 } | 64 } |
| 65 // TODO(paulberry): test entryPoint, exportNamespace, publicNamespace, | 65 // TODO(paulberry): test entryPoint, exportNamespace, publicNamespace, |
| 66 // and metadata. | 66 // and metadata. |
| 67 } | 67 } |
| 68 | 68 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 expect(resynthesized.methods.length, original.methods.length); | 121 expect(resynthesized.methods.length, original.methods.length); |
| 122 for (int i = 0; i < resynthesized.methods.length; i++) { | 122 for (int i = 0; i < resynthesized.methods.length; i++) { |
| 123 compareMethodElements(resynthesized.methods[i], original.methods[i], | 123 compareMethodElements(resynthesized.methods[i], original.methods[i], |
| 124 '$desc.${original.methods[i].name}'); | 124 '$desc.${original.methods[i].name}'); |
| 125 } | 125 } |
| 126 compareTypes(resynthesized.type, original.type, desc); | 126 compareTypes(resynthesized.type, original.type, desc); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized, | 129 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized, |
| 130 CompilationUnitElementImpl original) { | 130 CompilationUnitElementImpl original) { |
| 131 compareUriReferencedElements(resynthesized, original, '(compilation unit)'); | 131 String desc = 'Compilation unit ${original.source.uri}'; |
| 132 compareUriReferencedElements(resynthesized, original, desc); |
| 132 expect(resynthesized.source, original.source); | 133 expect(resynthesized.source, original.source); |
| 133 expect(resynthesized.librarySource, original.librarySource); | 134 expect(resynthesized.librarySource, original.librarySource); |
| 134 expect(resynthesized.types.length, original.types.length); | 135 expect(resynthesized.types.length, original.types.length); |
| 135 for (int i = 0; i < resynthesized.types.length; i++) { | 136 for (int i = 0; i < resynthesized.types.length; i++) { |
| 136 compareClassElements( | 137 compareClassElements( |
| 137 resynthesized.types[i], original.types[i], original.types[i].name); | 138 resynthesized.types[i], original.types[i], original.types[i].name); |
| 138 } | 139 } |
| 139 expect(resynthesized.topLevelVariables.length, | 140 expect(resynthesized.topLevelVariables.length, |
| 140 original.topLevelVariables.length); | 141 original.topLevelVariables.length); |
| 141 for (int i = 0; i < resynthesized.topLevelVariables.length; i++) { | 142 for (int i = 0; i < resynthesized.topLevelVariables.length; i++) { |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 'Type mismatch: expected ${original.runtimeType}, got ${resynthesized.
runtimeType}'); | 436 'Type mismatch: expected ${original.runtimeType}, got ${resynthesized.
runtimeType}'); |
| 436 } else { | 437 } else { |
| 437 fail('Unimplemented comparison for ${original.runtimeType}'); | 438 fail('Unimplemented comparison for ${original.runtimeType}'); |
| 438 } | 439 } |
| 439 } | 440 } |
| 440 | 441 |
| 441 void compareUriReferencedElements(UriReferencedElementImpl resynthesized, | 442 void compareUriReferencedElements(UriReferencedElementImpl resynthesized, |
| 442 UriReferencedElementImpl original, String desc) { | 443 UriReferencedElementImpl original, String desc) { |
| 443 compareElements(resynthesized, original, desc); | 444 compareElements(resynthesized, original, desc); |
| 444 expect(resynthesized.uri, original.uri); | 445 expect(resynthesized.uri, original.uri); |
| 446 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); |
| 447 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); |
| 445 } | 448 } |
| 446 | 449 |
| 447 void compareVariableElements(VariableElementImpl resynthesized, | 450 void compareVariableElements(VariableElementImpl resynthesized, |
| 448 VariableElementImpl original, String desc) { | 451 VariableElementImpl original, String desc) { |
| 449 compareElements(resynthesized, original, desc); | 452 compareElements(resynthesized, original, desc); |
| 450 compareTypes(resynthesized.type, original.type, desc); | 453 compareTypes(resynthesized.type, original.type, desc); |
| 451 // TODO(paulberry): test initializer | 454 // TODO(paulberry): test initializer |
| 452 } | 455 } |
| 453 | 456 |
| 454 LibraryElementImpl resynthesizeLibrary( | 457 LibraryElementImpl resynthesizeLibrary( |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 } | 1148 } |
| 1146 | 1149 |
| 1147 test_variable_implicit_type() { | 1150 test_variable_implicit_type() { |
| 1148 checkLibrary('var x;'); | 1151 checkLibrary('var x;'); |
| 1149 } | 1152 } |
| 1150 | 1153 |
| 1151 test_variables() { | 1154 test_variables() { |
| 1152 checkLibrary('int i; int j;'); | 1155 checkLibrary('int i; int j;'); |
| 1153 } | 1156 } |
| 1154 } | 1157 } |
| OLD | NEW |