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

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

Issue 11416054: Provide a code point iterator to the String class to simplify iteration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review 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
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 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 1545
1546 other_array = Array::New(kArrayLen - 1); 1546 other_array = Array::New(kArrayLen - 1);
1547 other_array.SetAt(0, array); 1547 other_array.SetAt(0, array);
1548 other_array.SetAt(2, array); 1548 other_array.SetAt(2, array);
1549 EXPECT(!array.Equals(other_array)); 1549 EXPECT(!array.Equals(other_array));
1550 1550
1551 EXPECT_EQ(0, Array::Handle(Object::empty_array()).Length()); 1551 EXPECT_EQ(0, Array::Handle(Object::empty_array()).Length());
1552 } 1552 }
1553 1553
1554 1554
1555 TEST_CASE(StringCodePointIterator) {
1556 const String& str0 = String::Handle(String::New(""));
1557 String::CodePointIterator it0(str0);
1558 EXPECT(!it0.Next());
1559
1560 const String& str1 = String::Handle(String::New(" \xc3\xa7 "));
1561 String::CodePointIterator it1(str1);
1562 EXPECT(it1.Next());
1563 EXPECT_EQ(' ', it1.Current());
1564 EXPECT(it1.Next());
1565 EXPECT_EQ(0xE7, it1.Current());
1566 EXPECT(it1.Next());
1567 EXPECT_EQ(' ', it1.Current());
1568 EXPECT(!it1.Next());
1569
1570 const String& str2 = String::Handle(String::New("\xD7\x92\xD7\x9C"
1571 "\xD7\xA2\xD7\x93"
1572 "\xD7\x91\xD7\xA8"
1573 "\xD7\x9B\xD7\x94"));
1574 String::CodePointIterator it2(str2);
1575 EXPECT(it2.Next());
1576 EXPECT_EQ(0x5D2, it2.Current());
1577 EXPECT(it2.Next());
1578 EXPECT_EQ(0x5DC, it2.Current());
1579 EXPECT(it2.Next());
1580 EXPECT_EQ(0x5E2, it2.Current());
1581 EXPECT(it2.Next());
1582 EXPECT_EQ(0x5D3, it2.Current());
1583 EXPECT(it2.Next());
1584 EXPECT_EQ(0x5D1, it2.Current());
1585 EXPECT(it2.Next());
1586 EXPECT_EQ(0x5E8, it2.Current());
1587 EXPECT(it2.Next());
1588 EXPECT_EQ(0x5DB, it2.Current());
1589 EXPECT(it2.Next());
1590 EXPECT_EQ(0x5D4, it2.Current());
1591 EXPECT(!it2.Next());
1592
1593 const String& str3 = String::Handle(String::New("\xF0\x9D\x91\xA0"
1594 "\xF0\x9D\x91\xA1"
1595 "\xF0\x9D\x91\xA2"
1596 "\xF0\x9D\x91\xA3"));
1597 String::CodePointIterator it3(str3);
1598 EXPECT(it3.Next());
1599 EXPECT_EQ(0x1D460, it3.Current());
1600 EXPECT(it3.Next());
1601 EXPECT_EQ(0x1D461, it3.Current());
1602 EXPECT(it3.Next());
1603 EXPECT_EQ(0x1D462, it3.Current());
1604 EXPECT(it3.Next());
1605 EXPECT_EQ(0x1D463, it3.Current());
1606 EXPECT(!it3.Next());
1607 }
1608
1609
1555 TEST_CASE(GrowableObjectArray) { 1610 TEST_CASE(GrowableObjectArray) {
1556 const int kArrayLen = 5; 1611 const int kArrayLen = 5;
1557 Smi& value = Smi::Handle(); 1612 Smi& value = Smi::Handle();
1558 Smi& expected_value = Smi::Handle(); 1613 Smi& expected_value = Smi::Handle();
1559 GrowableObjectArray& array = GrowableObjectArray::Handle(); 1614 GrowableObjectArray& array = GrowableObjectArray::Handle();
1560 1615
1561 // Test basic growing functionality. 1616 // Test basic growing functionality.
1562 array = GrowableObjectArray::New(kArrayLen); 1617 array = GrowableObjectArray::New(kArrayLen);
1563 EXPECT_EQ(kArrayLen, array.Capacity()); 1618 EXPECT_EQ(kArrayLen, array.Capacity());
1564 EXPECT_EQ(0, array.Length()); 1619 EXPECT_EQ(0, array.Length());
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 isolate->heap()->CollectAllGarbage(); 3086 isolate->heap()->CollectAllGarbage();
3032 EXPECT(weak1.key() == Object::null()); 3087 EXPECT(weak1.key() == Object::null());
3033 EXPECT(weak1.value() == Object::null()); 3088 EXPECT(weak1.value() == Object::null());
3034 EXPECT(weak2.key() == Object::null()); 3089 EXPECT(weak2.key() == Object::null());
3035 EXPECT(weak2.value() == Object::null()); 3090 EXPECT(weak2.value() == Object::null());
3036 } 3091 }
3037 3092
3038 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3093 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3039 3094
3040 } // namespace dart 3095 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | runtime/vm/unicode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698