OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_tools_api.h" | 6 #include "include/dart_tools_api.h" |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 | 1438 |
1439 TEST_CASE(IsolateReload_EnumDelete) { | 1439 TEST_CASE(IsolateReload_EnumDelete) { |
1440 const char* kScript = | 1440 const char* kScript = |
1441 "enum Fruit {\n" | 1441 "enum Fruit {\n" |
1442 " Apple,\n" | 1442 " Apple,\n" |
1443 " Banana,\n" | 1443 " Banana,\n" |
1444 " Cantalope,\n" | 1444 " Cantalope,\n" |
1445 "}\n" | 1445 "}\n" |
1446 "var x;\n" | 1446 "var x;\n" |
1447 "main() {\n" | 1447 "main() {\n" |
| 1448 " x = Fruit.Cantalope;\n" |
1448 " return Fruit.Apple.toString();\n" | 1449 " return Fruit.Apple.toString();\n" |
1449 "}\n"; | 1450 "}\n"; |
1450 | 1451 |
1451 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 1452 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
1452 EXPECT_VALID(lib); | 1453 EXPECT_VALID(lib); |
1453 | 1454 |
1454 EXPECT_STREQ("Fruit.Apple", SimpleInvokeStr(lib, "main")); | 1455 EXPECT_STREQ("Fruit.Apple", SimpleInvokeStr(lib, "main")); |
1455 | 1456 |
1456 // Delete 'Cantalope'. | 1457 // Delete 'Cantalope' but make sure that we can still invoke toString, |
| 1458 // and access the hashCode and index properties. |
1457 | 1459 |
1458 const char* kReloadScript = | 1460 const char* kReloadScript = |
1459 "enum Fruit {\n" | 1461 "enum Fruit {\n" |
1460 " Apple,\n" | 1462 " Apple,\n" |
1461 " Banana,\n" | 1463 " Banana,\n" |
1462 "}\n" | 1464 "}\n" |
1463 "var x;\n" | 1465 "var x;\n" |
1464 "main() {\n" | 1466 "main() {\n" |
1465 " String r = '${Fruit.Apple.index}/${Fruit.Apple} ';\n" | 1467 " String r = '$x ${x.hashCode is int} ${x.index}';\n" |
1466 " r += '${Fruit.Banana.index}/${Fruit.Banana} ';\n" | |
1467 " r += '${Fruit.Cantalope.index}/${Fruit.Cantalope}';\n" | |
1468 " return r;\n" | 1468 " return r;\n" |
1469 "}\n"; | 1469 "}\n"; |
1470 | 1470 |
1471 lib = TestCase::ReloadTestScript(kReloadScript); | 1471 lib = TestCase::ReloadTestScript(kReloadScript); |
1472 EXPECT_VALID(lib); | 1472 EXPECT_VALID(lib); |
1473 | 1473 |
1474 EXPECT_STREQ("0/Fruit.Apple 1/Fruit.Banana 2/Fruit.Cantalope", | 1474 EXPECT_STREQ("Fruit.Cantalope true 2", |
1475 SimpleInvokeStr(lib, "main")); | 1475 SimpleInvokeStr(lib, "main")); |
1476 } | 1476 } |
1477 | 1477 |
1478 | |
1479 TEST_CASE(IsolateReload_EnumComplex) { | |
1480 const char* kScript = | |
1481 "enum Fruit {\n" | |
1482 " Apple,\n" | |
1483 " Banana,\n" | |
1484 " Cantalope,\n" | |
1485 "}\n" | |
1486 "var x;\n" | |
1487 "var y;\n" | |
1488 "var z;\n" | |
1489 "main() {\n" | |
1490 " x = Fruit.Apple;\n" | |
1491 " y = Fruit.Banana;\n" | |
1492 " z = Fruit.Cantalope;\n" | |
1493 " return Fruit.Apple.toString();\n" | |
1494 "}\n"; | |
1495 | |
1496 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
1497 EXPECT_VALID(lib); | |
1498 | |
1499 EXPECT_STREQ("Fruit.Apple", SimpleInvokeStr(lib, "main")); | |
1500 | |
1501 // Delete 'Cantalope'. Add 'Dragon'. Move 'Apple' and 'Banana'. | |
1502 | |
1503 const char* kReloadScript = | |
1504 "enum Fruit {\n" | |
1505 " Dragon,\n" | |
1506 " Apple,\n" | |
1507 " Banana,\n" | |
1508 "}\n" | |
1509 "var x;\n" | |
1510 "var y;\n" | |
1511 "var z;\n" | |
1512 "main() {\n" | |
1513 " String r = '';\n" | |
1514 " r += '${identical(x, Fruit.Apple)}';\n" | |
1515 " r += ' ${identical(y, Fruit.Banana)}';\n" | |
1516 " r += ' ${identical(z, Fruit.Cantalope)}';\n" | |
1517 " r += ' ${Fruit.Dragon}';\n" | |
1518 " return r;\n" | |
1519 "}\n"; | |
1520 | |
1521 lib = TestCase::ReloadTestScript(kReloadScript); | |
1522 EXPECT_VALID(lib); | |
1523 | |
1524 EXPECT_STREQ("true true true Fruit.Dragon", SimpleInvokeStr(lib, "main")); | |
1525 } | |
1526 | |
1527 | |
1528 TEST_CASE(IsolateReload_EnumValuesArray) { | |
1529 const char* kScript = | |
1530 "enum Fruit {\n" | |
1531 " Cantalope,\n" | |
1532 " Apple,\n" | |
1533 " Banana,\n" | |
1534 "}\n" | |
1535 "var x;\n" | |
1536 "main() {\n" | |
1537 " x = Fruit.Cantalope;\n" | |
1538 " return Fruit.Apple.toString();\n" | |
1539 "}\n"; | |
1540 | |
1541 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
1542 EXPECT_VALID(lib); | |
1543 | |
1544 EXPECT_STREQ("Fruit.Apple", SimpleInvokeStr(lib, "main")); | |
1545 | |
1546 // Delete 'Cantalope'. | |
1547 | |
1548 const char* kReloadScript = | |
1549 "enum Fruit {\n" | |
1550 " Banana,\n" | |
1551 " Apple\n" | |
1552 "}\n" | |
1553 "var x;\n" | |
1554 "bool identityCheck(Fruit f) {\n" | |
1555 " return identical(Fruit.values[f.index], f);\n" | |
1556 "}\n" | |
1557 "main() {\n" | |
1558 " if ((x is Fruit) && identical(x, Fruit.Cantalope)) {\n" | |
1559 " String r = '${identityCheck(Fruit.Apple)}';\n" | |
1560 " r += ' ${identityCheck(Fruit.Banana)}';\n" | |
1561 " r += ' ${identityCheck(Fruit.Cantalope)}';\n" | |
1562 " r += ' ${identityCheck(x)}';\n" | |
1563 " return r;\n" | |
1564 " }\n" | |
1565 "}\n"; | |
1566 | |
1567 lib = TestCase::ReloadTestScript(kReloadScript); | |
1568 EXPECT_VALID(lib); | |
1569 | |
1570 EXPECT_STREQ("true true true true", | |
1571 SimpleInvokeStr(lib, "main")); | |
1572 } | |
1573 | |
1574 | 1478 |
1575 TEST_CASE(IsolateReload_EnumIdentityReload) { | 1479 TEST_CASE(IsolateReload_EnumIdentityReload) { |
1576 const char* kScript = | 1480 const char* kScript = |
1577 "enum Fruit {\n" | 1481 "enum Fruit {\n" |
1578 " Apple,\n" | 1482 " Apple,\n" |
1579 " Banana,\n" | 1483 " Banana,\n" |
1580 " Cantalope,\n" | 1484 " Cantalope,\n" |
1581 "}\n" | 1485 "}\n" |
1582 "var x;\n" | 1486 "var x;\n" |
1583 "var y;\n" | 1487 "var y;\n" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1899 | 1803 |
1900 // ...and the non-core subclass is still named AIterator. | 1804 // ...and the non-core subclass is still named AIterator. |
1901 new_subclass = subclasses.At(subclasses.Length() - 1); | 1805 new_subclass = subclasses.At(subclasses.Length() - 1); |
1902 name = Class::Cast(new_subclass).Name(); | 1806 name = Class::Cast(new_subclass).Name(); |
1903 EXPECT_STREQ("AIterator", name.ToCString()); | 1807 EXPECT_STREQ("AIterator", name.ToCString()); |
1904 } | 1808 } |
1905 | 1809 |
1906 #endif // !PRODUCT | 1810 #endif // !PRODUCT |
1907 | 1811 |
1908 } // namespace dart | 1812 } // namespace dart |
OLD | NEW |