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

Unified Diff: vm/object_test.cc

Issue 11275008: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: vm/object_test.cc
===================================================================
--- vm/object_test.cc (revision 14046)
+++ vm/object_test.cc (working copy)
@@ -470,7 +470,6 @@
EXPECT(str.IsString());
EXPECT(str.IsOneByteString());
EXPECT(!str.IsTwoByteString());
- EXPECT(!str.IsFourByteString());
EXPECT(!str.IsNumber());
EXPECT_EQ(hello_len, str.Length());
EXPECT_EQ('H', str.CharAt(0));
@@ -541,7 +540,6 @@
EXPECT(two_str.IsString());
EXPECT(two_str.IsTwoByteString());
EXPECT(!two_str.IsOneByteString());
- EXPECT(!two_str.IsFourByteString());
EXPECT_EQ(kWideCharsLen, two_str.Length());
EXPECT_EQ('H', two_str.CharAt(0));
EXPECT_EQ(256, two_str.CharAt(5));
@@ -564,9 +562,8 @@
const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' };
const String& four_str = String::Handle(String::New(four_chars, 7));
EXPECT_EQ(four_str.Hash(), four_str.Hash());
- EXPECT(!four_str.IsTwoByteString());
+ EXPECT(four_str.IsTwoByteString());
EXPECT(!four_str.IsOneByteString());
- EXPECT(four_str.IsFourByteString());
EXPECT_EQ(7, four_str.Length());
EXPECT_EQ('C', four_str.CharAt(0));
EXPECT_EQ(0xFF, four_str.CharAt(1));
@@ -582,7 +579,6 @@
const String& str8 = String::Handle(String::New(char16, 3));
EXPECT(str8.IsOneByteString());
EXPECT(!str8.IsTwoByteString());
- EXPECT(!str8.IsFourByteString());
EXPECT_EQ(0x00, str8.CharAt(0));
EXPECT_EQ(0x7F, str8.CharAt(1));
EXPECT_EQ(0xFF, str8.CharAt(2));
@@ -594,7 +590,6 @@
const String& str8 = String::Handle(String::New(char32, 3));
EXPECT(str8.IsOneByteString());
EXPECT(!str8.IsTwoByteString());
- EXPECT(!str8.IsFourByteString());
EXPECT_EQ(0x00, str8.CharAt(0));
EXPECT_EQ(0x7F, str8.CharAt(1));
EXPECT_EQ(0xFF, str8.CharAt(2));
@@ -606,7 +601,6 @@
const String& str16 = String::Handle(String::New(char32, 3));
EXPECT(!str16.IsOneByteString());
EXPECT(str16.IsTwoByteString());
- EXPECT(!str16.IsFourByteString());
EXPECT_EQ(0x0000, str16.CharAt(0));
EXPECT_EQ(0x7FFF, str16.CharAt(1));
EXPECT_EQ(0xFFFF, str16.CharAt(2));
@@ -622,7 +616,6 @@
EXPECT(str.IsString());
EXPECT(str.IsOneByteString());
EXPECT(!str.IsTwoByteString());
- EXPECT(!str.IsFourByteString());
EXPECT(!str.IsNumber());
EXPECT(str.Equals(hello_str));
}
@@ -952,7 +945,7 @@
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
intptr_t four_len = sizeof(four) / sizeof(four[0]);
const String& str2 = String::Handle(String::New(four, four_len));
- EXPECT(str2.IsFourByteString());
+ EXPECT(str2.IsTwoByteString());
EXPECT_EQ(4, str2.Length());
// Concat
@@ -962,7 +955,7 @@
EXPECT(str3.Equals(str2));
const String& str4 = String::Handle(String::Concat(str2, str1));
- EXPECT(str4.IsFourByteString());
+ EXPECT(str4.IsTwoByteString());
EXPECT_EQ(four_len, str4.Length());
EXPECT(str4.Equals(str2));
@@ -973,7 +966,7 @@
array1.SetAt(0, str1);
array1.SetAt(1, str2);
const String& str5 = String::Handle(String::ConcatAll(array1));
- EXPECT(str5.IsFourByteString());
+ EXPECT(str5.IsTwoByteString());
EXPECT_EQ(four_len, str5.Length());
EXPECT(str5.Equals(str2));
@@ -982,7 +975,7 @@
array2.SetAt(0, str1);
array2.SetAt(1, str2);
const String& str6 = String::Handle(String::ConcatAll(array2));
- EXPECT(str6.IsFourByteString());
+ EXPECT(str6.IsTwoByteString());
EXPECT_EQ(four_len, str6.Length());
EXPECT(str6.Equals(str2));
@@ -992,7 +985,7 @@
array3.SetAt(1, str1);
array3.SetAt(2, str2);
const String& str7 = String::Handle(String::ConcatAll(array3));
- EXPECT(str7.IsFourByteString());
+ EXPECT(str7.IsTwoByteString());
uint32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]);
@@ -1005,19 +998,19 @@
const uint32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF };
intptr_t one_len = sizeof(one) / sizeof(one[0]);
const String& onestr = String::Handle(String::New(one, one_len));
- EXPECT(onestr.IsFourByteString());
+ EXPECT(onestr.IsTwoByteString());
EXPECT_EQ(one_len, onestr.Length());
const uint32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 };
intptr_t two_len = sizeof(two) / sizeof(two[0]);
const String& twostr = String::Handle(String::New(two, two_len));
- EXPECT(twostr.IsFourByteString());
+ EXPECT(twostr.IsTwoByteString());
EXPECT_EQ(two_len, twostr.Length());
// Concat
const String& str1 = String::Handle(String::Concat(onestr, twostr));
- EXPECT(str1.IsFourByteString());
+ EXPECT(str1.IsTwoByteString());
const uint32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF,
0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 };
intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]);
@@ -1025,7 +1018,7 @@
EXPECT(str1.Equals(one_two, one_two_len));
const String& str2 = String::Handle(String::Concat(twostr, onestr));
- EXPECT(str2.IsFourByteString());
+ EXPECT(str2.IsTwoByteString());
const uint32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9,
0x105D0, 0x105D9, 0x105D9, 0x105DF };
intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]);
@@ -1039,7 +1032,7 @@
array1.SetAt(0, onestr);
array1.SetAt(1, twostr);
const String& str3 = String::Handle(String::ConcatAll(array1));
- EXPECT(str3.IsFourByteString());
+ EXPECT(str3.IsTwoByteString());
EXPECT_EQ(one_two_len, str3.Length());
EXPECT(str3.Equals(one_two, one_two_len));
@@ -1048,7 +1041,7 @@
array2.SetAt(0, twostr);
array2.SetAt(1, onestr);
const String& str4 = String::Handle(String::ConcatAll(array2));
- EXPECT(str4.IsFourByteString());
+ EXPECT(str4.IsTwoByteString());
EXPECT_EQ(two_one_len, str4.Length());
EXPECT(str4.Equals(two_one, two_one_len));
@@ -1058,7 +1051,7 @@
array3.SetAt(1, twostr);
array3.SetAt(2, onestr);
const String& str5 = String::Handle(String::ConcatAll(array3));
- EXPECT(str5.IsFourByteString());
+ EXPECT(str5.IsTwoByteString());
const uint32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF,
0x105E6, 0x105D5, 0x105D5, 0x105D9,
0x105D9,
@@ -1073,7 +1066,7 @@
array4.SetAt(1, onestr);
array4.SetAt(2, twostr);
const String& str6 = String::Handle(String::ConcatAll(array4));
- EXPECT(str6.IsFourByteString());
+ EXPECT(str6.IsTwoByteString());
const uint32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9,
0x105D9,
0x105D0, 0x105D9, 0x105D9, 0x105DF,
@@ -1149,7 +1142,7 @@
EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len));
}
- // Concatenate 1-byte strings and 4-byte strings.
+ // Concatenate 1byte strings and 4byte strings.
{
const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
intptr_t one_len = sizeof(one) / sizeof(one[0]);
@@ -1161,7 +1154,7 @@
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
intptr_t four_len = sizeof(four) / sizeof(four[0]);
const String& fourstr = String::Handle(String::New(four, four_len));
- EXPECT(fourstr.IsFourByteString());
+ EXPECT(fourstr.IsTwoByteString());
EXPECT_EQ(four_len, fourstr.Length());
EXPECT(fourstr.Equals(four, four_len));
@@ -1169,7 +1162,7 @@
const String& one_four_str = String::Handle(String::Concat(onestr,
fourstr));
- EXPECT(one_four_str.IsFourByteString());
+ EXPECT(one_four_str.IsTwoByteString());
uint32_t one_four[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
intptr_t one_four_len = sizeof(one_four) / sizeof(one_four[0]);
@@ -1178,7 +1171,7 @@
const String& four_one_str = String::Handle(String::Concat(fourstr,
onestr));
- EXPECT(four_one_str.IsFourByteString());
+ EXPECT(four_one_str.IsTwoByteString());
uint32_t four_one[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
intptr_t four_one_len = sizeof(four_one) / sizeof(four_one[0]);
@@ -1193,7 +1186,7 @@
array1.SetAt(1, fourstr);
array1.SetAt(2, onestr);
const String& one_four_one = String::Handle(String::ConcatAll(array1));
- EXPECT(one_four_one.IsFourByteString());
+ EXPECT(one_four_one.IsTwoByteString());
EXPECT_EQ(onestr.Length()*2 + fourstr.Length(), one_four_one.Length());
const Array& array2 = Array::Handle(Array::New(3));
@@ -1202,11 +1195,11 @@
array2.SetAt(1, onestr);
array2.SetAt(2, fourstr);
const String& four_one_four = String::Handle(String::ConcatAll(array2));
- EXPECT(four_one_four.IsFourByteString());
+ EXPECT(four_one_four.IsTwoByteString());
EXPECT_EQ(fourstr.Length()*2 + onestr.Length(), four_one_four.Length());
}
- // Concatenate 2-byte strings and 4-byte strings.
+ // Concatenate 2byte strings and 4byte strings.
{
uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
intptr_t two_len = sizeof(two) / sizeof(two[0]);
@@ -1218,7 +1211,7 @@
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
intptr_t four_len = sizeof(four) / sizeof(four[0]);
const String& fourstr = String::Handle(String::New(four, four_len));
- EXPECT(fourstr.IsFourByteString());
+ EXPECT(fourstr.IsTwoByteString());
EXPECT_EQ(four_len, fourstr.Length());
EXPECT(fourstr.Equals(four, four_len));
@@ -1226,7 +1219,7 @@
const String& two_four_str = String::Handle(String::Concat(twostr,
fourstr));
- EXPECT(two_four_str.IsFourByteString());
+ EXPECT(two_four_str.IsTwoByteString());
uint32_t two_four[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
intptr_t two_four_len = sizeof(two_four) / sizeof(two_four[0]);
@@ -1235,7 +1228,7 @@
const String& four_two_str = String::Handle(String::Concat(fourstr,
twostr));
- EXPECT(four_two_str.IsFourByteString());
+ EXPECT(four_two_str.IsTwoByteString());
uint32_t four_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
intptr_t four_two_len = sizeof(four_two) / sizeof(four_two[0]);
@@ -1250,7 +1243,7 @@
array1.SetAt(1, fourstr);
array1.SetAt(2, twostr);
const String& two_four_two_str = String::Handle(String::ConcatAll(array1));
- EXPECT(two_four_two_str.IsFourByteString());
+ EXPECT(two_four_two_str.IsTwoByteString());
EXPECT_EQ(twostr.Length()*2 + fourstr.Length(), two_four_two_str.Length());
const Array& array2 = Array::Handle(Array::New(3));
@@ -1259,11 +1252,11 @@
array2.SetAt(1, twostr);
array2.SetAt(2, fourstr);
const String& four_two_four_str = String::Handle(String::ConcatAll(array2));
- EXPECT(four_two_four_str.IsFourByteString());
+ EXPECT(four_two_four_str.IsTwoByteString());
EXPECT_EQ(fourstr.Length()*2 + twostr.Length(), four_two_four_str.Length());
}
- // Concatenate 1-byte, 2-byte and 4-byte strings.
+ // Concatenate 1byte, 2byte and 4byte strings.
cshapiro 2012/10/24 23:52:29 Not sure why this was changed. The rules of gramm
siva 2012/10/26 21:38:29 Restored to original format. On 2012/10/24 23:52:
{
const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
intptr_t one_len = sizeof(one) / sizeof(one[0]);
@@ -1282,18 +1275,18 @@
uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
intptr_t four_len = sizeof(four) / sizeof(four[0]);
const String& fourstr = String::Handle(String::New(four, four_len));
- EXPECT(fourstr.IsFourByteString());
+ EXPECT(fourstr.IsTwoByteString());
EXPECT_EQ(four_len, fourstr.Length());
EXPECT(fourstr.Equals(four, four_len));
- // Last element is a 4-byte string.
+ // Last element is a 4byte string.
const Array& array1 = Array::Handle(Array::New(3));
EXPECT_EQ(3, array1.Length());
array1.SetAt(0, onestr);
array1.SetAt(1, twostr);
array1.SetAt(2, fourstr);
const String& one_two_four_str = String::Handle(String::ConcatAll(array1));
- EXPECT(one_two_four_str.IsFourByteString());
+ EXPECT(one_two_four_str.IsTwoByteString());
EXPECT_EQ(onestr.Length() + twostr.Length() + fourstr.Length(),
one_two_four_str.Length());
uint32_t one_two_four[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
@@ -1302,14 +1295,14 @@
intptr_t one_two_four_len = sizeof(one_two_four) / sizeof(one_two_four[0]);
EXPECT(one_two_four_str.Equals(one_two_four, one_two_four_len));
- // Middle element is a 4-byte string.
+ // Middle element is a 4byte string.
const Array& array2 = Array::Handle(Array::New(3));
EXPECT_EQ(3, array2.Length());
array2.SetAt(0, onestr);
array2.SetAt(1, fourstr);
array2.SetAt(2, twostr);
const String& one_four_two_str = String::Handle(String::ConcatAll(array2));
- EXPECT(one_four_two_str.IsFourByteString());
+ EXPECT(one_four_two_str.IsTwoByteString());
EXPECT_EQ(onestr.Length() + fourstr.Length() + twostr.Length(),
one_four_two_str.Length());
uint32_t one_four_two[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
@@ -1318,14 +1311,14 @@
intptr_t one_four_two_len = sizeof(one_four_two) / sizeof(one_four_two[0]);
EXPECT(one_four_two_str.Equals(one_four_two, one_four_two_len));
- // First element is a 4-byte string.
+ // First element is a 4byte string.
const Array& array3 = Array::Handle(Array::New(3));
EXPECT_EQ(3, array3.Length());
array3.SetAt(0, fourstr);
array3.SetAt(1, onestr);
array3.SetAt(2, twostr);
const String& four_one_two_str = String::Handle(String::ConcatAll(array3));
- EXPECT(one_four_two_str.IsFourByteString());
+ EXPECT(one_four_two_str.IsTwoByteString());
EXPECT_EQ(onestr.Length() + fourstr.Length() + twostr.Length(),
one_four_two_str.Length());
uint32_t four_one_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
@@ -1378,7 +1371,7 @@
const String& fourstr = String::Handle(String::New(fourchars));
EXPECT(!fourstr.IsNull());
- EXPECT(fourstr.IsFourByteString());
+ EXPECT(fourstr.IsTwoByteString());
const String& foursub1 = String::Handle(String::SubString(fourstr, 0, 3));
EXPECT(!foursub1.IsNull());
@@ -1393,7 +1386,7 @@
const String& foursub4 = String::Handle(String::SubString(fourstr, 6));
EXPECT_EQ(foursub4.Length(), 4);
EXPECT(!foursub4.IsNull());
- EXPECT(foursub4.IsFourByteString());
+ EXPECT(foursub4.IsTwoByteString());
}
@@ -1466,7 +1459,7 @@
}
}
- // Create a 2-byte string from UTF-8 encoded 1- and 2-byte
+ // Create a BMP 2-byte string from UTF-8 encoded 1- and 2-byte
// characters.
{
const char* src =
@@ -1491,14 +1484,14 @@
}
}
- // Create a 4-byte string from a UTF-8 string literal.
+ // Create a SMP 2-byte string from a UTF-8 string literal.
{
const char* src =
"\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1"
"\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3";
const intptr_t expected[] = { 0x1D460, 0x1D461, 0x1D462, 0x1D463 };
const String& str = String::Handle(String::New(src));
- EXPECT(str.IsFourByteString());
+ EXPECT(str.IsTwoByteString());
intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
EXPECT_EQ(expected_size, str.Length());
for (int i = 0; i < str.Length(); ++i) {
@@ -1506,7 +1499,7 @@
}
}
- // Create a 4-byte string from UTF-8 encoded 2- and 4-byte
+ // Create a SMP 2-byte string from UTF-8 encoded 2- and 4-byte
// characters.
{
const char* src =
@@ -1522,7 +1515,7 @@
0xD000, 0xE000, 0xF000, 0x1A000, 0x1B000, 0x1D000, 0x1E000, 0x1F000
};
const String& str = String::Handle(String::New(src));
- EXPECT(str.IsFourByteString());
+ EXPECT(str.IsTwoByteString());
intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
EXPECT_EQ(expected_size, str.Length());
for (int i = 0; i < str.Length(); ++i) {
@@ -1530,7 +1523,7 @@
}
}
- // Create a 4-byte string from UTF-8 encoded 1-, 2- and 4-byte
+ // Create a SMP 2-byte string from UTF-8 encoded 1-, 2- and 4-byte
// characters.
{
const char* src =
@@ -1551,7 +1544,7 @@
0x1A000, 0x1B000, 0x1D000, 0x1E000, 0x1F000
};
const String& str = String::Handle(String::New(src));
- EXPECT(str.IsFourByteString());
+ EXPECT(str.IsTwoByteString());
intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
EXPECT_EQ(expected_size, str.Length());
for (int i = 0; i < str.Length(); ++i) {
@@ -1626,42 +1619,6 @@
}
-TEST_CASE(ExternalFourByteString) {
- uint32_t characters[] = { 0x1D5BF, 0x1D5C8, 0x1D5CE, 0x1D5CB };
- intptr_t len = ARRAY_SIZE(characters);
-
- const String& str =
- String::Handle(
- ExternalFourByteString::New(characters, len, NULL, NULL, Heap::kNew));
- EXPECT(!str.IsFourByteString());
- EXPECT(str.IsExternalFourByteString());
- EXPECT_EQ(str.Length(), len);
- EXPECT(str.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
- "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
-
- const String& copy = String::Handle(String::SubString(str, 0, len));
- EXPECT(!copy.IsExternalFourByteString());
- EXPECT(copy.IsFourByteString());
- EXPECT_EQ(len, copy.Length());
- EXPECT(copy.Equals(str));
-
- const String& concat = String::Handle(String::Concat(str, str));
- EXPECT(!concat.IsExternalFourByteString());
- EXPECT(concat.IsFourByteString());
- EXPECT_EQ(len * 2, concat.Length());
- EXPECT(concat.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
- "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"
- "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
- "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
-
- const String& substr = String::Handle(String::SubString(str, 1, 2));
- EXPECT(!substr.IsExternalFourByteString());
- EXPECT(substr.IsFourByteString());
- EXPECT_EQ(2, substr.Length());
- EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E"));
-}
-
-
TEST_CASE(Symbol) {
const String& one = String::Handle(Symbols::New("Eins"));
EXPECT(one.IsSymbol());
@@ -2846,7 +2803,7 @@
"}\n";
Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
EXPECT_VALID(lib);
- Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL);
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
EXPECT_ERROR(
result,
"Unhandled exception:\n"

Powered by Google App Engine
This is Rietveld 408576698