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

Side by Side Diff: runtime/vm/object_test.cc

Issue 8383029: Implement external strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address final review comments Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object_store.cc ('k') | runtime/vm/raw_object.h » ('j') | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/assert.h" 5 #include "vm/assert.h"
6 #include "vm/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 EXPECT(str.IsFourByteString()); 1481 EXPECT(str.IsFourByteString());
1482 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1482 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1483 EXPECT_EQ(expected_size, str.Length()); 1483 EXPECT_EQ(expected_size, str.Length());
1484 for (int i = 0; i < str.Length(); ++i) { 1484 for (int i = 0; i < str.Length(); ++i) {
1485 EXPECT_EQ(expected[i], str.CharAt(i)); 1485 EXPECT_EQ(expected[i], str.CharAt(i));
1486 } 1486 }
1487 } 1487 }
1488 } 1488 }
1489 1489
1490 1490
1491 TEST_CASE(ExternalOneByteString) {
1492 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 };
1493 intptr_t len = ARRAY_SIZE(characters);
1494
1495 const String& str =
1496 String::Handle(
1497 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew));
1498 EXPECT(!str.IsOneByteString());
1499 EXPECT(str.IsExternalOneByteString());
1500 EXPECT_EQ(str.Length(), len);
1501 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9"));
1502
1503 const String& copy = String::Handle(String::SubString(str, 0, len));
1504 EXPECT(!copy.IsExternalOneByteString());
1505 EXPECT(copy.IsOneByteString());
1506 EXPECT_EQ(len, copy.Length());
1507 EXPECT(copy.Equals(str));
1508
1509 const String& concat = String::Handle(String::Concat(str, str));
1510 EXPECT(!concat.IsExternalOneByteString());
1511 EXPECT(concat.IsOneByteString());
1512 EXPECT_EQ(len * 2, concat.Length());
1513 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9"));
1514
1515 const String& substr = String::Handle(String::SubString(str, 1, 1));
1516 EXPECT(!substr.IsExternalOneByteString());
1517 EXPECT(substr.IsOneByteString());
1518 EXPECT_EQ(1, substr.Length());
1519 EXPECT(substr.Equals("\xC3\xB1"));
1520 }
1521
1522
1523 TEST_CASE(ExternalTwoByteString) {
1524 uint16_t characters[] = { 0x1E6B, 0x1E85, 0x1E53 };
1525 intptr_t len = ARRAY_SIZE(characters);
1526
1527 const String& str =
1528 String::Handle(
1529 ExternalTwoByteString::New(characters, len, NULL, NULL, Heap::kNew));
1530 EXPECT(!str.IsTwoByteString());
1531 EXPECT(str.IsExternalTwoByteString());
1532 EXPECT_EQ(str.Length(), len);
1533 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1534
1535 const String& copy = String::Handle(String::SubString(str, 0, len));
1536 EXPECT(!copy.IsExternalTwoByteString());
1537 EXPECT(copy.IsTwoByteString());
1538 EXPECT_EQ(len, copy.Length());
1539 EXPECT(copy.Equals(str));
1540
1541 const String& concat = String::Handle(String::Concat(str, str));
1542 EXPECT(!concat.IsExternalTwoByteString());
1543 EXPECT(concat.IsTwoByteString());
1544 EXPECT_EQ(len * 2, concat.Length());
1545 EXPECT(concat.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"
1546 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1547
1548 const String& substr = String::Handle(String::SubString(str, 1, 1));
1549 EXPECT(!substr.IsExternalTwoByteString());
1550 EXPECT(substr.IsTwoByteString());
1551 EXPECT_EQ(1, substr.Length());
1552 EXPECT(substr.Equals("\xE1\xBA\x85"));
1553 }
1554
1555
1556 TEST_CASE(ExternalFourByteString) {
1557 uint32_t characters[] = { 0x1D5BF, 0x1D5C8, 0x1D5CE, 0x1D5CB };
1558 intptr_t len = ARRAY_SIZE(characters);
1559
1560 const String& str =
1561 String::Handle(
1562 ExternalFourByteString::New(characters, len, NULL, NULL, Heap::kNew));
1563 EXPECT(!str.IsFourByteString());
1564 EXPECT(str.IsExternalFourByteString());
1565 EXPECT_EQ(str.Length(), len);
1566 EXPECT(str.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1567 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1568
1569 const String& copy = String::Handle(String::SubString(str, 0, len));
1570 EXPECT(!copy.IsExternalFourByteString());
1571 EXPECT(copy.IsFourByteString());
1572 EXPECT_EQ(len, copy.Length());
1573 EXPECT(copy.Equals(str));
1574
1575 const String& concat = String::Handle(String::Concat(str, str));
1576 EXPECT(!concat.IsExternalFourByteString());
1577 EXPECT(concat.IsFourByteString());
1578 EXPECT_EQ(len * 2, concat.Length());
1579 EXPECT(concat.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1580 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"
1581 "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1582 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1583
1584 const String& substr = String::Handle(String::SubString(str, 1, 2));
1585 EXPECT(!substr.IsExternalFourByteString());
1586 EXPECT(substr.IsFourByteString());
1587 EXPECT_EQ(2, substr.Length());
1588 EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E"));
1589 }
1590
1591
1491 TEST_CASE(Symbol) { 1592 TEST_CASE(Symbol) {
1492 const String& one = String::Handle(String::NewSymbol("Eins")); 1593 const String& one = String::Handle(String::NewSymbol("Eins"));
1493 EXPECT(one.IsSymbol()); 1594 EXPECT(one.IsSymbol());
1494 const String& two = String::Handle(String::NewSymbol("Zwei")); 1595 const String& two = String::Handle(String::NewSymbol("Zwei"));
1495 const String& three = String::Handle(String::NewSymbol("Drei")); 1596 const String& three = String::Handle(String::NewSymbol("Drei"));
1496 const String& four = String::Handle(String::NewSymbol("Vier")); 1597 const String& four = String::Handle(String::NewSymbol("Vier"));
1497 const String& five = String::Handle(String::NewSymbol("Fuenf")); 1598 const String& five = String::Handle(String::NewSymbol("Fuenf"));
1498 const String& six = String::Handle(String::NewSymbol("Sechs")); 1599 const String& six = String::Handle(String::NewSymbol("Sechs"));
1499 const String& seven = String::Handle(String::NewSymbol("Sieben")); 1600 const String& seven = String::Handle(String::NewSymbol("Sieben"));
1500 const String& eight = String::Handle(String::NewSymbol("Acht")); 1601 const String& eight = String::Handle(String::NewSymbol("Acht"));
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 cls = iterator.GetNextClass(); 2214 cls = iterator.GetNextClass();
2114 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); 2215 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw()));
2115 count++; 2216 count++;
2116 } 2217 }
2117 ASSERT(count == 2); 2218 ASSERT(count == 2);
2118 } 2219 }
2119 2220
2120 #endif // TARGET_ARCH_IA32. 2221 #endif // TARGET_ARCH_IA32.
2121 2222
2122 } // namespace dart 2223 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_store.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698