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

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

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 464
465 TEST_CASE(String) { 465 TEST_CASE(String) {
466 const char* kHello = "Hello World!"; 466 const char* kHello = "Hello World!";
467 int32_t hello_len = strlen(kHello); 467 int32_t hello_len = strlen(kHello);
468 const String& str = String::Handle(String::New(kHello)); 468 const String& str = String::Handle(String::New(kHello));
469 EXPECT(str.IsInstance()); 469 EXPECT(str.IsInstance());
470 EXPECT(str.IsString()); 470 EXPECT(str.IsString());
471 EXPECT(str.IsOneByteString()); 471 EXPECT(str.IsOneByteString());
472 EXPECT(!str.IsTwoByteString()); 472 EXPECT(!str.IsTwoByteString());
473 EXPECT(!str.IsFourByteString());
474 EXPECT(!str.IsNumber()); 473 EXPECT(!str.IsNumber());
475 EXPECT_EQ(hello_len, str.Length()); 474 EXPECT_EQ(hello_len, str.Length());
476 EXPECT_EQ('H', str.CharAt(0)); 475 EXPECT_EQ('H', str.CharAt(0));
477 EXPECT_EQ('e', str.CharAt(1)); 476 EXPECT_EQ('e', str.CharAt(1));
478 EXPECT_EQ('l', str.CharAt(2)); 477 EXPECT_EQ('l', str.CharAt(2));
479 EXPECT_EQ('l', str.CharAt(3)); 478 EXPECT_EQ('l', str.CharAt(3));
480 EXPECT_EQ('o', str.CharAt(4)); 479 EXPECT_EQ('o', str.CharAt(4));
481 EXPECT_EQ(' ', str.CharAt(5)); 480 EXPECT_EQ(' ', str.CharAt(5));
482 EXPECT_EQ('W', str.CharAt(6)); 481 EXPECT_EQ('W', str.CharAt(6));
483 EXPECT_EQ('o', str.CharAt(7)); 482 EXPECT_EQ('o', str.CharAt(7));
(...skipping 24 matching lines...) Expand all
508 const String& str6 = String::Handle(String::Concat(str4, str5)); 507 const String& str6 = String::Handle(String::Concat(str4, str5));
509 const String& str7 = String::Handle(String::New("foobar")); 508 const String& str7 = String::Handle(String::New("foobar"));
510 EXPECT(str6.Equals(str7)); 509 EXPECT(str6.Equals(str7));
511 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4)))); 510 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4))));
512 511
513 const String& empty1 = String::Handle(String::New("")); 512 const String& empty1 = String::Handle(String::New(""));
514 const String& empty2 = String::Handle(String::New("")); 513 const String& empty2 = String::Handle(String::New(""));
515 EXPECT(empty1.Equals(empty2, 0, 0)); 514 EXPECT(empty1.Equals(empty2, 0, 0));
516 515
517 const intptr_t kCharsLen = 8; 516 const intptr_t kCharsLen = 8;
518 const uint8_t chars[kCharsLen] = { 1, 2, 127, 128, 192, 0, 255, -1 }; 517 const uint8_t chars[kCharsLen] = { 1, 2, 127, 64, 92, 0, 55, 55 };
519 const String& str8 = String::Handle(String::New(chars, kCharsLen)); 518 const String& str8 = String::Handle(String::New(chars, kCharsLen));
520 EXPECT_EQ(kCharsLen, str8.Length()); 519 EXPECT_EQ(kCharsLen, str8.Length());
521 EXPECT_EQ(1, str8.CharAt(0)); 520 EXPECT_EQ(1, str8.CharAt(0));
522 EXPECT_EQ(127, str8.CharAt(2)); 521 EXPECT_EQ(127, str8.CharAt(2));
523 EXPECT_EQ(128, str8.CharAt(3)); 522 EXPECT_EQ(64, str8.CharAt(3));
524 EXPECT_EQ(0, str8.CharAt(5)); 523 EXPECT_EQ(0, str8.CharAt(5));
525 EXPECT_EQ(255, str8.CharAt(6)); 524 EXPECT_EQ(55, str8.CharAt(6));
526 EXPECT_EQ(255, str8.CharAt(7)); 525 EXPECT_EQ(55, str8.CharAt(7));
527 const intptr_t kCharsIndex = 3; 526 const intptr_t kCharsIndex = 3;
528 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex)); 527 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex));
529 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length()); 528 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length());
530 EXPECT_EQ(128, sub1.CharAt(0)); 529 EXPECT_EQ(64, sub1.CharAt(0));
531 EXPECT_EQ(192, sub1.CharAt(1)); 530 EXPECT_EQ(92, sub1.CharAt(1));
532 EXPECT_EQ(0, sub1.CharAt(2)); 531 EXPECT_EQ(0, sub1.CharAt(2));
533 EXPECT_EQ(255, sub1.CharAt(3)); 532 EXPECT_EQ(55, sub1.CharAt(3));
534 EXPECT_EQ(255, sub1.CharAt(4)); 533 EXPECT_EQ(55, sub1.CharAt(4));
535 534
536 const intptr_t kWideCharsLen = 7; 535 const intptr_t kWideCharsLen = 7;
537 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; 536 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' };
538 const String& two_str = String::Handle(String::New(wide_chars, 537 const String& two_str = String::Handle(String::New(wide_chars,
539 kWideCharsLen)); 538 kWideCharsLen));
540 EXPECT(two_str.IsInstance()); 539 EXPECT(two_str.IsInstance());
541 EXPECT(two_str.IsString()); 540 EXPECT(two_str.IsString());
542 EXPECT(two_str.IsTwoByteString()); 541 EXPECT(two_str.IsTwoByteString());
543 EXPECT(!two_str.IsOneByteString()); 542 EXPECT(!two_str.IsOneByteString());
544 EXPECT(!two_str.IsFourByteString());
545 EXPECT_EQ(kWideCharsLen, two_str.Length()); 543 EXPECT_EQ(kWideCharsLen, two_str.Length());
546 EXPECT_EQ('H', two_str.CharAt(0)); 544 EXPECT_EQ('H', two_str.CharAt(0));
547 EXPECT_EQ(256, two_str.CharAt(5)); 545 EXPECT_EQ(256, two_str.CharAt(5));
548 const intptr_t kWideCharsIndex = 3; 546 const intptr_t kWideCharsIndex = 3;
549 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); 547 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex));
550 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); 548 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length());
551 EXPECT_EQ('l', sub2.CharAt(0)); 549 EXPECT_EQ('l', sub2.CharAt(0));
552 EXPECT_EQ('o', sub2.CharAt(1)); 550 EXPECT_EQ('o', sub2.CharAt(1));
553 EXPECT_EQ(256, sub2.CharAt(2)); 551 EXPECT_EQ(256, sub2.CharAt(2));
554 EXPECT_EQ('!', sub2.CharAt(3)); 552 EXPECT_EQ('!', sub2.CharAt(3));
555 553
556 { 554 {
557 const String& str1 = String::Handle(String::New("My.create")); 555 const String& str1 = String::Handle(String::New("My.create"));
558 const String& str2 = String::Handle(String::New("My")); 556 const String& str2 = String::Handle(String::New("My"));
559 const String& str3 = String::Handle(String::New("create")); 557 const String& str3 = String::Handle(String::New("create"));
560 EXPECT_EQ(true, str1.StartsWith(str2)); 558 EXPECT_EQ(true, str1.StartsWith(str2));
561 EXPECT_EQ(false, str1.StartsWith(str3)); 559 EXPECT_EQ(false, str1.StartsWith(str3));
562 } 560 }
563 561
564 const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; 562 const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' };
565 const String& four_str = String::Handle(String::New(four_chars, 7)); 563 const String& four_str = String::Handle(String::New(four_chars, 7));
566 EXPECT_EQ(four_str.Hash(), four_str.Hash()); 564 EXPECT_EQ(four_str.Hash(), four_str.Hash());
567 EXPECT(!four_str.IsTwoByteString()); 565 EXPECT(four_str.IsTwoByteString());
568 EXPECT(!four_str.IsOneByteString()); 566 EXPECT(!four_str.IsOneByteString());
569 EXPECT(four_str.IsFourByteString()); 567 EXPECT_EQ(8, four_str.Length());
570 EXPECT_EQ(7, four_str.Length());
571 EXPECT_EQ('C', four_str.CharAt(0)); 568 EXPECT_EQ('C', four_str.CharAt(0));
572 EXPECT_EQ(0xFF, four_str.CharAt(1)); 569 EXPECT_EQ(0xFF, four_str.CharAt(1));
573 EXPECT_EQ('h', four_str.CharAt(2)); 570 EXPECT_EQ('h', four_str.CharAt(2));
574 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); 571 EXPECT_EQ(0xFFFF, four_str.CharAt(3));
575 EXPECT_EQ('a', four_str.CharAt(4)); 572 EXPECT_EQ('a', four_str.CharAt(4));
576 EXPECT_EQ(0x10FFFF, four_str.CharAt(5)); 573 EXPECT_EQ(0xDBFF, four_str.CharAt(5));
577 EXPECT_EQ('r', four_str.CharAt(6)); 574 EXPECT_EQ(0xDFFF, four_str.CharAt(6));
575 EXPECT_EQ('r', four_str.CharAt(7));
578 576
579 // Create a 1-byte string from an array of 2-byte elements. 577 // Create a 1-byte string from an array of 2-byte elements.
580 { 578 {
581 const uint16_t char16[] = { 0x00, 0x7F, 0xFF }; 579 const uint16_t char16[] = { 0x00, 0x1F, 0x7F };
582 const String& str8 = String::Handle(String::New(char16, 3)); 580 const String& str8 = String::Handle(String::New(char16, 3));
583 EXPECT(str8.IsOneByteString()); 581 EXPECT(str8.IsOneByteString());
584 EXPECT(!str8.IsTwoByteString()); 582 EXPECT(!str8.IsTwoByteString());
585 EXPECT(!str8.IsFourByteString());
586 EXPECT_EQ(0x00, str8.CharAt(0)); 583 EXPECT_EQ(0x00, str8.CharAt(0));
587 EXPECT_EQ(0x7F, str8.CharAt(1)); 584 EXPECT_EQ(0x1F, str8.CharAt(1));
588 EXPECT_EQ(0xFF, str8.CharAt(2)); 585 EXPECT_EQ(0x7F, str8.CharAt(2));
589 } 586 }
590 587
591 // Create a 1-byte string from an array of 4-byte elements. 588 // Create a 1-byte string from an array of 4-byte elements.
592 { 589 {
593 const uint32_t char32[] = { 0x00, 0x7F, 0xFF }; 590 const uint32_t char32[] = { 0x00, 0x1F, 0x7F };
594 const String& str8 = String::Handle(String::New(char32, 3)); 591 const String& str8 = String::Handle(String::New(char32, 3));
595 EXPECT(str8.IsOneByteString()); 592 EXPECT(str8.IsOneByteString());
596 EXPECT(!str8.IsTwoByteString()); 593 EXPECT(!str8.IsTwoByteString());
597 EXPECT(!str8.IsFourByteString());
598 EXPECT_EQ(0x00, str8.CharAt(0)); 594 EXPECT_EQ(0x00, str8.CharAt(0));
599 EXPECT_EQ(0x7F, str8.CharAt(1)); 595 EXPECT_EQ(0x1F, str8.CharAt(1));
600 EXPECT_EQ(0xFF, str8.CharAt(2)); 596 EXPECT_EQ(0x7F, str8.CharAt(2));
601 } 597 }
602 598
603 // Create a 2-byte string from an array of 4-byte elements. 599 // Create a 2-byte string from an array of 4-byte elements.
604 { 600 {
605 const uint32_t char32[] = { 0, 0x7FFF, 0xFFFF }; 601 const uint32_t char32[] = { 0, 0x7FFF, 0xFFFF };
606 const String& str16 = String::Handle(String::New(char32, 3)); 602 const String& str16 = String::Handle(String::New(char32, 3));
607 EXPECT(!str16.IsOneByteString()); 603 EXPECT(!str16.IsOneByteString());
608 EXPECT(str16.IsTwoByteString()); 604 EXPECT(str16.IsTwoByteString());
609 EXPECT(!str16.IsFourByteString());
610 EXPECT_EQ(0x0000, str16.CharAt(0)); 605 EXPECT_EQ(0x0000, str16.CharAt(0));
611 EXPECT_EQ(0x7FFF, str16.CharAt(1)); 606 EXPECT_EQ(0x7FFF, str16.CharAt(1));
612 EXPECT_EQ(0xFFFF, str16.CharAt(2)); 607 EXPECT_EQ(0xFFFF, str16.CharAt(2));
613 } 608 }
614 } 609 }
615 610
616 611
617 TEST_CASE(StringFormat) { 612 TEST_CASE(StringFormat) {
618 const char* hello_str = "Hello World!"; 613 const char* hello_str = "Hello World!";
619 const String& str = 614 const String& str =
620 String::Handle(String::NewFormatted("Hello %s!", "World")); 615 String::Handle(String::NewFormatted("Hello %s!", "World"));
621 EXPECT(str.IsInstance()); 616 EXPECT(str.IsInstance());
622 EXPECT(str.IsString()); 617 EXPECT(str.IsString());
623 EXPECT(str.IsOneByteString()); 618 EXPECT(str.IsOneByteString());
624 EXPECT(!str.IsTwoByteString()); 619 EXPECT(!str.IsTwoByteString());
625 EXPECT(!str.IsFourByteString());
626 EXPECT(!str.IsNumber()); 620 EXPECT(!str.IsNumber());
627 EXPECT(str.Equals(hello_str)); 621 EXPECT(str.Equals(hello_str));
628 } 622 }
629 623
630 624
631 TEST_CASE(StringConcat) { 625 TEST_CASE(StringConcat) {
632 // Create strings from concatenated 1-byte empty strings. 626 // Create strings from concatenated 1-byte empty strings.
633 { 627 {
634 const String& empty1 = String::Handle(String::New("")); 628 const String& empty1 = String::Handle(String::New(""));
635 EXPECT(empty1.IsOneByteString()); 629 EXPECT(empty1.IsOneByteString());
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 const String& str6 = String::Handle(String::ConcatAll(array4)); 930 const String& str6 = String::Handle(String::ConcatAll(array4));
937 EXPECT(str6.IsTwoByteString()); 931 EXPECT(str6.IsTwoByteString());
938 const uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 932 const uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
939 0x05D0, 0x05D9, 0x05D9, 0x05DF, 933 0x05D0, 0x05D9, 0x05D9, 0x05DF,
940 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; 934 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
941 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); 935 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]);
942 EXPECT_EQ(two_one_two_len, str6.Length()); 936 EXPECT_EQ(two_one_two_len, str6.Length());
943 EXPECT(str6.Equals(two_one_two, two_one_two_len)); 937 EXPECT(str6.Equals(two_one_two, two_one_two_len));
944 } 938 }
945 939
946 // Concatenated emtpy and non-empty 4-byte strings. 940 // Concatenated emtpy and non-empty strings built from 4-byte elements.
947 { 941 {
948 const String& str1 = String::Handle(String::New("")); 942 const String& str1 = String::Handle(String::New(""));
949 EXPECT(str1.IsOneByteString()); 943 EXPECT(str1.IsOneByteString());
950 EXPECT_EQ(0, str1.Length()); 944 EXPECT_EQ(0, str1.Length());
951 945
952 uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; 946 uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
953 intptr_t four_len = sizeof(four) / sizeof(four[0]); 947 intptr_t four_len = sizeof(four) / sizeof(four[0]);
948 intptr_t expected_len = (four_len * 2);
954 const String& str2 = String::Handle(String::New(four, four_len)); 949 const String& str2 = String::Handle(String::New(four, four_len));
955 EXPECT(str2.IsFourByteString()); 950 EXPECT(str2.IsTwoByteString());
956 EXPECT_EQ(4, str2.Length()); 951 EXPECT_EQ(expected_len, str2.Length());
957 952
958 // Concat 953 // Concat
959 954
960 const String& str3 = String::Handle(String::Concat(str1, str2)); 955 const String& str3 = String::Handle(String::Concat(str1, str2));
961 EXPECT_EQ(four_len, str3.Length()); 956 EXPECT_EQ(expected_len, str3.Length());
962 EXPECT(str3.Equals(str2)); 957 EXPECT(str3.Equals(str2));
963 958
964 const String& str4 = String::Handle(String::Concat(str2, str1)); 959 const String& str4 = String::Handle(String::Concat(str2, str1));
965 EXPECT(str4.IsFourByteString()); 960 EXPECT(str4.IsTwoByteString());
966 EXPECT_EQ(four_len, str4.Length()); 961 EXPECT_EQ(expected_len, str4.Length());
967 EXPECT(str4.Equals(str2)); 962 EXPECT(str4.Equals(str2));
968 963
969 // ConcatAll 964 // ConcatAll
970 965
971 const Array& array1 = Array::Handle(Array::New(2)); 966 const Array& array1 = Array::Handle(Array::New(2));
972 EXPECT_EQ(2, array1.Length()); 967 EXPECT_EQ(2, array1.Length());
973 array1.SetAt(0, str1); 968 array1.SetAt(0, str1);
974 array1.SetAt(1, str2); 969 array1.SetAt(1, str2);
975 const String& str5 = String::Handle(String::ConcatAll(array1)); 970 const String& str5 = String::Handle(String::ConcatAll(array1));
976 EXPECT(str5.IsFourByteString()); 971 EXPECT(str5.IsTwoByteString());
977 EXPECT_EQ(four_len, str5.Length()); 972 EXPECT_EQ(expected_len, str5.Length());
978 EXPECT(str5.Equals(str2)); 973 EXPECT(str5.Equals(str2));
979 974
980 const Array& array2 = Array::Handle(Array::New(2)); 975 const Array& array2 = Array::Handle(Array::New(2));
981 EXPECT_EQ(2, array2.Length()); 976 EXPECT_EQ(2, array2.Length());
982 array2.SetAt(0, str1); 977 array2.SetAt(0, str1);
983 array2.SetAt(1, str2); 978 array2.SetAt(1, str2);
984 const String& str6 = String::Handle(String::ConcatAll(array2)); 979 const String& str6 = String::Handle(String::ConcatAll(array2));
985 EXPECT(str6.IsFourByteString()); 980 EXPECT(str6.IsTwoByteString());
986 EXPECT_EQ(four_len, str6.Length()); 981 EXPECT_EQ(expected_len, str6.Length());
987 EXPECT(str6.Equals(str2)); 982 EXPECT(str6.Equals(str2));
988 983
989 const Array& array3 = Array::Handle(Array::New(3)); 984 const Array& array3 = Array::Handle(Array::New(3));
990 EXPECT_EQ(3, array3.Length()); 985 EXPECT_EQ(3, array3.Length());
991 array3.SetAt(0, str2); 986 array3.SetAt(0, str2);
992 array3.SetAt(1, str1); 987 array3.SetAt(1, str1);
993 array3.SetAt(2, str2); 988 array3.SetAt(2, str2);
994 const String& str7 = String::Handle(String::ConcatAll(array3)); 989 const String& str7 = String::Handle(String::ConcatAll(array3));
995 EXPECT(str7.IsFourByteString()); 990 EXPECT(str7.IsTwoByteString());
996 uint32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, 991 uint32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
997 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; 992 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
998 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]); 993 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]);
999 EXPECT_EQ(fourfour_len, str7.Length()); 994 EXPECT_EQ((fourfour_len * 2), str7.Length());
1000 EXPECT(str7.Equals(fourfour, fourfour_len)); 995 const String& fourfour_str =
996 String::Handle(String::New(fourfour, fourfour_len));
997 EXPECT(str7.Equals(fourfour_str));
1001 } 998 }
1002 999
1003 // Concatenate non-empty 4-byte strings. 1000 // Concatenate non-empty strings built from 4-byte elements.
1004 { 1001 {
1005 const uint32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF }; 1002 const uint32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF };
1006 intptr_t one_len = sizeof(one) / sizeof(one[0]); 1003 intptr_t one_len = sizeof(one) / sizeof(one[0]);
1007 const String& onestr = String::Handle(String::New(one, one_len)); 1004 const String& onestr = String::Handle(String::New(one, one_len));
1008 EXPECT(onestr.IsFourByteString()); 1005 EXPECT(onestr.IsTwoByteString());
1009 EXPECT_EQ(one_len, onestr.Length()); 1006 EXPECT_EQ((one_len *2), onestr.Length());
1010 1007
1011 const uint32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; 1008 const uint32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 };
1012 intptr_t two_len = sizeof(two) / sizeof(two[0]); 1009 intptr_t two_len = sizeof(two) / sizeof(two[0]);
1013 const String& twostr = String::Handle(String::New(two, two_len)); 1010 const String& twostr = String::Handle(String::New(two, two_len));
1014 EXPECT(twostr.IsFourByteString()); 1011 EXPECT(twostr.IsTwoByteString());
1015 EXPECT_EQ(two_len, twostr.Length()); 1012 EXPECT_EQ((two_len * 2), twostr.Length());
1016 1013
1017 // Concat 1014 // Concat
1018 1015
1019 const String& str1 = String::Handle(String::Concat(onestr, twostr)); 1016 const String& str1 = String::Handle(String::Concat(onestr, twostr));
1020 EXPECT(str1.IsFourByteString()); 1017 EXPECT(str1.IsTwoByteString());
1021 const uint32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, 1018 const uint32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF,
1022 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; 1019 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 };
1023 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); 1020 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]);
1024 EXPECT_EQ(one_two_len, str1.Length()); 1021 EXPECT_EQ((one_two_len * 2), str1.Length());
1025 EXPECT(str1.Equals(one_two, one_two_len)); 1022 const String& one_two_str =
1023 String::Handle(String::New(one_two, one_two_len));
1024 EXPECT(str1.Equals(one_two_str));
1026 1025
1027 const String& str2 = String::Handle(String::Concat(twostr, onestr)); 1026 const String& str2 = String::Handle(String::Concat(twostr, onestr));
1028 EXPECT(str2.IsFourByteString()); 1027 EXPECT(str2.IsTwoByteString());
1029 const uint32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, 1028 const uint32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9,
1030 0x105D0, 0x105D9, 0x105D9, 0x105DF }; 1029 0x105D0, 0x105D9, 0x105D9, 0x105DF };
1031 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); 1030 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]);
1032 EXPECT_EQ(two_one_len, str2.Length()); 1031 EXPECT_EQ((two_one_len * 2), str2.Length());
1033 EXPECT(str2.Equals(two_one, two_one_len)); 1032 const String& two_one_str =
1033 String::Handle(String::New(two_one, two_one_len));
1034 EXPECT(str2.Equals(two_one_str));
1034 1035
1035 // ConcatAll 1036 // ConcatAll
1036 1037
1037 const Array& array1 = Array::Handle(Array::New(2)); 1038 const Array& array1 = Array::Handle(Array::New(2));
1038 EXPECT_EQ(2, array1.Length()); 1039 EXPECT_EQ(2, array1.Length());
1039 array1.SetAt(0, onestr); 1040 array1.SetAt(0, onestr);
1040 array1.SetAt(1, twostr); 1041 array1.SetAt(1, twostr);
1041 const String& str3 = String::Handle(String::ConcatAll(array1)); 1042 const String& str3 = String::Handle(String::ConcatAll(array1));
1042 EXPECT(str3.IsFourByteString()); 1043 EXPECT(str3.IsTwoByteString());
1043 EXPECT_EQ(one_two_len, str3.Length()); 1044 EXPECT_EQ((one_two_len * 2), str3.Length());
1044 EXPECT(str3.Equals(one_two, one_two_len)); 1045 EXPECT(str3.Equals(one_two_str));
1045 1046
1046 const Array& array2 = Array::Handle(Array::New(2)); 1047 const Array& array2 = Array::Handle(Array::New(2));
1047 EXPECT_EQ(2, array2.Length()); 1048 EXPECT_EQ(2, array2.Length());
1048 array2.SetAt(0, twostr); 1049 array2.SetAt(0, twostr);
1049 array2.SetAt(1, onestr); 1050 array2.SetAt(1, onestr);
1050 const String& str4 = String::Handle(String::ConcatAll(array2)); 1051 const String& str4 = String::Handle(String::ConcatAll(array2));
1051 EXPECT(str4.IsFourByteString()); 1052 EXPECT(str4.IsTwoByteString());
1052 EXPECT_EQ(two_one_len, str4.Length()); 1053 EXPECT_EQ((two_one_len * 2), str4.Length());
1053 EXPECT(str4.Equals(two_one, two_one_len)); 1054 EXPECT(str4.Equals(two_one_str));
1054 1055
1055 const Array& array3 = Array::Handle(Array::New(3)); 1056 const Array& array3 = Array::Handle(Array::New(3));
1056 EXPECT_EQ(3, array3.Length()); 1057 EXPECT_EQ(3, array3.Length());
1057 array3.SetAt(0, onestr); 1058 array3.SetAt(0, onestr);
1058 array3.SetAt(1, twostr); 1059 array3.SetAt(1, twostr);
1059 array3.SetAt(2, onestr); 1060 array3.SetAt(2, onestr);
1060 const String& str5 = String::Handle(String::ConcatAll(array3)); 1061 const String& str5 = String::Handle(String::ConcatAll(array3));
1061 EXPECT(str5.IsFourByteString()); 1062 EXPECT(str5.IsTwoByteString());
1062 const uint32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, 1063 const uint32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF,
1063 0x105E6, 0x105D5, 0x105D5, 0x105D9, 1064 0x105E6, 0x105D5, 0x105D5, 0x105D9,
1064 0x105D9, 1065 0x105D9,
1065 0x105D0, 0x105D9, 0x105D9, 0x105DF }; 1066 0x105D0, 0x105D9, 0x105D9, 0x105DF };
1066 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); 1067 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]);
1067 EXPECT_EQ(one_two_one_len, str5.Length()); 1068 EXPECT_EQ((one_two_one_len * 2), str5.Length());
1068 EXPECT(str5.Equals(one_two_one, one_two_one_len)); 1069 const String& one_two_one_str =
1070 String::Handle(String::New(one_two_one, one_two_one_len));
1071 EXPECT(str5.Equals(one_two_one_str));
1069 1072
1070 const Array& array4 = Array::Handle(Array::New(3)); 1073 const Array& array4 = Array::Handle(Array::New(3));
1071 EXPECT_EQ(3, array4.Length()); 1074 EXPECT_EQ(3, array4.Length());
1072 array4.SetAt(0, twostr); 1075 array4.SetAt(0, twostr);
1073 array4.SetAt(1, onestr); 1076 array4.SetAt(1, onestr);
1074 array4.SetAt(2, twostr); 1077 array4.SetAt(2, twostr);
1075 const String& str6 = String::Handle(String::ConcatAll(array4)); 1078 const String& str6 = String::Handle(String::ConcatAll(array4));
1076 EXPECT(str6.IsFourByteString()); 1079 EXPECT(str6.IsTwoByteString());
1077 const uint32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 1080 const uint32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9,
1078 0x105D9, 1081 0x105D9,
1079 0x105D0, 0x105D9, 0x105D9, 0x105DF, 1082 0x105D0, 0x105D9, 0x105D9, 0x105DF,
1080 0x105E6, 0x105D5, 0x105D5, 0x105D9, 1083 0x105E6, 0x105D5, 0x105D5, 0x105D9,
1081 0x105D9 }; 1084 0x105D9 };
1082 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); 1085 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]);
1083 EXPECT_EQ(two_one_two_len, str6.Length()); 1086 EXPECT_EQ((two_one_two_len * 2), str6.Length());
1084 EXPECT(str6.Equals(two_one_two, two_one_two_len)); 1087 const String& two_one_two_str =
1088 String::Handle(String::New(two_one_two, two_one_two_len));
1089 EXPECT(str6.Equals(two_one_two_str));
1085 } 1090 }
1086 1091
1087 // Concatenate 1-byte strings and 2-byte strings. 1092 // Concatenate 1-byte strings and 2-byte strings.
1088 { 1093 {
1089 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; 1094 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
1090 intptr_t one_len = sizeof(one) / sizeof(one[0]); 1095 intptr_t one_len = sizeof(one) / sizeof(one[0]);
1091 const String& onestr = String::Handle(String::New(one, one_len)); 1096 const String& onestr = String::Handle(String::New(one, one_len));
1092 EXPECT(onestr.IsOneByteString()); 1097 EXPECT(onestr.IsOneByteString());
1093 EXPECT_EQ(one_len, onestr.Length()); 1098 EXPECT_EQ(one_len, onestr.Length());
1094 EXPECT(onestr.Equals(one, one_len)); 1099 EXPECT(onestr.Equals(one, one_len));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 array2.SetAt(2, twostr); 1146 array2.SetAt(2, twostr);
1142 const String& two_one_two_str = String::Handle(String::ConcatAll(array2)); 1147 const String& two_one_two_str = String::Handle(String::ConcatAll(array2));
1143 EXPECT(two_one_two_str.IsTwoByteString()); 1148 EXPECT(two_one_two_str.IsTwoByteString());
1144 EXPECT_EQ(twostr.Length()*2 + onestr.Length(), two_one_two_str.Length()); 1149 EXPECT_EQ(twostr.Length()*2 + onestr.Length(), two_one_two_str.Length());
1145 uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9, 1150 uint16_t two_one_two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
1146 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e', 1151 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
1147 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 }; 1152 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1148 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); 1153 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]);
1149 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len)); 1154 EXPECT(two_one_two_str.Equals(two_one_two, two_one_two_len));
1150 } 1155 }
1151
1152 // Concatenate 1-byte strings and 4-byte strings.
1153 {
1154 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
1155 intptr_t one_len = sizeof(one) / sizeof(one[0]);
1156 const String& onestr = String::Handle(String::New(one, one_len));
1157 EXPECT(onestr.IsOneByteString());
1158 EXPECT_EQ(one_len, onestr.Length());
1159 EXPECT(onestr.Equals(one, one_len));
1160
1161 uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
1162 intptr_t four_len = sizeof(four) / sizeof(four[0]);
1163 const String& fourstr = String::Handle(String::New(four, four_len));
1164 EXPECT(fourstr.IsFourByteString());
1165 EXPECT_EQ(four_len, fourstr.Length());
1166 EXPECT(fourstr.Equals(four, four_len));
1167
1168 // Concat
1169
1170 const String& one_four_str = String::Handle(String::Concat(onestr,
1171 fourstr));
1172 EXPECT(one_four_str.IsFourByteString());
1173 uint32_t one_four[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
1174 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
1175 intptr_t one_four_len = sizeof(one_four) / sizeof(one_four[0]);
1176 EXPECT_EQ(one_four_len, one_four_str.Length());
1177 EXPECT(one_four_str.Equals(one_four, one_four_len));
1178
1179 const String& four_one_str = String::Handle(String::Concat(fourstr,
1180 onestr));
1181 EXPECT(four_one_str.IsFourByteString());
1182 uint32_t four_one[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
1183 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
1184 intptr_t four_one_len = sizeof(four_one) / sizeof(four_one[0]);
1185 EXPECT_EQ(four_one_len, four_one_str.Length());
1186 EXPECT(four_one_str.Equals(four_one, four_one_len));
1187
1188 // ConcatAll
1189
1190 const Array& array1 = Array::Handle(Array::New(3));
1191 EXPECT_EQ(3, array1.Length());
1192 array1.SetAt(0, onestr);
1193 array1.SetAt(1, fourstr);
1194 array1.SetAt(2, onestr);
1195 const String& one_four_one = String::Handle(String::ConcatAll(array1));
1196 EXPECT(one_four_one.IsFourByteString());
1197 EXPECT_EQ(onestr.Length()*2 + fourstr.Length(), one_four_one.Length());
1198
1199 const Array& array2 = Array::Handle(Array::New(3));
1200 EXPECT_EQ(3, array2.Length());
1201 array2.SetAt(0, fourstr);
1202 array2.SetAt(1, onestr);
1203 array2.SetAt(2, fourstr);
1204 const String& four_one_four = String::Handle(String::ConcatAll(array2));
1205 EXPECT(four_one_four.IsFourByteString());
1206 EXPECT_EQ(fourstr.Length()*2 + onestr.Length(), four_one_four.Length());
1207 }
1208
1209 // Concatenate 2-byte strings and 4-byte strings.
1210 {
1211 uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1212 intptr_t two_len = sizeof(two) / sizeof(two[0]);
1213 const String& twostr = String::Handle(String::New(two, two_len));
1214 EXPECT(twostr.IsTwoByteString());
1215 EXPECT_EQ(two_len, twostr.Length());
1216 EXPECT(twostr.Equals(two, two_len));
1217
1218 uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
1219 intptr_t four_len = sizeof(four) / sizeof(four[0]);
1220 const String& fourstr = String::Handle(String::New(four, four_len));
1221 EXPECT(fourstr.IsFourByteString());
1222 EXPECT_EQ(four_len, fourstr.Length());
1223 EXPECT(fourstr.Equals(four, four_len));
1224
1225 // Concat
1226
1227 const String& two_four_str = String::Handle(String::Concat(twostr,
1228 fourstr));
1229 EXPECT(two_four_str.IsFourByteString());
1230 uint32_t two_four[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
1231 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
1232 intptr_t two_four_len = sizeof(two_four) / sizeof(two_four[0]);
1233 EXPECT_EQ(two_four_len, two_four_str.Length());
1234 EXPECT(two_four_str.Equals(two_four, two_four_len));
1235
1236 const String& four_two_str = String::Handle(String::Concat(fourstr,
1237 twostr));
1238 EXPECT(four_two_str.IsFourByteString());
1239 uint32_t four_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
1240 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1241 intptr_t four_two_len = sizeof(four_two) / sizeof(four_two[0]);
1242 EXPECT_EQ(four_two_len, four_two_str.Length());
1243 EXPECT(four_two_str.Equals(four_two, four_two_len));
1244
1245 // ConcatAll
1246
1247 const Array& array1 = Array::Handle(Array::New(3));
1248 EXPECT_EQ(3, array1.Length());
1249 array1.SetAt(0, twostr);
1250 array1.SetAt(1, fourstr);
1251 array1.SetAt(2, twostr);
1252 const String& two_four_two_str = String::Handle(String::ConcatAll(array1));
1253 EXPECT(two_four_two_str.IsFourByteString());
1254 EXPECT_EQ(twostr.Length()*2 + fourstr.Length(), two_four_two_str.Length());
1255
1256 const Array& array2 = Array::Handle(Array::New(3));
1257 EXPECT_EQ(3, array2.Length());
1258 array2.SetAt(0, fourstr);
1259 array2.SetAt(1, twostr);
1260 array2.SetAt(2, fourstr);
1261 const String& four_two_four_str = String::Handle(String::ConcatAll(array2));
1262 EXPECT(four_two_four_str.IsFourByteString());
1263 EXPECT_EQ(fourstr.Length()*2 + twostr.Length(), four_two_four_str.Length());
1264 }
1265
1266 // Concatenate 1-byte, 2-byte and 4-byte strings.
1267 {
1268 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' };
1269 intptr_t one_len = sizeof(one) / sizeof(one[0]);
1270 const String& onestr = String::Handle(String::New(one, one_len));
1271 EXPECT(onestr.IsOneByteString());
1272 EXPECT_EQ(one_len, onestr.Length());
1273 EXPECT(onestr.Equals(one, one_len));
1274
1275 uint16_t two[] = { 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1276 intptr_t two_len = sizeof(two) / sizeof(two[0]);
1277 const String& twostr = String::Handle(String::New(two, two_len));
1278 EXPECT(twostr.IsTwoByteString());
1279 EXPECT_EQ(two_len, twostr.Length());
1280 EXPECT(twostr.Equals(two, two_len));
1281
1282 uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
1283 intptr_t four_len = sizeof(four) / sizeof(four[0]);
1284 const String& fourstr = String::Handle(String::New(four, four_len));
1285 EXPECT(fourstr.IsFourByteString());
1286 EXPECT_EQ(four_len, fourstr.Length());
1287 EXPECT(fourstr.Equals(four, four_len));
1288
1289 // Last element is a 4-byte string.
1290 const Array& array1 = Array::Handle(Array::New(3));
1291 EXPECT_EQ(3, array1.Length());
1292 array1.SetAt(0, onestr);
1293 array1.SetAt(1, twostr);
1294 array1.SetAt(2, fourstr);
1295 const String& one_two_four_str = String::Handle(String::ConcatAll(array1));
1296 EXPECT(one_two_four_str.IsFourByteString());
1297 EXPECT_EQ(onestr.Length() + twostr.Length() + fourstr.Length(),
1298 one_two_four_str.Length());
1299 uint32_t one_two_four[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
1300 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9,
1301 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 };
1302 intptr_t one_two_four_len = sizeof(one_two_four) / sizeof(one_two_four[0]);
1303 EXPECT(one_two_four_str.Equals(one_two_four, one_two_four_len));
1304
1305 // Middle element is a 4-byte string.
1306 const Array& array2 = Array::Handle(Array::New(3));
1307 EXPECT_EQ(3, array2.Length());
1308 array2.SetAt(0, onestr);
1309 array2.SetAt(1, fourstr);
1310 array2.SetAt(2, twostr);
1311 const String& one_four_two_str = String::Handle(String::ConcatAll(array2));
1312 EXPECT(one_four_two_str.IsFourByteString());
1313 EXPECT_EQ(onestr.Length() + fourstr.Length() + twostr.Length(),
1314 one_four_two_str.Length());
1315 uint32_t one_four_two[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
1316 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
1317 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1318 intptr_t one_four_two_len = sizeof(one_four_two) / sizeof(one_four_two[0]);
1319 EXPECT(one_four_two_str.Equals(one_four_two, one_four_two_len));
1320
1321 // First element is a 4-byte string.
1322 const Array& array3 = Array::Handle(Array::New(3));
1323 EXPECT_EQ(3, array3.Length());
1324 array3.SetAt(0, fourstr);
1325 array3.SetAt(1, onestr);
1326 array3.SetAt(2, twostr);
1327 const String& four_one_two_str = String::Handle(String::ConcatAll(array3));
1328 EXPECT(one_four_two_str.IsFourByteString());
1329 EXPECT_EQ(onestr.Length() + fourstr.Length() + twostr.Length(),
1330 one_four_two_str.Length());
1331 uint32_t four_one_two[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1,
1332 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e',
1333 0x05E6, 0x05D5, 0x05D5, 0x05D9, 0x05D9 };
1334 intptr_t four_one_two_len = sizeof(four_one_two) / sizeof(four_one_two[0]);
1335 EXPECT(four_one_two_str.Equals(four_one_two, four_one_two_len));
1336 }
1337 } 1156 }
1338 1157
1339 1158
1340 TEST_CASE(StringSubStringDifferentWidth) { 1159 TEST_CASE(StringSubStringDifferentWidth) {
1341 // Create 1-byte substring from a 1-byte source string. 1160 // Create 1-byte substring from a 1-byte source string.
1342 const char* onechars = 1161 const char* onechars =
1343 "\xC3\xB6\xC3\xB1\xC3\xA9"; 1162 "\xC3\xB6\xC3\xB1\xC3\xA9";
1344 1163
1345 const String& onestr = String::Handle(String::New(onechars)); 1164 const String& onestr = String::Handle(String::New(onechars));
1346 EXPECT(!onestr.IsNull()); 1165 EXPECT(!onestr.IsNull());
1347 EXPECT(onestr.IsOneByteString()); 1166 EXPECT(!onestr.IsOneByteString());
1167 EXPECT(onestr.IsTwoByteString());
1348 1168
1349 const String& onesub = String::Handle(String::SubString(onestr, 0)); 1169 const String& onesub = String::Handle(String::SubString(onestr, 0));
1350 EXPECT(!onesub.IsNull()); 1170 EXPECT(!onesub.IsNull());
1351 EXPECT(onestr.IsOneByteString()); 1171 EXPECT(!onestr.IsOneByteString());
1172 EXPECT(onestr.IsTwoByteString());
1352 EXPECT_EQ(onesub.Length(), 3); 1173 EXPECT_EQ(onesub.Length(), 3);
1353 1174
1354 // Create 1- and 2-byte substrings from a 2-byte source string. 1175 // Create 1- and 2-byte substrings from a 2-byte source string.
1355 const char* twochars = 1176 const char* twochars =
1356 "\xC3\xB6\xC3\xB1\xC3\xA9" 1177 "\x1f\x2f\x3f"
1357 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"; 1178 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93";
1358 1179
1359 const String& twostr = String::Handle(String::New(twochars)); 1180 const String& twostr = String::Handle(String::New(twochars));
1360 EXPECT(!twostr.IsNull()); 1181 EXPECT(!twostr.IsNull());
1361 EXPECT(twostr.IsTwoByteString()); 1182 EXPECT(twostr.IsTwoByteString());
1362 1183
1363 const String& twosub1 = String::Handle(String::SubString(twostr, 0, 3)); 1184 const String& twosub1 = String::Handle(String::SubString(twostr, 0, 3));
1364 EXPECT(!twosub1.IsNull()); 1185 EXPECT(!twosub1.IsNull());
1365 EXPECT(twosub1.IsOneByteString()); 1186 EXPECT(twosub1.IsOneByteString());
1366 EXPECT_EQ(twosub1.Length(), 3); 1187 EXPECT_EQ(twosub1.Length(), 3);
1367 1188
1368 const String& twosub2 = String::Handle(String::SubString(twostr, 3)); 1189 const String& twosub2 = String::Handle(String::SubString(twostr, 3));
1369 EXPECT(!twosub2.IsNull()); 1190 EXPECT(!twosub2.IsNull());
1370 EXPECT(twosub2.IsTwoByteString()); 1191 EXPECT(twosub2.IsTwoByteString());
1371 EXPECT_EQ(twosub2.Length(), 3); 1192 EXPECT_EQ(twosub2.Length(), 3);
1372 1193
1373 // Create 1-, 2-, and 4-byte substrings from a 4-byte source string. 1194 // Create substrings from a string built using 1-, 2- and 4-byte elements.
1374 const char* fourchars = 1195 const char* fourchars =
1375 "\xC3\xB6\xC3\xB1\xC3\xA9" 1196 "\x1f\x2f\x3f"
1376 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93" 1197 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"
1377 "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"; 1198 "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B";
1378 1199
1379 const String& fourstr = String::Handle(String::New(fourchars)); 1200 const String& fourstr = String::Handle(String::New(fourchars));
1380 EXPECT(!fourstr.IsNull()); 1201 EXPECT(!fourstr.IsNull());
1381 EXPECT(fourstr.IsFourByteString()); 1202 EXPECT(fourstr.IsTwoByteString());
1382 1203
1383 const String& foursub1 = String::Handle(String::SubString(fourstr, 0, 3)); 1204 const String& foursub1 = String::Handle(String::SubString(fourstr, 0, 3));
1384 EXPECT(!foursub1.IsNull()); 1205 EXPECT(!foursub1.IsNull());
1385 EXPECT(foursub1.IsOneByteString()); 1206 EXPECT(foursub1.IsOneByteString());
1386 EXPECT_EQ(foursub1.Length(), 3); 1207 EXPECT_EQ(foursub1.Length(), 3);
1387 1208
1388 const String& foursub2 = String::Handle(String::SubString(fourstr, 3, 3)); 1209 const String& foursub2 = String::Handle(String::SubString(fourstr, 3, 3));
1389 EXPECT(!foursub2.IsNull()); 1210 EXPECT(!foursub2.IsNull());
1390 EXPECT(foursub2.IsTwoByteString()); 1211 EXPECT(foursub2.IsTwoByteString());
1391 EXPECT_EQ(foursub2.Length(), 3); 1212 EXPECT_EQ(foursub2.Length(), 3);
1392 1213
1393 const String& foursub4 = String::Handle(String::SubString(fourstr, 6)); 1214 const String& foursub4 = String::Handle(String::SubString(fourstr, 6));
1394 EXPECT_EQ(foursub4.Length(), 4); 1215 EXPECT_EQ(foursub4.Length(), 8);
1395 EXPECT(!foursub4.IsNull()); 1216 EXPECT(!foursub4.IsNull());
1396 EXPECT(foursub4.IsFourByteString()); 1217 EXPECT(foursub4.IsTwoByteString());
1397 } 1218 }
1398 1219
1399 1220
1400 TEST_CASE(StringFromUtf8Literal) { 1221 TEST_CASE(StringFromUtf8Literal) {
1401 // Create a 1-byte string from a UTF-8 encoded string literal. 1222 // Create a 1-byte string from a UTF-8 encoded string literal.
1402 { 1223 {
1403 const char* src = 1224 const char* src =
1404 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3" 1225 "\xC2\xA0\xC2\xA1\xC2\xA2\xC2\xA3"
1405 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7" 1226 "\xC2\xA4\xC2\xA5\xC2\xA6\xC2\xA7"
1406 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB" 1227 "\xC2\xA8\xC2\xA9\xC2\xAA\xC2\xAB"
(...skipping 26 matching lines...) Expand all
1433 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 1254 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
1434 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 1255 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
1435 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 1256 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
1436 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 1257 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
1437 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 1258 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
1438 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 1259 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
1439 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 1260 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
1440 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 1261 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
1441 }; 1262 };
1442 const String& str = String::Handle(String::New(src)); 1263 const String& str = String::Handle(String::New(src));
1443 EXPECT(str.IsOneByteString()); 1264 EXPECT(str.IsTwoByteString());
1444 intptr_t expected_length = sizeof(expected); 1265 intptr_t expected_length = sizeof(expected);
1445 EXPECT_EQ(expected_length, str.Length()); 1266 EXPECT_EQ(expected_length, str.Length());
1446 for (int i = 0; i < str.Length(); ++i) { 1267 for (int i = 0; i < str.Length(); ++i) {
1447 EXPECT_EQ(expected[i], str.CharAt(i)); 1268 EXPECT_EQ(expected[i], str.CharAt(i));
1448 } 1269 }
1449 } 1270 }
1450 1271
1451 // Create a 2-byte string from a UTF-8 encoded string literal. 1272 // Create a 2-byte string from a UTF-8 encoded string literal.
1452 { 1273 {
1453 const char* src = 1274 const char* src =
1454 "\xD7\x92\xD7\x9C\xD7\xA2\xD7\x93" 1275 "\xD7\x92\xD7\x9C\xD7\xA2\xD7\x93"
1455 "\xD7\x91\xD7\xA8\xD7\x9B\xD7\x94"; 1276 "\xD7\x91\xD7\xA8\xD7\x9B\xD7\x94";
1456 const uint16_t expected[] = { 1277 const uint16_t expected[] = {
1457 0x5D2, 0x5DC, 0x5E2, 0x5D3, 1278 0x5D2, 0x5DC, 0x5E2, 0x5D3,
1458 0x5D1, 0x5E8, 0x5DB, 0x5D4 1279 0x5D1, 0x5E8, 0x5DB, 0x5D4
1459 }; 1280 };
1460 const String& str = String::Handle(String::New(src)); 1281 const String& str = String::Handle(String::New(src));
1461 EXPECT(str.IsTwoByteString()); 1282 EXPECT(str.IsTwoByteString());
1462 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1283 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1463 EXPECT_EQ(expected_size, str.Length()); 1284 EXPECT_EQ(expected_size, str.Length());
1464 for (int i = 0; i < str.Length(); ++i) { 1285 for (int i = 0; i < str.Length(); ++i) {
1465 EXPECT_EQ(expected[i], str.CharAt(i)); 1286 EXPECT_EQ(expected[i], str.CharAt(i));
1466 } 1287 }
1467 } 1288 }
1468 1289
1469 // Create a 2-byte string from UTF-8 encoded 1- and 2-byte 1290 // Create a BMP 2-byte string from UTF-8 encoded 1- and 2-byte
1470 // characters. 1291 // characters.
1471 { 1292 {
1472 const char* src = 1293 const char* src =
1473 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" 1294 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0"
1474 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" 1295 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0"
1475 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" 1296 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80"
1476 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" 1297 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8"
1477 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" 1298 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB"
1478 "\x80\x80\xEC\x80\x80\xED\x80\x80" 1299 "\x80\x80\xEC\x80\x80\xED\x80\x80"
1479 "\xEE\x80\x80\xEF\x80\x80"; 1300 "\xEE\x80\x80\xEF\x80\x80";
1480 const intptr_t expected[] = { 1301 const intptr_t expected[] = {
1481 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, 1302 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0,
1482 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, 1303 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00,
1483 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 1304 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000
1484 }; 1305 };
1485 const String& str = String::Handle(String::New(src)); 1306 const String& str = String::Handle(String::New(src));
1486 EXPECT(str.IsTwoByteString()); 1307 EXPECT(str.IsTwoByteString());
1487 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1308 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1488 EXPECT_EQ(expected_size, str.Length()); 1309 EXPECT_EQ(expected_size, str.Length());
1489 for (int i = 0; i < str.Length(); ++i) { 1310 for (int i = 0; i < str.Length(); ++i) {
1490 EXPECT_EQ(expected[i], str.CharAt(i)); 1311 EXPECT_EQ(expected[i], str.CharAt(i));
1491 } 1312 }
1492 } 1313 }
1493 1314
1494 // Create a 4-byte string from a UTF-8 string literal. 1315 // Create a SMP 2-byte string from a UTF-8 string literal.
1495 { 1316 {
1496 const char* src = 1317 const char* src =
1497 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" 1318 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1"
1498 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; 1319 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3";
1499 const intptr_t expected[] = { 0x1D460, 0x1D461, 0x1D462, 0x1D463 }; 1320 const intptr_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61,
1321 0xd835, 0xdc62, 0xd835, 0xdc63 };
1500 const String& str = String::Handle(String::New(src)); 1322 const String& str = String::Handle(String::New(src));
1501 EXPECT(str.IsFourByteString()); 1323 EXPECT(str.IsTwoByteString());
1502 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1324 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0]));
1503 EXPECT_EQ(expected_size, str.Length()); 1325 EXPECT_EQ(expected_size, str.Length());
1504 for (int i = 0; i < str.Length(); ++i) { 1326 for (int i = 0; i < str.Length(); ++i) {
1505 EXPECT_EQ(expected[i], str.CharAt(i)); 1327 EXPECT_EQ(expected[i], str.CharAt(i));
1506 } 1328 }
1507 } 1329 }
1508 1330
1509 // Create a 4-byte string from UTF-8 encoded 2- and 4-byte 1331 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte
1510 // characters. 1332 // characters.
1511 { 1333 {
1512 const char* src = 1334 const char* src =
1513 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" 1335 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0"
1514 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" 1336 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0"
1515 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" 1337 "\xBC\x80\xEA\x80\x80\xEB\x80\x80"
1516 "\xEC\x80\x80\xED\x80\x80\xEE\x80" 1338 "\xEC\x80\x80\xED\x80\x80\xEE\x80"
1517 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" 1339 "\x80\xEF\x80\x80\xF0\x9A\x80\x80"
1518 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" 1340 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80"
1519 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; 1341 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80";
1520 const intptr_t expected[] = { 1342 const intptr_t expected[] = {
1521 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 1343 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000,
1522 0xD000, 0xE000, 0xF000, 0x1A000, 0x1B000, 0x1D000, 0x1E000, 0x1F000 1344 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00,
1345 0xD838, 0xDC00, 0xD83c, 0xDC00,
1523 }; 1346 };
1524 const String& str = String::Handle(String::New(src)); 1347 const String& str = String::Handle(String::New(src));
1525 EXPECT(str.IsFourByteString()); 1348 EXPECT(str.IsTwoByteString());
1526 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1349 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1527 EXPECT_EQ(expected_size, str.Length()); 1350 EXPECT_EQ(expected_size, str.Length());
1528 for (int i = 0; i < str.Length(); ++i) { 1351 for (int i = 0; i < str.Length(); ++i) {
1529 EXPECT_EQ(expected[i], str.CharAt(i)); 1352 EXPECT_EQ(expected[i], str.CharAt(i));
1530 } 1353 }
1531 } 1354 }
1532 1355
1533 // Create a 4-byte string from UTF-8 encoded 1-, 2- and 4-byte 1356 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte
1534 // characters. 1357 // characters.
1535 { 1358 {
1536 const char* src = 1359 const char* src =
1537 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" 1360 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0"
1538 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" 1361 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0"
1539 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" 1362 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80"
1540 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" 1363 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8"
1541 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" 1364 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB"
1542 "\x80\x80\xEC\x80\x80\xED\x80\x80" 1365 "\x80\x80\xEC\x80\x80\xED\x80\x80"
1543 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" 1366 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A"
1544 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" 1367 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D"
1545 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" 1368 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F"
1546 "\x80\x80"; 1369 "\x80\x80";
1547 const intptr_t expected[] = { 1370 const intptr_t expected[] = {
1548 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, 1371 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0,
1549 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, 1372 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00,
1550 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 1373 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000,
1551 0x1A000, 0x1B000, 0x1D000, 0x1E000, 0x1F000 1374 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00,
1375 0xD83c, 0xDC00,
1552 }; 1376 };
1553 const String& str = String::Handle(String::New(src)); 1377 const String& str = String::Handle(String::New(src));
1554 EXPECT(str.IsFourByteString()); 1378 EXPECT(str.IsTwoByteString());
1555 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); 1379 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]);
1556 EXPECT_EQ(expected_size, str.Length()); 1380 EXPECT_EQ(expected_size, str.Length());
1557 for (int i = 0; i < str.Length(); ++i) { 1381 for (int i = 0; i < str.Length(); ++i) {
1558 EXPECT_EQ(expected[i], str.CharAt(i)); 1382 EXPECT_EQ(expected[i], str.CharAt(i));
1559 } 1383 }
1560 } 1384 }
1561 } 1385 }
1562 1386
1563 1387
1564 TEST_CASE(ExternalOneByteString) { 1388 TEST_CASE(ExternalOneByteString) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93")); 1443 "\xE1\xB9\xAB\xE1\xBA\x85\xE1\xB9\x93"));
1620 1444
1621 const String& substr = String::Handle(String::SubString(str, 1, 1)); 1445 const String& substr = String::Handle(String::SubString(str, 1, 1));
1622 EXPECT(!substr.IsExternalTwoByteString()); 1446 EXPECT(!substr.IsExternalTwoByteString());
1623 EXPECT(substr.IsTwoByteString()); 1447 EXPECT(substr.IsTwoByteString());
1624 EXPECT_EQ(1, substr.Length()); 1448 EXPECT_EQ(1, substr.Length());
1625 EXPECT(substr.Equals("\xE1\xBA\x85")); 1449 EXPECT(substr.Equals("\xE1\xBA\x85"));
1626 } 1450 }
1627 1451
1628 1452
1629 TEST_CASE(ExternalFourByteString) {
1630 uint32_t characters[] = { 0x1D5BF, 0x1D5C8, 0x1D5CE, 0x1D5CB };
1631 intptr_t len = ARRAY_SIZE(characters);
1632
1633 const String& str =
1634 String::Handle(
1635 ExternalFourByteString::New(characters, len, NULL, NULL, Heap::kNew));
1636 EXPECT(!str.IsFourByteString());
1637 EXPECT(str.IsExternalFourByteString());
1638 EXPECT_EQ(str.Length(), len);
1639 EXPECT(str.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1640 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1641
1642 const String& copy = String::Handle(String::SubString(str, 0, len));
1643 EXPECT(!copy.IsExternalFourByteString());
1644 EXPECT(copy.IsFourByteString());
1645 EXPECT_EQ(len, copy.Length());
1646 EXPECT(copy.Equals(str));
1647
1648 const String& concat = String::Handle(String::Concat(str, str));
1649 EXPECT(!concat.IsExternalFourByteString());
1650 EXPECT(concat.IsFourByteString());
1651 EXPECT_EQ(len * 2, concat.Length());
1652 EXPECT(concat.Equals("\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1653 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"
1654 "\xF0\x9D\x96\xBF\xF0\x9D\x97\x88"
1655 "\xF0\x9D\x97\x8E\xF0\x9D\x97\x8B"));
1656
1657 const String& substr = String::Handle(String::SubString(str, 1, 2));
1658 EXPECT(!substr.IsExternalFourByteString());
1659 EXPECT(substr.IsFourByteString());
1660 EXPECT_EQ(2, substr.Length());
1661 EXPECT(substr.Equals("\xF0\x9D\x97\x88\xF0\x9D\x97\x8E"));
1662 }
1663
1664
1665 TEST_CASE(Symbol) { 1453 TEST_CASE(Symbol) {
1666 const String& one = String::Handle(Symbols::New("Eins")); 1454 const String& one = String::Handle(Symbols::New("Eins"));
1667 EXPECT(one.IsSymbol()); 1455 EXPECT(one.IsSymbol());
1668 const String& two = String::Handle(Symbols::New("Zwei")); 1456 const String& two = String::Handle(Symbols::New("Zwei"));
1669 const String& three = String::Handle(Symbols::New("Drei")); 1457 const String& three = String::Handle(Symbols::New("Drei"));
1670 const String& four = String::Handle(Symbols::New("Vier")); 1458 const String& four = String::Handle(Symbols::New("Vier"));
1671 const String& five = String::Handle(Symbols::New("Fuenf")); 1459 const String& five = String::Handle(Symbols::New("Fuenf"));
1672 const String& six = String::Handle(Symbols::New("Sechs")); 1460 const String& six = String::Handle(Symbols::New("Sechs"));
1673 const String& seven = String::Handle(Symbols::New("Sieben")); 1461 const String& seven = String::Handle(Symbols::New("Sieben"));
1674 const String& eight = String::Handle(Symbols::New("Acht")); 1462 const String& eight = String::Handle(Symbols::New("Acht"));
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 " }\n" 2627 " }\n"
2840 " fooHelper();\n" 2628 " fooHelper();\n"
2841 " }\n" 2629 " }\n"
2842 "}\n" 2630 "}\n"
2843 "\n" 2631 "\n"
2844 "main() {\n" 2632 "main() {\n"
2845 " (() => new MyClass())();\n" 2633 " (() => new MyClass())();\n"
2846 "}\n"; 2634 "}\n";
2847 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2635 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2848 EXPECT_VALID(lib); 2636 EXPECT_VALID(lib);
2849 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); 2637 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
2850 EXPECT_ERROR( 2638 EXPECT_ERROR(
2851 result, 2639 result,
2852 "Unhandled exception:\n" 2640 "Unhandled exception:\n"
2853 "MyException\n" 2641 "MyException\n"
2854 "#0 baz (dart:test-lib:2:3)\n" 2642 "#0 baz (dart:test-lib:2:3)\n"
2855 "#1 _OtherClass._OtherClass._named (dart:test-lib:7:8)\n" 2643 "#1 _OtherClass._OtherClass._named (dart:test-lib:7:8)\n"
2856 "#2 globalVar= (dart:test-lib:12:3)\n" 2644 "#2 globalVar= (dart:test-lib:12:3)\n"
2857 "#3 _bar (dart:test-lib:16:3)\n" 2645 "#3 _bar (dart:test-lib:16:3)\n"
2858 "#4 MyClass.field (dart:test-lib:25:9)\n" 2646 "#4 MyClass.field (dart:test-lib:25:9)\n"
2859 "#5 MyClass.foo.fooHelper (dart:test-lib:30:7)\n" 2647 "#5 MyClass.foo.fooHelper (dart:test-lib:30:7)\n"
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
3243 isolate->heap()->CollectAllGarbage(); 3031 isolate->heap()->CollectAllGarbage();
3244 EXPECT(weak1.key() == Object::null()); 3032 EXPECT(weak1.key() == Object::null());
3245 EXPECT(weak1.value() == Object::null()); 3033 EXPECT(weak1.value() == Object::null());
3246 EXPECT(weak2.key() == Object::null()); 3034 EXPECT(weak2.key() == Object::null());
3247 EXPECT(weak2.value() == Object::null()); 3035 EXPECT(weak2.value() == Object::null());
3248 } 3036 }
3249 3037
3250 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 3038 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
3251 3039
3252 } // namespace dart 3040 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698