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

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: pre-review clean-up 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
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 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 EXPECT(str.IsFourByteString()); 1484 EXPECT(str.IsFourByteString());
1485 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1485 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1486 EXPECT_EQ(expected_size, str.Length()); 1486 EXPECT_EQ(expected_size, str.Length());
1487 for (int i = 0; i < str.Length(); ++i) { 1487 for (int i = 0; i < str.Length(); ++i) {
1488 EXPECT_EQ(expected[i], str.CharAt(i)); 1488 EXPECT_EQ(expected[i], str.CharAt(i));
1489 } 1489 }
1490 } 1490 }
1491 } 1491 }
1492 1492
1493 1493
1494 TEST_CASE(ExternalOneByteString) {
1495 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 };
1496 intptr_t len = ARRAY_SIZE(characters);
1497
1498 const String& str =
1499 String::Handle(
1500 ExternalOneByteString::New(characters, len, NULL, Heap::kNew));
1501 EXPECT(!str.IsOneByteString());
1502 EXPECT(str.IsExternalOneByteString());
1503 EXPECT_EQ(str.Length(), len);
1504 EXPECT(str.Equals("\xC3\xB6\xC3\xB1\xC3\xA9"));
1505
1506 const String& copy = String::Handle(String::SubString(str, 0, len));
1507 EXPECT(!copy.IsExternalOneByteString());
1508 EXPECT(copy.IsOneByteString());
1509 EXPECT_EQ(len, copy.Length());
1510 EXPECT(copy.Equals(str));
1511
1512 const String& concat = String::Handle(String::Concat(str, str));
1513 EXPECT(!concat.IsExternalOneByteString());
1514 EXPECT(concat.IsOneByteString());
1515 EXPECT_EQ(len * 2, concat.Length());
1516 EXPECT(concat.Equals("\xC3\xB6\xC3\xB1\xC3\xA9\xC3\xB6\xC3\xB1\xC3\xA9"));
1517
1518 const String& substr = String::Handle(String::SubString(str, 1, 1));
1519 EXPECT(!substr.IsExternalOneByteString());
1520 EXPECT(substr.IsOneByteString());
1521 EXPECT_EQ(1, substr.Length());
1522 EXPECT(substr.Equals("\xC3\xB1"));
1523 }
1524
1525
1526 TEST_CASE(ExternalTwoByteString) {
1527 uint16_t characters[] = { 0x1E6B, 0x1E85, 0x1E53 };
1528 intptr_t len = ARRAY_SIZE(characters);
1529
1530 const String& str =
1531 String::Handle(
1532 ExternalTwoByteString::New(characters, len, NULL, Heap::kNew));
1533 EXPECT(!str.IsTwoByteString());
1534 EXPECT(str.IsExternalTwoByteString());
1535 EXPECT_EQ(str.Length(), len);
1536 EXPECT(str.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1537
1538 const String& copy = String::Handle(String::SubString(str, 0, len));
1539 EXPECT(!copy.IsExternalTwoByteString());
1540 EXPECT(copy.IsTwoByteString());
1541 EXPECT_EQ(len, copy.Length());
1542 EXPECT(copy.Equals(str));
1543
1544 const String& concat = String::Handle(String::Concat(str, str));
1545 EXPECT(!concat.IsExternalTwoByteString());
1546 EXPECT(concat.IsTwoByteString());
1547 EXPECT_EQ(len * 2, concat.Length());
1548 EXPECT(concat.Equals("\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"
1549 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1550
1551 const String& substr = String::Handle(String::SubString(str, 1, 1));
1552 EXPECT(!substr.IsExternalTwoByteString());
1553 EXPECT(substr.IsTwoByteString());
1554 EXPECT_EQ(1, substr.Length());
1555 EXPECT(substr.Equals("\xE1\xBA\x85"));
1556 }
1557
1558
1559 TEST_CASE(ExternalFourByteString) {
1560 uint32_t characters[] = { 0x1D5BF, 0x1D5C8, 0x1D5CE, 0x1D5CB };
1561 intptr_t len = ARRAY_SIZE(characters);
1562
1563 const String& str =
1564 String::Handle(
1565 ExternalFourByteString::New(characters, len, NULL, Heap::kNew));
1566 EXPECT(!str.IsFourByteString());
1567 EXPECT(str.IsExternalFourByteString());
1568 EXPECT_EQ(str.Length(), len);
1569 EXPECT(str.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1570 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1571
1572 const String& copy = String::Handle(String::SubString(str, 0, len));
1573 EXPECT(!copy.IsExternalFourByteString());
1574 EXPECT(copy.IsFourByteString());
1575 EXPECT_EQ(len, copy.Length());
1576 EXPECT(copy.Equals(str));
1577
1578 const String& concat = String::Handle(String::Concat(str, str));
1579 EXPECT(!concat.IsExternalFourByteString());
1580 EXPECT(concat.IsFourByteString());
1581 EXPECT_EQ(len * 2, concat.Length());
1582 EXPECT(concat.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1583 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"
1584 "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1585 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1586
1587 const String& substr = String::Handle(String::SubString(str, 1, 2));
1588 EXPECT(!substr.IsExternalFourByteString());
1589 EXPECT(substr.IsFourByteString());
1590 EXPECT_EQ(2, substr.Length());
1591 EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E"));
1592 }
1593
1594
1494 TEST_CASE(Symbol) { 1595 TEST_CASE(Symbol) {
1495 const String& one = String::Handle(String::NewSymbol("Eins")); 1596 const String& one = String::Handle(String::NewSymbol("Eins"));
1496 EXPECT(one.IsSymbol()); 1597 EXPECT(one.IsSymbol());
1497 const String& two = String::Handle(String::NewSymbol("Zwei")); 1598 const String& two = String::Handle(String::NewSymbol("Zwei"));
1498 const String& three = String::Handle(String::NewSymbol("Drei")); 1599 const String& three = String::Handle(String::NewSymbol("Drei"));
1499 const String& four = String::Handle(String::NewSymbol("Vier")); 1600 const String& four = String::Handle(String::NewSymbol("Vier"));
1500 const String& five = String::Handle(String::NewSymbol("Fuenf")); 1601 const String& five = String::Handle(String::NewSymbol("Fuenf"));
1501 const String& six = String::Handle(String::NewSymbol("Sechs")); 1602 const String& six = String::Handle(String::NewSymbol("Sechs"));
1502 const String& seven = String::Handle(String::NewSymbol("Sieben")); 1603 const String& seven = String::Handle(String::NewSymbol("Sieben"));
1503 const String& eight = String::Handle(String::NewSymbol("Acht")); 1604 const String& eight = String::Handle(String::NewSymbol("Acht"));
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 cls = iterator.GetNextClass(); 2051 cls = iterator.GetNextClass();
1951 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); 2052 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw()));
1952 count++; 2053 count++;
1953 } 2054 }
1954 ASSERT(count == 2); 2055 ASSERT(count == 2);
1955 } 2056 }
1956 2057
1957 #endif // TARGET_ARCH_IA32. 2058 #endif // TARGET_ARCH_IA32.
1958 2059
1959 } // namespace dart 2060 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698