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

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

Issue 11418095: Use the code point iterator in equality comparisons to C strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add comments Created 8 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.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "platform/assert.h" 5 #include "platform/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 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 EXPECT(str.IsTwoByteString()); 1379 EXPECT(str.IsTwoByteString());
1380 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1380 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1381 EXPECT_EQ(expected_size, str.Length()); 1381 EXPECT_EQ(expected_size, str.Length());
1382 for (int i = 0; i < str.Length(); ++i) { 1382 for (int i = 0; i < str.Length(); ++i) {
1383 EXPECT_EQ(expected[i], str.CharAt(i)); 1383 EXPECT_EQ(expected[i], str.CharAt(i));
1384 } 1384 }
1385 } 1385 }
1386 } 1386 }
1387 1387
1388 1388
1389 TEST_CASE(StringEqualsUtf8) {
1390 const char* onesrc = "abc";
1391 const String& onestr = String::Handle(String::New(onesrc));
1392 EXPECT(onestr.IsOneByteString());
1393 EXPECT(!onestr.Equals(""));
1394 EXPECT(!onestr.Equals("a"));
1395 EXPECT(!onestr.Equals("ab"));
1396 EXPECT(onestr.Equals("abc"));
1397 EXPECT(!onestr.Equals("abcd"));
1398
1399 const char* twosrc = "\xD7\x90\xD7\x91\xD7\x92";
1400 const String& twostr = String::Handle(String::New(twosrc));
1401 EXPECT(twostr.IsTwoByteString());
1402 EXPECT(!twostr.Equals(""));
1403 EXPECT(!twostr.Equals("\xD7\x90"));
1404 EXPECT(!twostr.Equals("\xD7\x90\xD7\x91"));
1405 EXPECT(twostr.Equals("\xD7\x90\xD7\x91\xD7\x92"));
1406 EXPECT(!twostr.Equals("\xD7\x90\xD7\x91\xD7\x92\xD7\x93"));
1407
1408 const char* foursrc = "\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2";
1409 const String& fourstr = String::Handle(String::New(foursrc));
1410 EXPECT(fourstr.IsTwoByteString());
1411 EXPECT(!fourstr.Equals(""));
1412 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0"));
1413 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1"));
1414 EXPECT(fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1\xF0\x90\x8E\xA2"));
1415 EXPECT(!fourstr.Equals("\xF0\x90\x8E\xA0\xF0\x90\x8E\xA1"
1416 "\xF0\x90\x8E\xA2\xF0\x90\x8E\xA3"));
1417 }
1418
1419
1389 TEST_CASE(ExternalOneByteString) { 1420 TEST_CASE(ExternalOneByteString) {
1390 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 }; 1421 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 };
1391 intptr_t len = ARRAY_SIZE(characters); 1422 intptr_t len = ARRAY_SIZE(characters);
1392 1423
1393 const String& str = 1424 const String& str =
1394 String::Handle( 1425 String::Handle(
1395 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew)); 1426 ExternalOneByteString::New(characters, len, NULL, NULL, Heap::kNew));
1396 EXPECT(!str.IsOneByteString()); 1427 EXPECT(!str.IsOneByteString());
1397 EXPECT(str.IsExternalOneByteString()); 1428 EXPECT(str.IsExternalOneByteString());
1398 EXPECT_EQ(str.Length(), len); 1429 EXPECT_EQ(str.Length(), len);
(...skipping 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
3087 isolate->heap()->CollectAllGarbage(); 3118 isolate->heap()->CollectAllGarbage();
3088 EXPECT(weak1.key() == Object::null()); 3119 EXPECT(weak1.key() == Object::null());
3089 EXPECT(weak1.value() == Object::null()); 3120 EXPECT(weak1.value() == Object::null());
3090 EXPECT(weak2.key() == Object::null()); 3121 EXPECT(weak2.key() == Object::null());
3091 EXPECT(weak2.value() == Object::null()); 3122 EXPECT(weak2.value() == Object::null());
3092 } 3123 }
3093 3124
3094 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3125 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3095 3126
3096 } // namespace dart 3127 } // 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