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

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

Issue 1979343002: Test resynthesized modifiers using accessors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | 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 '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/constant/value.dart'; 10 import 'package:analyzer/dart/constant/value.dart';
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 expect(resynthesized.kind, original.kind); 668 expect(resynthesized.kind, original.kind);
669 expect(resynthesized.location, original.location, reason: desc); 669 expect(resynthesized.location, original.location, reason: desc);
670 expect(resynthesized.name, original.name); 670 expect(resynthesized.name, original.name);
671 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); 671 expect(resynthesized.nameOffset, original.nameOffset, reason: desc);
672 expect(rImpl.codeOffset, oImpl.codeOffset, reason: desc); 672 expect(rImpl.codeOffset, oImpl.codeOffset, reason: desc);
673 expect(rImpl.codeLength, oImpl.codeLength, reason: desc); 673 expect(rImpl.codeLength, oImpl.codeLength, reason: desc);
674 expect(resynthesized.documentationComment, original.documentationComment, 674 expect(resynthesized.documentationComment, original.documentationComment,
675 reason: desc); 675 reason: desc);
676 expect(resynthesized.docRange, original.docRange, reason: desc); 676 expect(resynthesized.docRange, original.docRange, reason: desc);
677 compareMetadata(resynthesized.metadata, original.metadata, desc); 677 compareMetadata(resynthesized.metadata, original.metadata, desc);
678 // Modifiers are a pain to test via handles. So just test them via the 678
679 // actual element. 679 // Validate modifiers.
680 for (Modifier modifier in Modifier.persistedValues) { 680 for (Modifier modifier in Modifier.persistedValues) {
681 bool got = rImpl.hasModifier(modifier); 681 bool got = _hasModifier(resynthesized, modifier);
682 bool want = oImpl.hasModifier(modifier); 682 bool want = _hasModifier(original, modifier);
683 expect(got, want, 683 expect(got, want,
684 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); 684 reason: 'Mismatch in $desc.$modifier: got $got, want $want');
685 } 685 }
686 for (Modifier modifier in Modifier.transientValues) { 686 for (Modifier modifier in Modifier.transientValues) {
687 bool got = rImpl.hasModifier(modifier); 687 bool got = rImpl.hasModifier(modifier);
688 bool want = false; 688 bool want = false;
689 expect(got, false, 689 expect(got, false,
690 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); 690 reason: 'Mismatch in $desc.$modifier: got $got, want $want');
691 } 691 }
692 692
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 void setUp() { 1214 void setUp() {
1215 super.setUp(); 1215 super.setUp();
1216 prepareAnalysisContext(createOptions()); 1216 prepareAnalysisContext(createOptions());
1217 } 1217 }
1218 1218
1219 void _assertUnresolvedIdentifier(Expression initializer, String desc) { 1219 void _assertUnresolvedIdentifier(Expression initializer, String desc) {
1220 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc); 1220 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc);
1221 SimpleIdentifier identifier = initializer; 1221 SimpleIdentifier identifier = initializer;
1222 expect(identifier.staticElement, isNull, reason: desc); 1222 expect(identifier.staticElement, isNull, reason: desc);
1223 } 1223 }
1224
1225 bool _hasModifier(Element element, Modifier modifier) {
1226 if (modifier == Modifier.ABSTRACT) {
1227 if (element is ClassElement) {
1228 return element.isAbstract;
1229 }
1230 if (element is ExecutableElement) {
1231 return element.isAbstract;
1232 }
1233 return false;
1234 } else if (modifier == Modifier.ASYNCHRONOUS) {
1235 if (element is ExecutableElement) {
1236 return element.isAsynchronous;
1237 }
1238 return false;
1239 } else if (modifier == Modifier.CONST) {
1240 if (element is VariableElement) {
1241 return element.isConst;
1242 }
1243 return false;
1244 } else if (modifier == Modifier.DEFERRED) {
1245 if (element is ImportElement) {
1246 return element.isDeferred;
1247 }
1248 return false;
1249 } else if (modifier == Modifier.ENUM) {
1250 if (element is ClassElement) {
1251 return element.isEnum;
1252 }
1253 return false;
1254 } else if (modifier == Modifier.EXTERNAL) {
1255 if (element is ExecutableElement) {
1256 return element.isExternal;
1257 }
1258 return false;
1259 } else if (modifier == Modifier.FACTORY) {
1260 if (element is ConstructorElement) {
1261 return element.isFactory;
1262 }
1263 return false;
1264 } else if (modifier == Modifier.FINAL) {
1265 if (element is VariableElement) {
1266 return element.isFinal;
1267 }
1268 return false;
1269 } else if (modifier == Modifier.GENERATOR) {
1270 if (element is ExecutableElement) {
1271 return element.isGenerator;
1272 }
1273 return false;
1274 } else if (modifier == Modifier.GETTER) {
1275 if (element is PropertyAccessorElement) {
1276 return element.isGetter;
1277 }
1278 return false;
1279 } else if (modifier == Modifier.HAS_EXT_URI) {
1280 if (element is LibraryElement) {
1281 return element.hasExtUri;
1282 }
1283 return false;
1284 } else if (modifier == Modifier.IMPLICIT_TYPE) {
1285 if (element is ExecutableElement) {
1286 return element.hasImplicitReturnType;
1287 }
1288 return false;
1289 } else if (modifier == Modifier.MIXIN_APPLICATION) {
1290 if (element is ClassElement) {
1291 return element.isMixinApplication;
1292 }
1293 return false;
1294 } else if (modifier == Modifier.REFERENCES_SUPER) {
1295 if (element is ClassElement) {
1296 return element.hasReferenceToSuper;
1297 }
1298 return false;
1299 } else if (modifier == Modifier.SETTER) {
1300 if (element is PropertyAccessorElement) {
1301 return element.isSetter;
1302 }
1303 return false;
1304 } else if (modifier == Modifier.STATIC) {
1305 if (element is ExecutableElement) {
1306 return element.isStatic;
1307 }
1308 return false;
1309 } else if (modifier == Modifier.SYNTHETIC) {
1310 return element.isSynthetic;
1311 }
1312 throw new UnimplementedError(
1313 'Modifier $modifier for ${element?.runtimeType}');
1314 }
1224 } 1315 }
1225 1316
1226 @reflectiveTest 1317 @reflectiveTest
1227 class ResynthesizeElementTest extends ResynthesizeTest { 1318 class ResynthesizeElementTest extends ResynthesizeTest {
1228 @override 1319 @override
1229 LibraryElementImpl checkLibrary(String text, 1320 LibraryElementImpl checkLibrary(String text,
1230 {bool allowErrors: false, bool dumpSummaries: false}) { 1321 {bool allowErrors: false, bool dumpSummaries: false}) {
1231 Source source = addTestSource(text); 1322 Source source = addTestSource(text);
1232 LibraryElementImpl original = context.computeLibraryElement(source); 1323 LibraryElementImpl original = context.computeLibraryElement(source);
1233 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 1324 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
(...skipping 3197 matching lines...) Expand 10 before | Expand all | Expand 10 after
4431 fail('Unexpectedly tried to get unlinked summary for $uri'); 4522 fail('Unexpectedly tried to get unlinked summary for $uri');
4432 } 4523 }
4433 return serializedUnit; 4524 return serializedUnit;
4434 } 4525 }
4435 4526
4436 @override 4527 @override
4437 bool hasLibrarySummary(String uri) { 4528 bool hasLibrarySummary(String uri) {
4438 return true; 4529 return true;
4439 } 4530 }
4440 } 4531 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698