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

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

Issue 8346014: Use the narrowest character width possible for substrings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improved changelog message. Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | 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 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 one_four_two_str.Length()); 1259 one_four_two_str.Length());
1260 uint32_t four_one_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, 1260 uint32_t four_one_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
1261 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e', 1261 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
1262 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; 1262 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1263 intptr_t four_one_two_len = sizeof(four_one_two) / sizeof(four_one_two[0]); 1263 intptr_t four_one_two_len = sizeof(four_one_two) / sizeof(four_one_two[0]);
1264 EXPECT(four_one_two_str.Equals(four_one_two, four_one_two_len)); 1264 EXPECT(four_one_two_str.Equals(four_one_two, four_one_two_len));
1265 } 1265 }
1266 } 1266 }
1267 1267
1268 1268
1269 TEST_CASE(StringSubStringDifferentWidth) {
1270 // Create 1-byte substring from a 1-byte source string.
1271 const char* onechars =
1272 "\xC3\xB6\xC3\xB1\xC3\xA9";
1273
1274 const String& onestr = String::Handle(String::New(onechars));
1275 EXPECT(!onestr.IsNull());
1276 EXPECT(onestr.IsOneByteString());
1277
1278 const String& onesub = String::Handle(String::SubString(onestr, 0));
1279 EXPECT(!onesub.IsNull());
1280 EXPECT(onestr.IsOneByteString());
1281 EXPECT_EQ(onesub.Length(), 3);
1282
1283 // Create 1- and 2-byte substrings from a 2-byte source string.
1284 const char* twochars =
1285 "\xC3\xB6\xC3\xB1\xC3\xA9"
1286 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93";
1287
1288 const String& twostr = String::Handle(String::New(twochars));
1289 EXPECT(!twostr.IsNull());
1290 EXPECT(twostr.IsTwoByteString());
1291
1292 const String& twosub1 = String::Handle(String::SubString(twostr, 0, 3));
1293 EXPECT(!twosub1.IsNull());
1294 EXPECT(twosub1.IsOneByteString());
1295 EXPECT_EQ(twosub1.Length(), 3);
1296
1297 const String& twosub2 = String::Handle(String::SubString(twostr, 3));
1298 EXPECT(!twosub2.IsNull());
1299 EXPECT(twosub2.IsTwoByteString());
1300 EXPECT_EQ(twosub2.Length(), 3);
1301
1302 // Create 1-, 2-, and 4-byte substrings from a 4-byte source string.
1303 const char* fourchars =
1304 "\xC3\xB6\xC3\xB1\xC3\xA9"
1305 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"
1306 "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B";
1307
1308 const String& fourstr = String::Handle(String::New(fourchars));
1309 EXPECT(!fourstr.IsNull());
1310 EXPECT(fourstr.IsFourByteString());
1311
1312 const String& foursub1 = String::Handle(String::SubString(fourstr, 0, 3));
1313 EXPECT(!foursub1.IsNull());
1314 EXPECT(foursub1.IsOneByteString());
1315 EXPECT_EQ(foursub1.Length(), 3);
1316
1317 const String& foursub2 = String::Handle(String::SubString(fourstr, 3, 3));
1318 EXPECT(!foursub2.IsNull());
1319 EXPECT(foursub2.IsTwoByteString());
1320 EXPECT_EQ(foursub2.Length(), 3);
1321
1322 const String& foursub4 = String::Handle(String::SubString(fourstr, 6));
1323 EXPECT_EQ(foursub4.Length(), 4);
1324 EXPECT(!foursub4.IsNull());
1325 EXPECT(foursub4.IsFourByteString());
1326 }
1327
1328
1269 TEST_CASE(StringFromUtf8Literal) { 1329 TEST_CASE(StringFromUtf8Literal) {
1270 // Create a 1-byte string from a UTF-8 encoded string literal. 1330 // Create a 1-byte string from a UTF-8 encoded string literal.
1271 { 1331 {
1272 const char* src = 1332 const char* src =
1273 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3" 1333 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3"
1274 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7" 1334 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7"
1275 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB" 1335 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB"
1276 "\xC2\xAC\xC2\xAD\xC2\xAE\xC2\xAF" 1336 "\xC2\xAC\xC2\xAD\xC2\xAE\xC2\xAF"
1277 "\xC2\xB0\xC2\xB1\xC2\xB2\xC2\xB3" 1337 "\xC2\xB0\xC2\xB1\xC2\xB2\xC2\xB3"
1278 "\xC2\xB4\xC2\xB5\xC2\xB6\xC2\xB7" 1338 "\xC2\xB4\xC2\xB5\xC2\xB6\xC2\xB7"
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 cls = iterator.GetNext(); 1949 cls = iterator.GetNext();
1890 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw())); 1950 ASSERT((cls.raw() == ae66.raw()) || (cls.raw() == re44.raw()));
1891 count++; 1951 count++;
1892 } 1952 }
1893 ASSERT(count == 2); 1953 ASSERT(count == 2);
1894 } 1954 }
1895 1955
1896 #endif // TARGET_ARCH_IA32. 1956 #endif // TARGET_ARCH_IA32.
1897 1957
1898 } // namespace dart 1958 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698