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

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

Issue 1602203004: Serialize constant initializers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 analyzer.test.src.summary.summary_test; 5 library analyzer.test.src.summary.summary_test;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Scanner scanner = 75 Scanner scanner =
76 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER); 76 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER);
77 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); 77 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
78 parser.parseGenericMethods = true; 78 parser.parseGenericMethods = true;
79 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); 79 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize());
80 UnlinkedPublicNamespace namespace = new UnlinkedPublicNamespace.fromBuffer( 80 UnlinkedPublicNamespace namespace = new UnlinkedPublicNamespace.fromBuffer(
81 public_namespace.computePublicNamespace(unit).toBuffer()); 81 public_namespace.computePublicNamespace(unit).toBuffer());
82 return namespace; 82 return namespace;
83 } 83 }
84 84
85 typedef bool _UnlinkedTypeRefPredicate(UnlinkedTypeRef unlinkedTypeRef);
86
85 /** 87 /**
86 * Override of [SummaryTest] which verifies the correctness of the prelinker by 88 * Override of [SummaryTest] which verifies the correctness of the prelinker by
87 * creating summaries from the element model, discarding their prelinked 89 * creating summaries from the element model, discarding their prelinked
88 * information, and then recreating it using the prelinker. 90 * information, and then recreating it using the prelinker.
89 */ 91 */
90 @reflectiveTest 92 @reflectiveTest
91 class PrelinkerTest extends SummarizeElementsTest { 93 class PrelinkerTest extends SummarizeElementsTest {
92 /** 94 /**
93 * The public namespaces of the sdk are computed once so that we don't bog 95 * The public namespaces of the sdk are computed once so that we don't bog
94 * down the test. Structured as a map from absolute URI to the corresponding 96 * down the test. Structured as a map from absolute URI to the corresponding
(...skipping 10 matching lines...) Expand all
105 <String, UnlinkedPublicNamespace>{}; 107 <String, UnlinkedPublicNamespace>{};
106 List<LibraryElement> libraries = [ 108 List<LibraryElement> libraries = [
107 analysisContext.typeProvider.objectType.element.library, 109 analysisContext.typeProvider.objectType.element.library,
108 analysisContext.typeProvider.futureType.element.library 110 analysisContext.typeProvider.futureType.element.library
109 ]; 111 ];
110 for (LibraryElement library in libraries) { 112 for (LibraryElement library in libraries) {
111 summarize_elements.LibrarySerializationResult serializedLibrary = 113 summarize_elements.LibrarySerializationResult serializedLibrary =
112 summarize_elements.serializeLibrary( 114 summarize_elements.serializeLibrary(
113 library, analysisContext.typeProvider); 115 library, analysisContext.typeProvider);
114 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { 116 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) {
115 uriToNamespace[ 117 uriToNamespace[serializedLibrary.unitUris[i]] =
116 serializedLibrary.unitUris[i]] = new UnlinkedUnit.fromBuffer( 118 new UnlinkedUnit.fromBuffer(
117 serializedLibrary.unlinkedUnits[i].toBuffer()).publicNamespace; 119 serializedLibrary.unlinkedUnits[i].toBuffer())
120 .publicNamespace;
118 } 121 }
119 } 122 }
120 return uriToNamespace; 123 return uriToNamespace;
121 } catch (_) { 124 } catch (_) {
122 return null; 125 return null;
123 } 126 }
124 }(); 127 }();
125 128
126 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = 129 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace =
127 <String, UnlinkedPublicNamespace>{}; 130 <String, UnlinkedPublicNamespace>{};
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 815
813 /** 816 /**
814 * Serialize a type declaration using the given [text] as a type name, and 817 * Serialize a type declaration using the given [text] as a type name, and
815 * return a summary of the corresponding [UnlinkedTypeRef]. If the type 818 * return a summary of the corresponding [UnlinkedTypeRef]. If the type
816 * declaration needs to refer to types that are not available in core, those 819 * declaration needs to refer to types that are not available in core, those
817 * types may be declared in [otherDeclarations]. 820 * types may be declared in [otherDeclarations].
818 */ 821 */
819 UnlinkedTypeRef serializeTypeText(String text, 822 UnlinkedTypeRef serializeTypeText(String text,
820 {String otherDeclarations: '', bool allowErrors: false}) { 823 {String otherDeclarations: '', bool allowErrors: false}) {
821 return serializeVariableText('$otherDeclarations\n$text v;', 824 return serializeVariableText('$otherDeclarations\n$text v;',
822 allowErrors: allowErrors).type; 825 allowErrors: allowErrors)
826 .type;
823 } 827 }
824 828
825 /** 829 /**
826 * Serialize the given library [text] and return the summary of the variable 830 * Serialize the given library [text] and return the summary of the variable
827 * with the given [variableName]. 831 * with the given [variableName].
828 */ 832 */
829 UnlinkedVariable serializeVariableText(String text, 833 UnlinkedVariable serializeVariableText(String text,
830 {String variableName: 'v', bool allowErrors: false}) { 834 {String variableName: 'v', bool allowErrors: false}) {
831 serializeLibraryText(text, allowErrors: allowErrors); 835 serializeLibraryText(text, allowErrors: allowErrors);
832 return findVariable(variableName, failIfAbsent: true); 836 return findVariable(variableName, failIfAbsent: true);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 test_class_type_param_no_bound() { 1236 test_class_type_param_no_bound() {
1233 String text = 'class C<T> {}'; 1237 String text = 'class C<T> {}';
1234 UnlinkedClass cls = serializeClassText(text); 1238 UnlinkedClass cls = serializeClassText(text);
1235 expect(cls.typeParameters, hasLength(1)); 1239 expect(cls.typeParameters, hasLength(1));
1236 expect(cls.typeParameters[0].name, 'T'); 1240 expect(cls.typeParameters[0].name, 'T');
1237 expect(cls.typeParameters[0].nameOffset, text.indexOf('T')); 1241 expect(cls.typeParameters[0].nameOffset, text.indexOf('T'));
1238 expect(cls.typeParameters[0].bound, isNull); 1242 expect(cls.typeParameters[0].bound, isNull);
1239 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); 1243 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1);
1240 } 1244 }
1241 1245
1246 test_constExpr_binary_add() {
1247 UnlinkedVariable variable = serializeVariableText('const v = 1 + 2;');
1248 _assertUnlinkedConst(variable.constExpr, operators: [
1249 UnlinkedConstOperation.pushInt,
1250 UnlinkedConstOperation.pushInt,
1251 UnlinkedConstOperation.add
1252 ], ints: [
1253 1,
1254 2
1255 ]);
1256 }
1257
1258 test_constExpr_binary_and() {
1259 UnlinkedVariable variable =
1260 serializeVariableText('const v = true && false;');
1261 _assertUnlinkedConst(variable.constExpr, operators: [
1262 UnlinkedConstOperation.pushTrue,
1263 UnlinkedConstOperation.pushFalse,
1264 UnlinkedConstOperation.and
1265 ]);
1266 }
1267
1268 test_constExpr_binary_bitAnd() {
1269 UnlinkedVariable variable = serializeVariableText('const v = 1 & 2;');
1270 _assertUnlinkedConst(variable.constExpr, operators: [
1271 UnlinkedConstOperation.pushInt,
1272 UnlinkedConstOperation.pushInt,
1273 UnlinkedConstOperation.bitAnd
1274 ], ints: [
1275 1,
1276 2
1277 ]);
1278 }
1279
1280 test_constExpr_binary_bitOr() {
1281 UnlinkedVariable variable = serializeVariableText('const v = 1 | 2;');
1282 _assertUnlinkedConst(variable.constExpr, operators: [
1283 UnlinkedConstOperation.pushInt,
1284 UnlinkedConstOperation.pushInt,
1285 UnlinkedConstOperation.bitOr
1286 ], ints: [
1287 1,
1288 2
1289 ]);
1290 }
1291
1292 test_constExpr_binary_bitShiftLeft() {
1293 UnlinkedVariable variable = serializeVariableText('const v = 1 << 2;');
1294 _assertUnlinkedConst(variable.constExpr, operators: [
1295 UnlinkedConstOperation.pushInt,
1296 UnlinkedConstOperation.pushInt,
1297 UnlinkedConstOperation.bitShiftLeft
1298 ], ints: [
1299 1,
1300 2
1301 ]);
1302 }
1303
1304 test_constExpr_binary_bitShiftRight() {
1305 UnlinkedVariable variable = serializeVariableText('const v = 1 >> 2;');
1306 _assertUnlinkedConst(variable.constExpr, operators: [
1307 UnlinkedConstOperation.pushInt,
1308 UnlinkedConstOperation.pushInt,
1309 UnlinkedConstOperation.bitShiftRight
1310 ], ints: [
1311 1,
1312 2
1313 ]);
1314 }
1315
1316 test_constExpr_binary_bitXor() {
1317 UnlinkedVariable variable = serializeVariableText('const v = 1 ^ 2;');
1318 _assertUnlinkedConst(variable.constExpr, operators: [
1319 UnlinkedConstOperation.pushInt,
1320 UnlinkedConstOperation.pushInt,
1321 UnlinkedConstOperation.bitXor
1322 ], ints: [
1323 1,
1324 2
1325 ]);
1326 }
1327
1328 test_constExpr_binary_divide() {
1329 UnlinkedVariable variable = serializeVariableText('const v = 1 / 2;');
1330 _assertUnlinkedConst(variable.constExpr, operators: [
1331 UnlinkedConstOperation.pushInt,
1332 UnlinkedConstOperation.pushInt,
1333 UnlinkedConstOperation.divide
1334 ], ints: [
1335 1,
1336 2
1337 ]);
1338 }
1339
1340 test_constExpr_binary_equal() {
1341 UnlinkedVariable variable = serializeVariableText('const v = 1 == 2;');
1342 _assertUnlinkedConst(variable.constExpr, operators: [
1343 UnlinkedConstOperation.pushInt,
1344 UnlinkedConstOperation.pushInt,
1345 UnlinkedConstOperation.equal
1346 ], ints: [
1347 1,
1348 2
1349 ]);
1350 }
1351
1352 test_constExpr_binary_equal_not() {
1353 UnlinkedVariable variable = serializeVariableText('const v = 1 != 2;');
1354 _assertUnlinkedConst(variable.constExpr, operators: [
1355 UnlinkedConstOperation.pushInt,
1356 UnlinkedConstOperation.pushInt,
1357 UnlinkedConstOperation.equal,
1358 UnlinkedConstOperation.not
1359 ], ints: [
1360 1,
1361 2
1362 ]);
1363 }
1364
1365 test_constExpr_binary_floorDivide() {
1366 UnlinkedVariable variable = serializeVariableText('const v = 1 ~/ 2;');
1367 _assertUnlinkedConst(variable.constExpr, operators: [
1368 UnlinkedConstOperation.pushInt,
1369 UnlinkedConstOperation.pushInt,
1370 UnlinkedConstOperation.floorDivide
1371 ], ints: [
1372 1,
1373 2
1374 ]);
1375 }
1376
1377 test_constExpr_binary_greater() {
1378 UnlinkedVariable variable = serializeVariableText('const v = 1 > 2;');
1379 _assertUnlinkedConst(variable.constExpr, operators: [
1380 UnlinkedConstOperation.pushInt,
1381 UnlinkedConstOperation.pushInt,
1382 UnlinkedConstOperation.greater
1383 ], ints: [
1384 1,
1385 2
1386 ]);
1387 }
1388
1389 test_constExpr_binary_greaterEqual() {
1390 UnlinkedVariable variable = serializeVariableText('const v = 1 >= 2;');
1391 _assertUnlinkedConst(variable.constExpr, operators: [
1392 UnlinkedConstOperation.pushInt,
1393 UnlinkedConstOperation.pushInt,
1394 UnlinkedConstOperation.greaterEqual
1395 ], ints: [
1396 1,
1397 2
1398 ]);
1399 }
1400
1401 test_constExpr_binary_less() {
1402 UnlinkedVariable variable = serializeVariableText('const v = 1 < 2;');
1403 _assertUnlinkedConst(variable.constExpr, operators: [
1404 UnlinkedConstOperation.pushInt,
1405 UnlinkedConstOperation.pushInt,
1406 UnlinkedConstOperation.less
1407 ], ints: [
1408 1,
1409 2
1410 ]);
1411 }
1412
1413 test_constExpr_binary_lessEqual() {
1414 UnlinkedVariable variable = serializeVariableText('const v = 1 <= 2;');
1415 _assertUnlinkedConst(variable.constExpr, operators: [
1416 UnlinkedConstOperation.pushInt,
1417 UnlinkedConstOperation.pushInt,
1418 UnlinkedConstOperation.lessEqual
1419 ], ints: [
1420 1,
1421 2
1422 ]);
1423 }
1424
1425 test_constExpr_binary_modulo() {
1426 UnlinkedVariable variable = serializeVariableText('const v = 1 % 2;');
1427 _assertUnlinkedConst(variable.constExpr, operators: [
1428 UnlinkedConstOperation.pushInt,
1429 UnlinkedConstOperation.pushInt,
1430 UnlinkedConstOperation.modulo
1431 ], ints: [
1432 1,
1433 2
1434 ]);
1435 }
1436
1437 test_constExpr_binary_multiply() {
1438 UnlinkedVariable variable = serializeVariableText('const v = 1 * 2;');
1439 _assertUnlinkedConst(variable.constExpr, operators: [
1440 UnlinkedConstOperation.pushInt,
1441 UnlinkedConstOperation.pushInt,
1442 UnlinkedConstOperation.multiply
1443 ], ints: [
1444 1,
1445 2
1446 ]);
1447 }
1448
1449 test_constExpr_binary_or() {
1450 UnlinkedVariable variable =
1451 serializeVariableText('const v = false || true;');
1452 _assertUnlinkedConst(variable.constExpr, operators: [
1453 UnlinkedConstOperation.pushFalse,
1454 UnlinkedConstOperation.pushTrue,
1455 UnlinkedConstOperation.or
1456 ]);
1457 }
1458
1459 test_constExpr_binary_subtract() {
1460 UnlinkedVariable variable = serializeVariableText('const v = 1 - 2;');
1461 _assertUnlinkedConst(variable.constExpr, operators: [
1462 UnlinkedConstOperation.pushInt,
1463 UnlinkedConstOperation.pushInt,
1464 UnlinkedConstOperation.subtract
1465 ], ints: [
1466 1,
1467 2
1468 ]);
1469 }
1470
1471 test_constExpr_conditional() {
1472 UnlinkedVariable variable =
1473 serializeVariableText('const v = true ? 1 : 2;', allowErrors: true);
1474 _assertUnlinkedConst(variable.constExpr, operators: [
1475 UnlinkedConstOperation.pushTrue,
1476 UnlinkedConstOperation.pushInt,
1477 UnlinkedConstOperation.pushInt,
1478 UnlinkedConstOperation.conditional
1479 ], ints: [
1480 1,
1481 2
1482 ]);
1483 }
1484
1485 test_constExpr_identical() {
1486 UnlinkedVariable variable =
1487 serializeVariableText('const v = identical(42, null);');
1488 _assertUnlinkedConst(variable.constExpr, operators: [
1489 UnlinkedConstOperation.pushInt,
1490 UnlinkedConstOperation.pushNull,
1491 UnlinkedConstOperation.identical
1492 ], ints: [
1493 42
1494 ]);
1495 }
1496
1497 test_constExpr_invokeConstructor_named() {
1498 UnlinkedVariable variable = serializeVariableText('''
1499 class C {
1500 const C.named();
1501 }
1502 const v = const C.named();
1503 ''');
1504 _assertUnlinkedConst(variable.constExpr, operators: [
1505 UnlinkedConstOperation.invokeConstructor,
1506 ], ints: [
1507 0
1508 ], strings: [
1509 'named'
1510 ], references: [
1511 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1512 expectedKind: ReferenceKind.classOrEnum)
1513 ]);
1514 }
1515
1516 test_constExpr_invokeConstructor_named_imported() {
1517 addNamedSource(
1518 '/a.dart',
1519 '''
1520 class C {
1521 const C.named();
1522 }
1523 ''');
1524 UnlinkedVariable variable = serializeVariableText('''
1525 import 'a.dart';
1526 const v = const C.named();
1527 ''');
1528 _assertUnlinkedConst(variable.constExpr, operators: [
1529 UnlinkedConstOperation.invokeConstructor,
1530 ], ints: [
1531 0
1532 ], strings: [
1533 'named'
1534 ], references: [
1535 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1536 expectedKind: ReferenceKind.classOrEnum)
1537 ]);
1538 }
1539
1540 test_constExpr_invokeConstructor_named_imported_withPrefix() {
1541 addNamedSource(
1542 '/a.dart',
1543 '''
1544 class C {
1545 const C.named();
1546 }
1547 ''');
1548 UnlinkedVariable variable = serializeVariableText('''
1549 import 'a.dart' as p;
1550 const v = const p.C.named();
1551 ''');
1552 _assertUnlinkedConst(variable.constExpr, operators: [
1553 UnlinkedConstOperation.invokeConstructor,
1554 ], ints: [
1555 0
1556 ], strings: [
1557 'named'
1558 ], references: [
1559 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'C',
1560 expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'p')
1561 ]);
1562 }
1563
1564 test_constExpr_invokeConstructor_unnamed() {
1565 UnlinkedVariable variable = serializeVariableText('''
1566 class C {
1567 const C(int a, String b);
1568 }
1569 const v = const C(42, 'sss');
1570 ''');
1571 _assertUnlinkedConst(variable.constExpr, operators: [
1572 UnlinkedConstOperation.pushInt,
1573 UnlinkedConstOperation.pushString,
1574 UnlinkedConstOperation.invokeConstructor,
1575 ], ints: [
1576 42,
1577 2
1578 ], strings: [
1579 'sss',
1580 ''
1581 ], references: [
1582 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1583 expectedKind: ReferenceKind.classOrEnum)
1584 ]);
1585 }
1586
1587 test_constExpr_length() {
1588 UnlinkedVariable variable =
1589 serializeVariableText('const v = "abc".length;');
1590 _assertUnlinkedConst(variable.constExpr, operators: [
1591 UnlinkedConstOperation.pushString,
1592 UnlinkedConstOperation.length
1593 ], strings: [
1594 'abc'
1595 ]);
1596 }
1597
1598 test_constExpr_makeList_typed() {
1599 UnlinkedVariable variable =
1600 serializeVariableText('const v = const <int>[11, 22, 33];');
1601 _assertUnlinkedConst(variable.constExpr, operators: [
1602 UnlinkedConstOperation.pushInt,
1603 UnlinkedConstOperation.pushInt,
1604 UnlinkedConstOperation.pushInt,
1605 UnlinkedConstOperation.makeList
1606 ], ints: [
1607 11,
1608 22,
1609 33,
1610 3
1611 ], references: [
1612 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int',
1613 expectedKind: ReferenceKind.classOrEnum)
1614 ]);
1615 }
1616
1617 test_constExpr_makeList_untyped() {
1618 UnlinkedVariable variable =
1619 serializeVariableText('const v = const [11, 22, 33];');
1620 _assertUnlinkedConst(variable.constExpr, operators: [
1621 UnlinkedConstOperation.pushInt,
1622 UnlinkedConstOperation.pushInt,
1623 UnlinkedConstOperation.pushInt,
1624 UnlinkedConstOperation.makeList
1625 ], ints: [
1626 11,
1627 22,
1628 33,
1629 3
1630 ], references: [
1631 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '',
1632 expectedKind: ReferenceKind.classOrEnum)
1633 ]);
1634 }
1635
1636 test_constExpr_makeMap_typed() {
1637 UnlinkedVariable variable = serializeVariableText(
1638 'const v = const <int, String>{11: "aaa", 22: "bbb", 33: "ccc"};');
1639 _assertUnlinkedConst(variable.constExpr, operators: [
1640 UnlinkedConstOperation.pushInt,
1641 UnlinkedConstOperation.pushString,
1642 UnlinkedConstOperation.pushInt,
1643 UnlinkedConstOperation.pushString,
1644 UnlinkedConstOperation.pushInt,
1645 UnlinkedConstOperation.pushString,
1646 UnlinkedConstOperation.makeMap
1647 ], ints: [
1648 11,
1649 22,
1650 33,
1651 3
1652 ], strings: [
1653 'aaa',
1654 'bbb',
1655 'ccc'
1656 ], references: [
1657 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'int',
1658 expectedKind: ReferenceKind.classOrEnum),
1659 (UnlinkedTypeRef r) => checkTypeRef(r, 'dart:core', 'dart:core', 'String',
1660 expectedKind: ReferenceKind.classOrEnum)
1661 ]);
1662 }
1663
1664 test_constExpr_makeMap_untyped() {
1665 UnlinkedVariable variable = serializeVariableText(
1666 'const v = const {11: "aaa", 22: "bbb", 33: "ccc"};');
1667 _assertUnlinkedConst(variable.constExpr, operators: [
1668 UnlinkedConstOperation.pushInt,
1669 UnlinkedConstOperation.pushString,
1670 UnlinkedConstOperation.pushInt,
1671 UnlinkedConstOperation.pushString,
1672 UnlinkedConstOperation.pushInt,
1673 UnlinkedConstOperation.pushString,
1674 UnlinkedConstOperation.makeMap
1675 ], ints: [
1676 11,
1677 22,
1678 33,
1679 3
1680 ], strings: [
1681 'aaa',
1682 'bbb',
1683 'ccc'
1684 ], references: [
1685 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '',
1686 expectedKind: ReferenceKind.classOrEnum),
1687 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, '',
1688 expectedKind: ReferenceKind.classOrEnum)
1689 ]);
1690 }
1691
1692 test_constExpr_makeSymbol() {
1693 UnlinkedVariable variable = serializeVariableText('const v = #a.bb.ccc;');
1694 _assertUnlinkedConst(variable.constExpr, operators: [
1695 UnlinkedConstOperation.pushString,
1696 UnlinkedConstOperation.pushString,
1697 UnlinkedConstOperation.pushString,
1698 UnlinkedConstOperation.makeSymbol
1699 ], ints: [
1700 3
1701 ], strings: [
1702 'a',
1703 'bb',
1704 'ccc'
1705 ]);
1706 }
1707
1708 test_constExpr_parenthesized() {
1709 UnlinkedVariable variable = serializeVariableText('const v = (1 + 2) * 3;');
1710 _assertUnlinkedConst(variable.constExpr, operators: [
1711 UnlinkedConstOperation.pushInt,
1712 UnlinkedConstOperation.pushInt,
1713 UnlinkedConstOperation.add,
1714 UnlinkedConstOperation.pushInt,
1715 UnlinkedConstOperation.multiply,
1716 ], ints: [
1717 1,
1718 2,
1719 3
1720 ]);
1721 }
1722
1723 test_constExpr_prefix_complement() {
1724 UnlinkedVariable variable = serializeVariableText('const v = ~2;');
1725 _assertUnlinkedConst(variable.constExpr, operators: [
1726 UnlinkedConstOperation.pushInt,
1727 UnlinkedConstOperation.complement
1728 ], ints: [
1729 2
1730 ]);
1731 }
1732
1733 test_constExpr_prefix_not() {
1734 UnlinkedVariable variable = serializeVariableText('const v = !true;');
1735 _assertUnlinkedConst(variable.constExpr, operators: [
1736 UnlinkedConstOperation.pushTrue,
1737 UnlinkedConstOperation.not
1738 ]);
1739 }
1740
1741 test_constExpr_pushDouble() {
1742 UnlinkedVariable variable = serializeVariableText('const v = 123.4567;');
1743 _assertUnlinkedConst(variable.constExpr,
1744 operators: [UnlinkedConstOperation.pushDouble], doubles: [123.4567]);
1745 }
1746
1747 test_constExpr_pushFalse() {
1748 UnlinkedVariable variable = serializeVariableText('const v = false;');
1749 _assertUnlinkedConst(variable.constExpr,
1750 operators: [UnlinkedConstOperation.pushFalse]);
1751 }
1752
1753 test_constExpr_pushInt() {
1754 UnlinkedVariable variable = serializeVariableText('const v = 1;');
1755 _assertUnlinkedConst(variable.constExpr,
1756 operators: [UnlinkedConstOperation.pushInt], ints: [1]);
1757 }
1758
1759 test_constExpr_pushInt_shiftOr() {
1760 UnlinkedVariable variable =
1761 serializeVariableText('const v = 0x111222333444555666;');
1762 // ^^!!!!^^^^!!!!^^^^
1763 _assertUnlinkedConst(variable.constExpr, operators: [
1764 UnlinkedConstOperation.pushInt,
1765 UnlinkedConstOperation.shiftOr,
1766 UnlinkedConstOperation.shiftOr
1767 ], ints: [
1768 0x11,
1769 0x12223334,
1770 0x44555666
1771 ]);
1772 }
1773
1774 test_constExpr_pushNull() {
1775 UnlinkedVariable variable = serializeVariableText('const v = null;');
1776 _assertUnlinkedConst(variable.constExpr,
1777 operators: [UnlinkedConstOperation.pushNull]);
1778 }
1779
1780 test_constExpr_pushReference_class() {
1781 UnlinkedVariable variable = serializeVariableText('''
1782 class C {}
1783 const v = C;
1784 ''');
1785 _assertUnlinkedConst(variable.constExpr, operators: [
1786 UnlinkedConstOperation.pushReference
1787 ], references: [
1788 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1789 expectedKind: ReferenceKind.classOrEnum)
1790 ]);
1791 }
1792
1793 test_constExpr_pushReference_class_field() {
1794 // TODO(scheglov) Not sure for to represent a field reference
Paul Berry 2016/01/19 20:02:10 Yeah, I haven't figured out how to do this either.
1795 // using UnlinkedTypeRef.
1796 // UnlinkedVariable variable = serializeVariableText('''
1797 //class C {
1798 // static const int F = 1;
1799 //}
1800 //const v = C.F;
1801 //''');
1802 // _assertUnlinkedConst(variable.constExpr, operators: [
1803 // UnlinkedConstOperation.pushReference
1804 // ], references: [
1805 // (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'F',
1806 // expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'C')
1807 // ]);
1808 }
1809
1810 test_constExpr_pushReference_enum() {
1811 UnlinkedVariable variable = serializeVariableText('''
1812 enum C {V1, V2, V3}
1813 const v = C;
1814 ''');
1815 _assertUnlinkedConst(variable.constExpr, operators: [
1816 UnlinkedConstOperation.pushReference
1817 ], references: [
1818 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'C',
1819 expectedKind: ReferenceKind.classOrEnum)
1820 ]);
1821 }
1822
1823 test_constExpr_pushReference_topLevelVariable_imported() {
1824 addNamedSource('/a.dart', 'const int a = 1;');
1825 UnlinkedVariable variable = serializeVariableText('''
1826 import 'a.dart';
1827 const v = a;
1828 ''');
1829 _assertUnlinkedConst(variable.constExpr, operators: [
1830 UnlinkedConstOperation.pushReference
1831 ], references: [
1832 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a',
1833 expectedKind: ReferenceKind.topLevelPropertyAccessor)
1834 ]);
1835 }
1836
1837 test_constExpr_pushReference_topLevelVariable_imported_withPrefix() {
1838 addNamedSource('/a.dart', 'const int a = 1;');
1839 UnlinkedVariable variable = serializeVariableText('''
1840 import 'a.dart' as p;
1841 const v = p.a;
1842 ''');
1843 _assertUnlinkedConst(variable.constExpr, operators: [
1844 UnlinkedConstOperation.pushReference
1845 ], references: [
1846 (UnlinkedTypeRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a',
1847 expectedKind: ReferenceKind.topLevelPropertyAccessor,
1848 expectedPrefix: 'p')
1849 ]);
1850 }
1851
1852 test_constExpr_pushReference_topLevelVariable_local() {
1853 // TODO(scheglov) use `a + b`
1854 UnlinkedVariable variable = serializeVariableText('''
1855 const int a = 1;
1856 const v = a;
1857 ''');
1858 _assertUnlinkedConst(variable.constExpr, operators: [
1859 UnlinkedConstOperation.pushReference
1860 ], references: [
1861 (UnlinkedTypeRef r) => checkTypeRef(r, null, null, 'a',
1862 expectedKind: ReferenceKind.topLevelPropertyAccessor)
1863 ]);
1864 }
1865
1866 test_constExpr_pushString_adjacent() {
1867 UnlinkedVariable variable =
1868 serializeVariableText('const v = "aaa" "b" "ccc";');
1869 _assertUnlinkedConst(variable.constExpr,
1870 operators: [UnlinkedConstOperation.pushString], strings: ['aaabccc']);
1871 }
1872
1873 test_constExpr_pushString_interpolation() {
1874 UnlinkedVariable variable =
1875 serializeVariableText(r'const v = "aaa ${42} bbb";');
1876 _assertUnlinkedConst(variable.constExpr, operators: [
1877 UnlinkedConstOperation.pushString,
1878 UnlinkedConstOperation.pushInt,
1879 UnlinkedConstOperation.pushString,
1880 UnlinkedConstOperation.concatenate
1881 ], ints: [
1882 42,
1883 3
1884 ], strings: [
1885 'aaa ',
1886 ' bbb'
1887 ]);
1888 }
1889
1890 test_constExpr_pushString_simple() {
1891 UnlinkedVariable variable = serializeVariableText('const v = "abc";');
1892 _assertUnlinkedConst(variable.constExpr,
1893 operators: [UnlinkedConstOperation.pushString], strings: ['abc']);
1894 }
1895
1896 test_constExpr_pushTrue() {
1897 UnlinkedVariable variable = serializeVariableText('const v = true;');
1898 _assertUnlinkedConst(variable.constExpr,
1899 operators: [UnlinkedConstOperation.pushTrue]);
1900 }
1901
1242 test_constructor() { 1902 test_constructor() {
1243 String text = 'class C { C(); }'; 1903 String text = 'class C { C(); }';
1244 UnlinkedExecutable executable = 1904 UnlinkedExecutable executable =
1245 findExecutable('', executables: serializeClassText(text).executables); 1905 findExecutable('', executables: serializeClassText(text).executables);
1246 expect(executable.kind, UnlinkedExecutableKind.constructor); 1906 expect(executable.kind, UnlinkedExecutableKind.constructor);
1247 expect(executable.hasImplicitReturnType, isFalse); 1907 expect(executable.hasImplicitReturnType, isFalse);
1248 expect(executable.isExternal, isFalse); 1908 expect(executable.isExternal, isFalse);
1249 expect(executable.nameOffset, text.indexOf('C();')); 1909 expect(executable.nameOffset, text.indexOf('C();'));
1250 } 1910 }
1251 1911
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 expect(executable.isConst, false); 2556 expect(executable.isConst, false);
1897 expect(executable.isFactory, false); 2557 expect(executable.isFactory, false);
1898 expect(executable.isStatic, false); 2558 expect(executable.isStatic, false);
1899 expect(executable.parameters, hasLength(1)); 2559 expect(executable.parameters, hasLength(1));
1900 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 2560 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
1901 expect(executable.typeParameters, isEmpty); 2561 expect(executable.typeParameters, isEmpty);
1902 } 2562 }
1903 2563
1904 test_executable_operator_index_set() { 2564 test_executable_operator_index_set() {
1905 UnlinkedExecutable executable = serializeClassText( 2565 UnlinkedExecutable executable = serializeClassText(
1906 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; 2566 'class C { void operator[]=(int i, bool v) => null; }')
2567 .executables[0];
1907 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 2568 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1908 expect(executable.name, '[]='); 2569 expect(executable.name, '[]=');
1909 expect(executable.hasImplicitReturnType, false); 2570 expect(executable.hasImplicitReturnType, false);
1910 expect(executable.isAbstract, false); 2571 expect(executable.isAbstract, false);
1911 expect(executable.isConst, false); 2572 expect(executable.isConst, false);
1912 expect(executable.isFactory, false); 2573 expect(executable.isFactory, false);
1913 expect(executable.isStatic, false); 2574 expect(executable.isStatic, false);
1914 expect(executable.parameters, hasLength(2)); 2575 expect(executable.parameters, hasLength(2));
1915 expect(executable.returnType, isNull); 2576 expect(executable.returnType, isNull);
1916 expect(executable.typeParameters, isEmpty); 2577 expect(executable.typeParameters, isEmpty);
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 expect(variable.isStatic, isFalse); 3024 expect(variable.isStatic, isFalse);
2364 expect(variable.isFinal, isFalse); 3025 expect(variable.isFinal, isFalse);
2365 expect(findExecutable('i', executables: cls.executables), isNull); 3026 expect(findExecutable('i', executables: cls.executables), isNull);
2366 expect(findExecutable('i=', executables: cls.executables), isNull); 3027 expect(findExecutable('i=', executables: cls.executables), isNull);
2367 } 3028 }
2368 3029
2369 test_field_const() { 3030 test_field_const() {
2370 UnlinkedVariable variable = 3031 UnlinkedVariable variable =
2371 serializeClassText('class C { static const int i = 0; }').fields[0]; 3032 serializeClassText('class C { static const int i = 0; }').fields[0];
2372 expect(variable.isConst, isTrue); 3033 expect(variable.isConst, isTrue);
3034 _assertUnlinkedConst(variable.constExpr,
3035 operators: [UnlinkedConstOperation.pushInt], ints: [0]);
2373 } 3036 }
2374 3037
2375 test_field_documented() { 3038 test_field_documented() {
2376 String text = ''' 3039 String text = '''
2377 class C { 3040 class C {
2378 /** 3041 /**
2379 * Docs 3042 * Docs
2380 */ 3043 */
2381 var v; 3044 var v;
2382 }'''; 3045 }''';
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
3157 test_variable_type() { 3820 test_variable_type() {
3158 UnlinkedVariable variable = 3821 UnlinkedVariable variable =
3159 serializeVariableText('int i;', variableName: 'i'); 3822 serializeVariableText('int i;', variableName: 'i');
3160 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 3823 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
3161 } 3824 }
3162 3825
3163 test_varible_private() { 3826 test_varible_private() {
3164 serializeVariableText('int _i;', variableName: '_i'); 3827 serializeVariableText('int _i;', variableName: '_i');
3165 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 3828 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
3166 } 3829 }
3830
3831 void _assertUnlinkedConst(UnlinkedConst constExpr,
3832 {List<UnlinkedConstOperation> operators,
3833 List<int> ints: const <int>[],
3834 List<double> doubles: const <double>[],
3835 List<String> strings: const <String>[],
3836 List<_UnlinkedTypeRefPredicate> references:
3837 const <_UnlinkedTypeRefPredicate>[]}) {
3838 expect(constExpr.operations, operators);
3839 expect(constExpr.ints, ints);
3840 expect(constExpr.doubles, doubles);
3841 expect(constExpr.strings, strings);
3842 expect(constExpr.references, hasLength(references.length));
3843 for (int i = 0; i < references.length; i++) {
3844 references[i](constExpr.references[i]);
Paul Berry 2016/01/19 20:02:10 I think you might mean: expect(references[i](cons
scheglov 2016/01/19 20:59:28 Nesting `expect` invocations does not work well. S
3845 }
3846 }
3167 } 3847 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698