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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1532763002: Fixes to mock SDK to enable dart:core to be summarized. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove a bogus comment Created 5 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
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/builder.dart'; 9 import 'package:analyzer/src/summary/builder.dart';
10 import 'package:analyzer/src/summary/format.dart'; 10 import 'package:analyzer/src/summary/format.dart';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
69 void compareClassElements( 69 void compareClassElements(
70 ClassElementImpl resynthesized, ClassElementImpl original, String desc) { 70 ClassElementImpl resynthesized, ClassElementImpl original, String desc) {
71 compareElements(resynthesized, original, desc); 71 compareElements(resynthesized, original, desc);
72 expect(resynthesized.fields.length, original.fields.length); 72 expect(resynthesized.fields.length, original.fields.length,
73 reason: '$desc fields.length');
73 for (int i = 0; i < resynthesized.fields.length; i++) { 74 for (int i = 0; i < resynthesized.fields.length; i++) {
74 String name = original.fields[i].name; 75 String name = original.fields[i].name;
75 compareFieldElements( 76 compareFieldElements(resynthesized.getField(name), original.fields[i],
76 resynthesized.getField(name), original.fields[i], '$desc.$name'); 77 '$desc.field $name');
77 } 78 }
78 compareTypes( 79 compareTypes(
79 resynthesized.supertype, original.supertype, '$desc supertype'); 80 resynthesized.supertype, original.supertype, '$desc supertype');
80 expect(resynthesized.interfaces.length, original.interfaces.length); 81 expect(resynthesized.interfaces.length, original.interfaces.length);
81 for (int i = 0; i < resynthesized.interfaces.length; i++) { 82 for (int i = 0; i < resynthesized.interfaces.length; i++) {
82 compareTypes(resynthesized.interfaces[i], original.interfaces[i], 83 compareTypes(resynthesized.interfaces[i], original.interfaces[i],
83 '$desc interface ${original.interfaces[i].name}'); 84 '$desc interface ${original.interfaces[i].name}');
84 } 85 }
85 expect(resynthesized.mixins.length, original.mixins.length); 86 expect(resynthesized.mixins.length, original.mixins.length);
86 for (int i = 0; i < resynthesized.mixins.length; i++) { 87 for (int i = 0; i < resynthesized.mixins.length; i++) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void compareConstructorElements(ConstructorElementImpl resynthesized, 167 void compareConstructorElements(ConstructorElementImpl resynthesized,
167 ConstructorElementImpl original, String desc) { 168 ConstructorElementImpl original, String desc) {
168 compareExecutableElements(resynthesized, original, desc); 169 compareExecutableElements(resynthesized, original, desc);
169 // TODO(paulberry): test redirectedConstructor and constantInitializers 170 // TODO(paulberry): test redirectedConstructor and constantInitializers
170 } 171 }
171 172
172 void compareElements( 173 void compareElements(
173 ElementImpl resynthesized, ElementImpl original, String desc) { 174 ElementImpl resynthesized, ElementImpl original, String desc) {
174 expect(resynthesized, isNotNull); 175 expect(resynthesized, isNotNull);
175 expect(resynthesized.kind, original.kind); 176 expect(resynthesized.kind, original.kind);
176 expect(resynthesized.location, original.location); 177 expect(resynthesized.location, original.location, reason: desc);
177 expect(resynthesized.name, original.name); 178 expect(resynthesized.name, original.name);
178 for (Modifier modifier in Modifier.values) { 179 for (Modifier modifier in Modifier.values) {
179 if (modifier == Modifier.MIXIN) { 180 if (modifier == Modifier.MIXIN) {
180 // Skipping for now. TODO(paulberry): fix. 181 // Skipping for now. TODO(paulberry): fix.
181 continue; 182 continue;
182 } 183 }
183 bool got = resynthesized.hasModifier(modifier); 184 bool got = resynthesized.hasModifier(modifier);
184 bool want = original.hasModifier(modifier); 185 bool want = original.hasModifier(modifier);
185 expect(got, want, 186 expect(got, want,
186 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); 187 reason: 'Mismatch in $desc.$modifier: got $got, want $want');
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 356
356 void compareTypeParameterElements(TypeParameterElementImpl resynthesized, 357 void compareTypeParameterElements(TypeParameterElementImpl resynthesized,
357 TypeParameterElementImpl original, String desc) { 358 TypeParameterElementImpl original, String desc) {
358 compareElements(resynthesized, original, desc); 359 compareElements(resynthesized, original, desc);
359 compareTypes(resynthesized.type, original.type, desc); 360 compareTypes(resynthesized.type, original.type, desc);
360 compareTypes(resynthesized.bound, original.bound, '$desc bound'); 361 compareTypes(resynthesized.bound, original.bound, '$desc bound');
361 } 362 }
362 363
363 void compareTypes(DartType resynthesized, DartType original, String desc) { 364 void compareTypes(DartType resynthesized, DartType original, String desc) {
364 if (original == null) { 365 if (original == null) {
365 expect(resynthesized, isNull); 366 expect(resynthesized, isNull, reason: desc);
366 } else if (resynthesized is InterfaceTypeImpl && 367 } else if (resynthesized is InterfaceTypeImpl &&
367 original is InterfaceTypeImpl) { 368 original is InterfaceTypeImpl) {
368 compareTypeImpls(resynthesized, original); 369 compareTypeImpls(resynthesized, original);
369 expect(resynthesized.typeArguments.length, original.typeArguments.length); 370 expect(resynthesized.typeArguments.length, original.typeArguments.length);
370 for (int i = 0; i < resynthesized.typeArguments.length; i++) { 371 for (int i = 0; i < resynthesized.typeArguments.length; i++) {
371 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i], 372 compareTypes(resynthesized.typeArguments[i], original.typeArguments[i],
372 '$desc type argument ${original.typeArguments[i].name}'); 373 '$desc type argument ${original.typeArguments[i].name}');
373 } 374 }
374 } else if (resynthesized is TypeParameterTypeImpl && 375 } else if (resynthesized is TypeParameterTypeImpl &&
375 original is TypeParameterTypeImpl) { 376 original is TypeParameterTypeImpl) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 expect(resynthesized.uri, original.uri); 410 expect(resynthesized.uri, original.uri);
410 } 411 }
411 412
412 void compareVariableElements(VariableElementImpl resynthesized, 413 void compareVariableElements(VariableElementImpl resynthesized,
413 VariableElementImpl original, String desc) { 414 VariableElementImpl original, String desc) {
414 compareElements(resynthesized, original, desc); 415 compareElements(resynthesized, original, desc);
415 compareTypes(resynthesized.type, original.type, desc); 416 compareTypes(resynthesized.type, original.type, desc);
416 // TODO(paulberry): test initializer 417 // TODO(paulberry): test initializer
417 } 418 }
418 419
419 fail_core() {
420 // TODO(paulberry): figure out why this test is failing. It's possible
421 // some of the elements in the core library fail to resynthesize properly
422 // because of flaws in the mock SDK; it's also possible that there are bugs
423 // in the summary logic which are not caught by other tests.
424 String uri = 'dart:core';
425 LibraryElementImpl original =
426 resolve2(analysisContext2.sourceFactory.forUri(uri));
427 LibraryElementImpl resynthesized =
428 resynthesizeLibraryElement(uri, original);
429 checkLibraryElements(original, resynthesized);
430 }
431
432 PrelinkedLibrary getSummaryFor(LibraryElement lib) { 420 PrelinkedLibrary getSummaryFor(LibraryElement lib) {
433 BuilderContext ctx = new BuilderContext(); 421 BuilderContext ctx = new BuilderContext();
434 List<int> summary = serializeLibrary(ctx, lib, typeProvider).toBuffer(); 422 List<int> summary = serializeLibrary(ctx, lib, typeProvider).toBuffer();
435 return new PrelinkedLibrary.fromBuffer(summary); 423 return new PrelinkedLibrary.fromBuffer(summary);
436 } 424 }
437 425
438 LibraryElementImpl resynthesizeLibrary( 426 LibraryElementImpl resynthesizeLibrary(
439 Source source, LibraryElementImpl original, bool allowErrors) { 427 Source source, LibraryElementImpl original, bool allowErrors) {
440 if (!allowErrors) { 428 if (!allowErrors) {
441 assertNoErrors(source); 429 assertNoErrors(source);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 } 638 }
651 639
652 test_class_type_parameters_f_bound_simple() { 640 test_class_type_parameters_f_bound_simple() {
653 checkLibrary('class C<T extends U, U> {}'); 641 checkLibrary('class C<T extends U, U> {}');
654 } 642 }
655 643
656 test_classes() { 644 test_classes() {
657 checkLibrary('class C {} class D {}'); 645 checkLibrary('class C {} class D {}');
658 } 646 }
659 647
648 test_core() {
649 String uri = 'dart:core';
650 LibraryElementImpl original =
651 resolve2(analysisContext2.sourceFactory.forUri(uri));
652 LibraryElementImpl resynthesized =
653 resynthesizeLibraryElement(uri, original);
654 checkLibraryElements(original, resynthesized);
655 }
656
660 test_enum_values() { 657 test_enum_values() {
661 checkLibrary('enum E { v1, v2 }'); 658 checkLibrary('enum E { v1, v2 }');
662 } 659 }
663 660
664 test_enums() { 661 test_enums() {
665 checkLibrary('enum E1 { v1 } enum E2 { v2 }'); 662 checkLibrary('enum E1 { v1 } enum E2 { v2 }');
666 } 663 }
667 664
668 test_export_hide() { 665 test_export_hide() {
669 addLibrary('dart:async'); 666 addLibrary('dart:async');
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 } 1017 }
1021 1018
1022 test_variable_const() { 1019 test_variable_const() {
1023 checkLibrary('const int i = 0;'); 1020 checkLibrary('const int i = 0;');
1024 } 1021 }
1025 1022
1026 test_variables() { 1023 test_variables() {
1027 checkLibrary('int i; int j;'); 1024 checkLibrary('int i; int j;');
1028 } 1025 }
1029 } 1026 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698