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

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

Issue 1688233004: Validate that (actual) resynthesized elements have the same runtimeType as originals. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Use actual double.X values. Created 4 years, 10 months 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
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 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // We don't resynthesize property access. 366 // We don't resynthesize property access.
367 // We use simple identifiers with correct elements. 367 // We use simple identifiers with correct elements.
368 compareConstAsts(r, o.propertyName, desc); 368 compareConstAsts(r, o.propertyName, desc);
369 } else if (o is NullLiteral) { 369 } else if (o is NullLiteral) {
370 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); 370 expect(r, new isInstanceOf<NullLiteral>(), reason: desc);
371 } else if (o is BooleanLiteral && r is BooleanLiteral) { 371 } else if (o is BooleanLiteral && r is BooleanLiteral) {
372 expect(r.value, o.value, reason: desc); 372 expect(r.value, o.value, reason: desc);
373 } else if (o is IntegerLiteral && r is IntegerLiteral) { 373 } else if (o is IntegerLiteral && r is IntegerLiteral) {
374 expect(r.value, o.value, reason: desc); 374 expect(r.value, o.value, reason: desc);
375 } else if (o is DoubleLiteral && r is DoubleLiteral) { 375 } else if (o is DoubleLiteral && r is DoubleLiteral) {
376 expect(r.value, o.value, reason: desc); 376 if (r.value != null &&
377 r.value.isNaN &&
378 o.value != null &&
379 o.value.isNaN) {
380 // NaN is not comparable.
381 } else {
382 expect(r.value, o.value, reason: desc);
383 }
377 } else if (o is StringInterpolation && r is StringInterpolation) { 384 } else if (o is StringInterpolation && r is StringInterpolation) {
378 compareConstAstLists(r.elements, o.elements, desc); 385 compareConstAstLists(r.elements, o.elements, desc);
379 } else if (o is StringLiteral && r is StringLiteral) { 386 } else if (o is StringLiteral && r is StringLiteral) {
380 // We don't keep all the tokens of AdjacentStrings. 387 // We don't keep all the tokens of AdjacentStrings.
381 // So, we can compare only their values. 388 // So, we can compare only their values.
382 expect(r.stringValue, o.stringValue, reason: desc); 389 expect(r.stringValue, o.stringValue, reason: desc);
383 } else if (o is SymbolLiteral && r is SymbolLiteral) { 390 } else if (o is SymbolLiteral && r is SymbolLiteral) {
384 // We don't keep all the tokens of symbol literals. 391 // We don't keep all the tokens of symbol literals.
385 // So, we can compare only their values. 392 // So, we can compare only their values.
386 expect(r.components.map((t) => t.lexeme).join('.'), 393 expect(r.components.map((t) => t.lexeme).join('.'),
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 reason: desc); 502 reason: desc);
496 expect(resynthesized.compilationUnit, isNotNull, reason: desc); 503 expect(resynthesized.compilationUnit, isNotNull, reason: desc);
497 expect(resynthesized.compilationUnit.location, 504 expect(resynthesized.compilationUnit.location,
498 original.compilationUnit.location, 505 original.compilationUnit.location,
499 reason: desc); 506 reason: desc);
500 expect(resynthesized.annotationAst, isNotNull, reason: desc); 507 expect(resynthesized.annotationAst, isNotNull, reason: desc);
501 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc); 508 compareConstAsts(resynthesized.annotationAst, original.annotationAst, desc);
502 } 509 }
503 510
504 void compareElements(Element resynthesized, Element original, String desc) { 511 void compareElements(Element resynthesized, Element original, String desc) {
512 ElementImpl rImpl = getActualElement(resynthesized, desc);
513 ElementImpl oImpl = getActualElement(original, desc);
514 expect(rImpl.runtimeType, oImpl.runtimeType);
505 expect(resynthesized, isNotNull); 515 expect(resynthesized, isNotNull);
506 expect(resynthesized.kind, original.kind); 516 expect(resynthesized.kind, original.kind);
507 expect(resynthesized.location, original.location, reason: desc); 517 expect(resynthesized.location, original.location, reason: desc);
508 expect(resynthesized.name, original.name); 518 expect(resynthesized.name, original.name);
509 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); 519 expect(resynthesized.nameOffset, original.nameOffset, reason: desc);
510 expect(resynthesized.documentationComment, original.documentationComment, 520 expect(resynthesized.documentationComment, original.documentationComment,
511 reason: desc); 521 reason: desc);
512 expect(resynthesized.docRange, original.docRange, reason: desc); 522 expect(resynthesized.docRange, original.docRange, reason: desc);
513 compareMetadata(resynthesized.metadata, original.metadata, desc); 523 compareMetadata(resynthesized.metadata, original.metadata, desc);
514 // Modifiers are a pain to test via handles. So just test them via the 524 // Modifiers are a pain to test via handles. So just test them via the
515 // actual element. 525 // actual element.
516 ElementImpl actualResynthesized = getActualElement(resynthesized, desc);
517 ElementImpl actualOriginal = getActualElement(original, desc);
518 for (Modifier modifier in Modifier.values) { 526 for (Modifier modifier in Modifier.values) {
519 bool got = actualResynthesized.hasModifier(modifier); 527 bool got = rImpl.hasModifier(modifier);
520 bool want = actualOriginal.hasModifier(modifier); 528 bool want = oImpl.hasModifier(modifier);
521 expect(got, want, 529 expect(got, want,
522 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); 530 reason: 'Mismatch in $desc.$modifier: got $got, want $want');
523 } 531 }
524 // Validate members. 532 // Validate members.
525 if (actualOriginal is Member) { 533 if (oImpl is Member) {
526 expect(actualResynthesized, new isInstanceOf<Member>(), reason: desc); 534 expect(rImpl, new isInstanceOf<Member>(), reason: desc);
527 } else { 535 } else {
528 expect(actualResynthesized, isNot(new isInstanceOf<Member>()), 536 expect(rImpl, isNot(new isInstanceOf<Member>()), reason: desc);
529 reason: desc);
530 } 537 }
531 } 538 }
532 539
533 void compareExecutableElements(ExecutableElement resynthesized, 540 void compareExecutableElements(ExecutableElement resynthesized,
534 ExecutableElement original, String desc) { 541 ExecutableElement original, String desc) {
535 compareElements(resynthesized, original, desc); 542 compareElements(resynthesized, original, desc);
536 expect(resynthesized.parameters.length, original.parameters.length); 543 expect(resynthesized.parameters.length, original.parameters.length);
537 for (int i = 0; i < resynthesized.parameters.length; i++) { 544 for (int i = 0; i < resynthesized.parameters.length; i++) {
538 compareParameterElements( 545 compareParameterElements(
539 resynthesized.parameters[i], 546 resynthesized.parameters[i],
(...skipping 2870 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 fail('Unexpectedly tried to get unlinked summary for $uri'); 3417 fail('Unexpectedly tried to get unlinked summary for $uri');
3411 } 3418 }
3412 return serializedUnit; 3419 return serializedUnit;
3413 } 3420 }
3414 3421
3415 @override 3422 @override
3416 bool hasLibrarySummary(String uri) { 3423 bool hasLibrarySummary(String uri) {
3417 return true; 3424 return true;
3418 } 3425 }
3419 } 3426 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_ast.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698