OLD | NEW |
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 "10000000000000000000")); | 266 "10000000000000000000")); |
267 Bigint& big2 = Bigint::Handle(BigintOperations::NewFromCString( | 267 Bigint& big2 = Bigint::Handle(BigintOperations::NewFromCString( |
268 "-10000000000000000000")); | 268 "-10000000000000000000")); |
269 EXPECT_EQ(-1, a.CompareWith(big1)); | 269 EXPECT_EQ(-1, a.CompareWith(big1)); |
270 EXPECT_EQ(1, a.CompareWith(big2)); | 270 EXPECT_EQ(1, a.CompareWith(big2)); |
271 EXPECT_EQ(-1, c.CompareWith(big1)); | 271 EXPECT_EQ(-1, c.CompareWith(big1)); |
272 EXPECT_EQ(1, c.CompareWith(big2)); | 272 EXPECT_EQ(1, c.CompareWith(big2)); |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 TEST_CASE(StringCompareTo) { | |
277 const String& abcd = String::Handle(String::New("abcd")); | |
278 const String& abce = String::Handle(String::New("abce")); | |
279 EXPECT_EQ(0, abcd.CompareTo(abcd)); | |
280 EXPECT_EQ(0, abce.CompareTo(abce)); | |
281 EXPECT(abcd.CompareTo(abce) < 0); | |
282 EXPECT(abce.CompareTo(abcd) > 0); | |
283 | |
284 const int kMonkeyLen = 4; | |
285 const uint8_t monkey_utf8[kMonkeyLen] = { 0xf0, 0x9f, 0x90, 0xb5 }; | |
286 const String& monkey_face = | |
287 String::Handle(String::New(monkey_utf8, kMonkeyLen)); | |
288 const int kDogLen = 4; | |
289 // 0x1f436 DOG FACE. | |
290 const uint8_t dog_utf8[kDogLen] = { 0xf0, 0x9f, 0x90, 0xb6 }; | |
291 const String& dog_face = String::Handle(String::New(dog_utf8, kDogLen)); | |
292 EXPECT_EQ(0, monkey_face.CompareTo(monkey_face)); | |
293 EXPECT_EQ(0, dog_face.CompareTo(dog_face)); | |
294 EXPECT(monkey_face.CompareTo(dog_face) < 0); | |
295 EXPECT(dog_face.CompareTo(monkey_face) > 0); | |
296 | |
297 const int kDominoLen = 4; | |
298 // 0x1f036 DOMINO TILE HORIZONTAL-00-05. | |
299 const uint8_t domino_utf8[kDominoLen] = { 0xf0, 0x9f, 0x80, 0xb6 }; | |
300 const String& domino = String::Handle(String::New(domino_utf8, kDominoLen)); | |
301 EXPECT_EQ(0, domino.CompareTo(domino)); | |
302 EXPECT(domino.CompareTo(dog_face) < 0); | |
303 EXPECT(domino.CompareTo(monkey_face) < 0); | |
304 EXPECT(dog_face.CompareTo(domino) > 0); | |
305 EXPECT(monkey_face.CompareTo(domino) > 0); | |
306 | |
307 EXPECT(abcd.CompareTo(monkey_face) < 0); | |
308 EXPECT(abce.CompareTo(monkey_face) < 0); | |
309 EXPECT(abcd.CompareTo(domino) < 0); | |
310 EXPECT(abce.CompareTo(domino) < 0); | |
311 EXPECT(domino.CompareTo(abcd) > 0); | |
312 EXPECT(domino.CompareTo(abcd) > 0); | |
313 EXPECT(monkey_face.CompareTo(abce) > 0); | |
314 EXPECT(monkey_face.CompareTo(abce) > 0); | |
315 } | |
316 | |
317 | |
318 TEST_CASE(Mint) { | 276 TEST_CASE(Mint) { |
319 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot | 277 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot |
320 // be allocated if it does fit into a Smi. | 278 // be allocated if it does fit into a Smi. |
321 #if !defined(ARCH_IS_64_BIT) | 279 #if !defined(ARCH_IS_64_BIT) |
322 { Mint& med = Mint::Handle(); | 280 { Mint& med = Mint::Handle(); |
323 EXPECT(med.IsNull()); | 281 EXPECT(med.IsNull()); |
324 int64_t v = DART_2PART_UINT64_C(1, 0); | 282 int64_t v = DART_2PART_UINT64_C(1, 0); |
325 med = Mint::New(v); | 283 med = Mint::New(v); |
326 EXPECT_EQ(v, med.value()); | 284 EXPECT_EQ(v, med.value()); |
327 const String& smi_str = String::Handle(String::New("1")); | 285 const String& smi_str = String::Handle(String::New("1")); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 EXPECT(i.IsSmi()); | 455 EXPECT(i.IsSmi()); |
498 i = Integer::New(String::Handle(String::New("0"))); | 456 i = Integer::New(String::Handle(String::New("0"))); |
499 EXPECT(i.IsSmi()); | 457 EXPECT(i.IsSmi()); |
500 i = Integer::New(String::Handle(String::New("12345678901234567890"))); | 458 i = Integer::New(String::Handle(String::New("12345678901234567890"))); |
501 EXPECT(i.IsBigint()); | 459 EXPECT(i.IsBigint()); |
502 i = Integer::New(String::Handle(String::New("-12345678901234567890111222"))); | 460 i = Integer::New(String::Handle(String::New("-12345678901234567890111222"))); |
503 EXPECT(i.IsBigint()); | 461 EXPECT(i.IsBigint()); |
504 } | 462 } |
505 | 463 |
506 | 464 |
507 static unsigned char ToUChar(char x) { return static_cast<unsigned char>(x); } | |
508 | |
509 | |
510 TEST_CASE(String) { | 465 TEST_CASE(String) { |
511 const char* kHello = "Hello World!"; | 466 const char* kHello = "Hello World!"; |
512 int32_t hello_len = strlen(kHello); | 467 int32_t hello_len = strlen(kHello); |
513 const String& str = String::Handle(String::New(kHello)); | 468 const String& str = String::Handle(String::New(kHello)); |
514 EXPECT(str.IsInstance()); | 469 EXPECT(str.IsInstance()); |
515 EXPECT(str.IsString()); | 470 EXPECT(str.IsString()); |
516 EXPECT(str.IsOneByteString()); | 471 EXPECT(str.IsOneByteString()); |
517 EXPECT(!str.IsTwoByteString()); | 472 EXPECT(!str.IsTwoByteString()); |
518 EXPECT(!str.IsNumber()); | 473 EXPECT(!str.IsNumber()); |
519 EXPECT_EQ(hello_len, str.Length()); | 474 EXPECT_EQ(hello_len, str.Length()); |
520 EXPECT_EQ(ToUChar('H'), str.CharAt(0)); | 475 EXPECT_EQ('H', str.CharAt(0)); |
521 EXPECT_EQ(ToUChar('e'), str.CharAt(1)); | 476 EXPECT_EQ('e', str.CharAt(1)); |
522 EXPECT_EQ(ToUChar('l'), str.CharAt(2)); | 477 EXPECT_EQ('l', str.CharAt(2)); |
523 EXPECT_EQ(ToUChar('l'), str.CharAt(3)); | 478 EXPECT_EQ('l', str.CharAt(3)); |
524 EXPECT_EQ(ToUChar('o'), str.CharAt(4)); | 479 EXPECT_EQ('o', str.CharAt(4)); |
525 EXPECT_EQ(ToUChar(' '), str.CharAt(5)); | 480 EXPECT_EQ(' ', str.CharAt(5)); |
526 EXPECT_EQ(ToUChar('W'), str.CharAt(6)); | 481 EXPECT_EQ('W', str.CharAt(6)); |
527 EXPECT_EQ(ToUChar('o'), str.CharAt(7)); | 482 EXPECT_EQ('o', str.CharAt(7)); |
528 EXPECT_EQ(ToUChar('r'), str.CharAt(8)); | 483 EXPECT_EQ('r', str.CharAt(8)); |
529 EXPECT_EQ(ToUChar('l'), str.CharAt(9)); | 484 EXPECT_EQ('l', str.CharAt(9)); |
530 EXPECT_EQ(ToUChar('d'), str.CharAt(10)); | 485 EXPECT_EQ('d', str.CharAt(10)); |
531 EXPECT_EQ(ToUChar('!'), str.CharAt(11)); | 486 EXPECT_EQ('!', str.CharAt(11)); |
532 | 487 |
533 const uint8_t* motto = | 488 const uint8_t* motto = |
534 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); | 489 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); |
535 const String& str2 = String::Handle(String::New(motto+7, 4)); | 490 const String& str2 = String::Handle(String::New(motto+7, 4)); |
536 EXPECT_EQ(4, str2.Length()); | 491 EXPECT_EQ(4, str2.Length()); |
537 EXPECT_EQ(ToUChar('b'), str2.CharAt(0)); | 492 EXPECT_EQ('b', str2.CharAt(0)); |
538 EXPECT_EQ(ToUChar('e'), str2.CharAt(1)); | 493 EXPECT_EQ('e', str2.CharAt(1)); |
539 EXPECT_EQ(ToUChar('s'), str2.CharAt(2)); | 494 EXPECT_EQ('s', str2.CharAt(2)); |
540 EXPECT_EQ(ToUChar('c'), str2.CharAt(3)); | 495 EXPECT_EQ('c', str2.CharAt(3)); |
541 | 496 |
542 const String& str3 = String::Handle(String::New(kHello)); | 497 const String& str3 = String::Handle(String::New(kHello)); |
543 EXPECT(str.Equals(str)); | 498 EXPECT(str.Equals(str)); |
544 EXPECT_EQ(str.Hash(), str.Hash()); | 499 EXPECT_EQ(str.Hash(), str.Hash()); |
545 EXPECT(!str.Equals(str2)); | 500 EXPECT(!str.Equals(str2)); |
546 EXPECT(str.Equals(str3)); | 501 EXPECT(str.Equals(str3)); |
547 EXPECT_EQ(str.Hash(), str3.Hash()); | 502 EXPECT_EQ(str.Hash(), str3.Hash()); |
548 EXPECT(str3.Equals(str)); | 503 EXPECT(str3.Equals(str)); |
549 | 504 |
550 const String& str4 = String::Handle(String::New("foo")); | 505 const String& str4 = String::Handle(String::New("foo")); |
(...skipping 28 matching lines...) Expand all Loading... |
579 | 534 |
580 const intptr_t kWideCharsLen = 7; | 535 const intptr_t kWideCharsLen = 7; |
581 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; | 536 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; |
582 const String& two_str = String::Handle(String::New(wide_chars, | 537 const String& two_str = String::Handle(String::New(wide_chars, |
583 kWideCharsLen)); | 538 kWideCharsLen)); |
584 EXPECT(two_str.IsInstance()); | 539 EXPECT(two_str.IsInstance()); |
585 EXPECT(two_str.IsString()); | 540 EXPECT(two_str.IsString()); |
586 EXPECT(two_str.IsTwoByteString()); | 541 EXPECT(two_str.IsTwoByteString()); |
587 EXPECT(!two_str.IsOneByteString()); | 542 EXPECT(!two_str.IsOneByteString()); |
588 EXPECT_EQ(kWideCharsLen, two_str.Length()); | 543 EXPECT_EQ(kWideCharsLen, two_str.Length()); |
589 EXPECT_EQ(ToUChar('H'), two_str.CharAt(0)); | 544 EXPECT_EQ('H', two_str.CharAt(0)); |
590 EXPECT_EQ(256, two_str.CharAt(5)); | 545 EXPECT_EQ(256, two_str.CharAt(5)); |
591 const intptr_t kWideCharsIndex = 3; | 546 const intptr_t kWideCharsIndex = 3; |
592 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); | 547 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); |
593 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); | 548 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); |
594 EXPECT_EQ(ToUChar('l'), sub2.CharAt(0)); | 549 EXPECT_EQ('l', sub2.CharAt(0)); |
595 EXPECT_EQ(ToUChar('o'), sub2.CharAt(1)); | 550 EXPECT_EQ('o', sub2.CharAt(1)); |
596 EXPECT_EQ(256, sub2.CharAt(2)); | 551 EXPECT_EQ(256, sub2.CharAt(2)); |
597 EXPECT_EQ(ToUChar('!'), sub2.CharAt(3)); | 552 EXPECT_EQ('!', sub2.CharAt(3)); |
598 | 553 |
599 { | 554 { |
600 const String& str1 = String::Handle(String::New("My.create")); | 555 const String& str1 = String::Handle(String::New("My.create")); |
601 const String& str2 = String::Handle(String::New("My")); | 556 const String& str2 = String::Handle(String::New("My")); |
602 const String& str3 = String::Handle(String::New("create")); | 557 const String& str3 = String::Handle(String::New("create")); |
603 EXPECT_EQ(true, str1.StartsWith(str2)); | 558 EXPECT_EQ(true, str1.StartsWith(str2)); |
604 EXPECT_EQ(false, str1.StartsWith(str3)); | 559 EXPECT_EQ(false, str1.StartsWith(str3)); |
605 } | 560 } |
606 | 561 |
607 const int32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; | 562 const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; |
608 const String& four_str = String::Handle(String::New(four_chars, 7)); | 563 const String& four_str = String::Handle(String::New(four_chars, 7)); |
609 EXPECT_EQ(four_str.Hash(), four_str.Hash()); | 564 EXPECT_EQ(four_str.Hash(), four_str.Hash()); |
610 EXPECT(four_str.IsTwoByteString()); | 565 EXPECT(four_str.IsTwoByteString()); |
611 EXPECT(!four_str.IsOneByteString()); | 566 EXPECT(!four_str.IsOneByteString()); |
612 EXPECT_EQ(8, four_str.Length()); | 567 EXPECT_EQ(8, four_str.Length()); |
613 EXPECT_EQ(ToUChar('C'), four_str.CharAt(0)); | 568 EXPECT_EQ('C', four_str.CharAt(0)); |
614 EXPECT_EQ(0xFF, four_str.CharAt(1)); | 569 EXPECT_EQ(0xFF, four_str.CharAt(1)); |
615 EXPECT_EQ(ToUChar('h'), four_str.CharAt(2)); | 570 EXPECT_EQ('h', four_str.CharAt(2)); |
616 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); | 571 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); |
617 EXPECT_EQ(ToUChar('a'), four_str.CharAt(4)); | 572 EXPECT_EQ('a', four_str.CharAt(4)); |
618 EXPECT_EQ(0xDBFF, four_str.CharAt(5)); | 573 EXPECT_EQ(0xDBFF, four_str.CharAt(5)); |
619 EXPECT_EQ(0xDFFF, four_str.CharAt(6)); | 574 EXPECT_EQ(0xDFFF, four_str.CharAt(6)); |
620 EXPECT_EQ(ToUChar('r'), four_str.CharAt(7)); | 575 EXPECT_EQ('r', four_str.CharAt(7)); |
621 | 576 |
622 // 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. |
623 { | 578 { |
624 const uint16_t char16[] = { 0x00, 0x7F, 0xFF }; | 579 const uint16_t char16[] = { 0x00, 0x7F, 0xFF }; |
625 const String& str8 = String::Handle(String::New(char16, 3)); | 580 const String& str8 = String::Handle(String::New(char16, 3)); |
626 EXPECT(str8.IsOneByteString()); | 581 EXPECT(str8.IsOneByteString()); |
627 EXPECT(!str8.IsTwoByteString()); | 582 EXPECT(!str8.IsTwoByteString()); |
628 EXPECT_EQ(0x00, str8.CharAt(0)); | 583 EXPECT_EQ(0x00, str8.CharAt(0)); |
629 EXPECT_EQ(0x7F, str8.CharAt(1)); | 584 EXPECT_EQ(0x7F, str8.CharAt(1)); |
630 EXPECT_EQ(0xFF, str8.CharAt(2)); | 585 EXPECT_EQ(0xFF, str8.CharAt(2)); |
631 } | 586 } |
632 | 587 |
633 // 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. |
634 { | 589 { |
635 const int32_t char32[] = { 0x00, 0x1F, 0x7F }; | 590 const uint32_t char32[] = { 0x00, 0x1F, 0x7F }; |
636 const String& str8 = String::Handle(String::New(char32, 3)); | 591 const String& str8 = String::Handle(String::New(char32, 3)); |
637 EXPECT(str8.IsOneByteString()); | 592 EXPECT(str8.IsOneByteString()); |
638 EXPECT(!str8.IsTwoByteString()); | 593 EXPECT(!str8.IsTwoByteString()); |
639 EXPECT_EQ(0x00, str8.CharAt(0)); | 594 EXPECT_EQ(0x00, str8.CharAt(0)); |
640 EXPECT_EQ(0x1F, str8.CharAt(1)); | 595 EXPECT_EQ(0x1F, str8.CharAt(1)); |
641 EXPECT_EQ(0x7F, str8.CharAt(2)); | 596 EXPECT_EQ(0x7F, str8.CharAt(2)); |
642 } | 597 } |
643 | 598 |
644 // 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. |
645 { | 600 { |
646 const int32_t char32[] = { 0, 0x7FFF, 0xFFFF }; | 601 const uint32_t char32[] = { 0, 0x7FFF, 0xFFFF }; |
647 const String& str16 = String::Handle(String::New(char32, 3)); | 602 const String& str16 = String::Handle(String::New(char32, 3)); |
648 EXPECT(!str16.IsOneByteString()); | 603 EXPECT(!str16.IsOneByteString()); |
649 EXPECT(str16.IsTwoByteString()); | 604 EXPECT(str16.IsTwoByteString()); |
650 EXPECT_EQ(0x0000, str16.CharAt(0)); | 605 EXPECT_EQ(0x0000, str16.CharAt(0)); |
651 EXPECT_EQ(0x7FFF, str16.CharAt(1)); | 606 EXPECT_EQ(0x7FFF, str16.CharAt(1)); |
652 EXPECT_EQ(0xFFFF, str16.CharAt(2)); | 607 EXPECT_EQ(0xFFFF, str16.CharAt(2)); |
653 } | 608 } |
654 } | 609 } |
655 | 610 |
656 | 611 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 EXPECT_EQ(two_one_two_len, str6.Length()); | 936 EXPECT_EQ(two_one_two_len, str6.Length()); |
982 EXPECT(str6.Equals(two_one_two, two_one_two_len)); | 937 EXPECT(str6.Equals(two_one_two, two_one_two_len)); |
983 } | 938 } |
984 | 939 |
985 // Concatenated emtpy and non-empty strings built from 4-byte elements. | 940 // Concatenated emtpy and non-empty strings built from 4-byte elements. |
986 { | 941 { |
987 const String& str1 = String::Handle(String::New("")); | 942 const String& str1 = String::Handle(String::New("")); |
988 EXPECT(str1.IsOneByteString()); | 943 EXPECT(str1.IsOneByteString()); |
989 EXPECT_EQ(0, str1.Length()); | 944 EXPECT_EQ(0, str1.Length()); |
990 | 945 |
991 int32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; | 946 uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; |
992 intptr_t four_len = sizeof(four) / sizeof(four[0]); | 947 intptr_t four_len = sizeof(four) / sizeof(four[0]); |
993 intptr_t expected_len = (four_len * 2); | 948 intptr_t expected_len = (four_len * 2); |
994 const String& str2 = String::Handle(String::New(four, four_len)); | 949 const String& str2 = String::Handle(String::New(four, four_len)); |
995 EXPECT(str2.IsTwoByteString()); | 950 EXPECT(str2.IsTwoByteString()); |
996 EXPECT_EQ(expected_len, str2.Length()); | 951 EXPECT_EQ(expected_len, str2.Length()); |
997 | 952 |
998 // Concat | 953 // Concat |
999 | 954 |
1000 const String& str3 = String::Handle(String::Concat(str1, str2)); | 955 const String& str3 = String::Handle(String::Concat(str1, str2)); |
1001 EXPECT_EQ(expected_len, str3.Length()); | 956 EXPECT_EQ(expected_len, str3.Length()); |
(...skipping 24 matching lines...) Expand all Loading... |
1026 EXPECT_EQ(expected_len, str6.Length()); | 981 EXPECT_EQ(expected_len, str6.Length()); |
1027 EXPECT(str6.Equals(str2)); | 982 EXPECT(str6.Equals(str2)); |
1028 | 983 |
1029 const Array& array3 = Array::Handle(Array::New(3)); | 984 const Array& array3 = Array::Handle(Array::New(3)); |
1030 EXPECT_EQ(3, array3.Length()); | 985 EXPECT_EQ(3, array3.Length()); |
1031 array3.SetAt(0, str2); | 986 array3.SetAt(0, str2); |
1032 array3.SetAt(1, str1); | 987 array3.SetAt(1, str1); |
1033 array3.SetAt(2, str2); | 988 array3.SetAt(2, str2); |
1034 const String& str7 = String::Handle(String::ConcatAll(array3)); | 989 const String& str7 = String::Handle(String::ConcatAll(array3)); |
1035 EXPECT(str7.IsTwoByteString()); | 990 EXPECT(str7.IsTwoByteString()); |
1036 int32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, | 991 uint32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, |
1037 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; | 992 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; |
1038 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]); | 993 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]); |
1039 EXPECT_EQ((fourfour_len * 2), str7.Length()); | 994 EXPECT_EQ((fourfour_len * 2), str7.Length()); |
1040 const String& fourfour_str = | 995 const String& fourfour_str = |
1041 String::Handle(String::New(fourfour, fourfour_len)); | 996 String::Handle(String::New(fourfour, fourfour_len)); |
1042 EXPECT(str7.Equals(fourfour_str)); | 997 EXPECT(str7.Equals(fourfour_str)); |
1043 } | 998 } |
1044 | 999 |
1045 // Concatenate non-empty strings built from 4-byte elements. | 1000 // Concatenate non-empty strings built from 4-byte elements. |
1046 { | 1001 { |
1047 const int32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1002 const uint32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF }; |
1048 intptr_t one_len = sizeof(one) / sizeof(one[0]); | 1003 intptr_t one_len = sizeof(one) / sizeof(one[0]); |
1049 const String& onestr = String::Handle(String::New(one, one_len)); | 1004 const String& onestr = String::Handle(String::New(one, one_len)); |
1050 EXPECT(onestr.IsTwoByteString()); | 1005 EXPECT(onestr.IsTwoByteString()); |
1051 EXPECT_EQ((one_len *2), onestr.Length()); | 1006 EXPECT_EQ((one_len *2), onestr.Length()); |
1052 | 1007 |
1053 const int32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; | 1008 const uint32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; |
1054 intptr_t two_len = sizeof(two) / sizeof(two[0]); | 1009 intptr_t two_len = sizeof(two) / sizeof(two[0]); |
1055 const String& twostr = String::Handle(String::New(two, two_len)); | 1010 const String& twostr = String::Handle(String::New(two, two_len)); |
1056 EXPECT(twostr.IsTwoByteString()); | 1011 EXPECT(twostr.IsTwoByteString()); |
1057 EXPECT_EQ((two_len * 2), twostr.Length()); | 1012 EXPECT_EQ((two_len * 2), twostr.Length()); |
1058 | 1013 |
1059 // Concat | 1014 // Concat |
1060 | 1015 |
1061 const String& str1 = String::Handle(String::Concat(onestr, twostr)); | 1016 const String& str1 = String::Handle(String::Concat(onestr, twostr)); |
1062 EXPECT(str1.IsTwoByteString()); | 1017 EXPECT(str1.IsTwoByteString()); |
1063 const int32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1018 const uint32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, |
1064 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; | 1019 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; |
1065 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]); |
1066 EXPECT_EQ((one_two_len * 2), str1.Length()); | 1021 EXPECT_EQ((one_two_len * 2), str1.Length()); |
1067 const String& one_two_str = | 1022 const String& one_two_str = |
1068 String::Handle(String::New(one_two, one_two_len)); | 1023 String::Handle(String::New(one_two, one_two_len)); |
1069 EXPECT(str1.Equals(one_two_str)); | 1024 EXPECT(str1.Equals(one_two_str)); |
1070 | 1025 |
1071 const String& str2 = String::Handle(String::Concat(twostr, onestr)); | 1026 const String& str2 = String::Handle(String::Concat(twostr, onestr)); |
1072 EXPECT(str2.IsTwoByteString()); | 1027 EXPECT(str2.IsTwoByteString()); |
1073 const int32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, | 1028 const uint32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, |
1074 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1029 0x105D0, 0x105D9, 0x105D9, 0x105DF }; |
1075 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]); |
1076 EXPECT_EQ((two_one_len * 2), str2.Length()); | 1031 EXPECT_EQ((two_one_len * 2), str2.Length()); |
1077 const String& two_one_str = | 1032 const String& two_one_str = |
1078 String::Handle(String::New(two_one, two_one_len)); | 1033 String::Handle(String::New(two_one, two_one_len)); |
1079 EXPECT(str2.Equals(two_one_str)); | 1034 EXPECT(str2.Equals(two_one_str)); |
1080 | 1035 |
1081 // ConcatAll | 1036 // ConcatAll |
1082 | 1037 |
1083 const Array& array1 = Array::Handle(Array::New(2)); | 1038 const Array& array1 = Array::Handle(Array::New(2)); |
1084 EXPECT_EQ(2, array1.Length()); | 1039 EXPECT_EQ(2, array1.Length()); |
(...skipping 13 matching lines...) Expand all Loading... |
1098 EXPECT_EQ((two_one_len * 2), str4.Length()); | 1053 EXPECT_EQ((two_one_len * 2), str4.Length()); |
1099 EXPECT(str4.Equals(two_one_str)); | 1054 EXPECT(str4.Equals(two_one_str)); |
1100 | 1055 |
1101 const Array& array3 = Array::Handle(Array::New(3)); | 1056 const Array& array3 = Array::Handle(Array::New(3)); |
1102 EXPECT_EQ(3, array3.Length()); | 1057 EXPECT_EQ(3, array3.Length()); |
1103 array3.SetAt(0, onestr); | 1058 array3.SetAt(0, onestr); |
1104 array3.SetAt(1, twostr); | 1059 array3.SetAt(1, twostr); |
1105 array3.SetAt(2, onestr); | 1060 array3.SetAt(2, onestr); |
1106 const String& str5 = String::Handle(String::ConcatAll(array3)); | 1061 const String& str5 = String::Handle(String::ConcatAll(array3)); |
1107 EXPECT(str5.IsTwoByteString()); | 1062 EXPECT(str5.IsTwoByteString()); |
1108 const int32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1063 const uint32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, |
1109 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1064 0x105E6, 0x105D5, 0x105D5, 0x105D9, |
1110 0x105D9, | 1065 0x105D9, |
1111 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1066 0x105D0, 0x105D9, 0x105D9, 0x105DF }; |
1112 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]); |
1113 EXPECT_EQ((one_two_one_len * 2), str5.Length()); | 1068 EXPECT_EQ((one_two_one_len * 2), str5.Length()); |
1114 const String& one_two_one_str = | 1069 const String& one_two_one_str = |
1115 String::Handle(String::New(one_two_one, one_two_one_len)); | 1070 String::Handle(String::New(one_two_one, one_two_one_len)); |
1116 EXPECT(str5.Equals(one_two_one_str)); | 1071 EXPECT(str5.Equals(one_two_one_str)); |
1117 | 1072 |
1118 const Array& array4 = Array::Handle(Array::New(3)); | 1073 const Array& array4 = Array::Handle(Array::New(3)); |
1119 EXPECT_EQ(3, array4.Length()); | 1074 EXPECT_EQ(3, array4.Length()); |
1120 array4.SetAt(0, twostr); | 1075 array4.SetAt(0, twostr); |
1121 array4.SetAt(1, onestr); | 1076 array4.SetAt(1, onestr); |
1122 array4.SetAt(2, twostr); | 1077 array4.SetAt(2, twostr); |
1123 const String& str6 = String::Handle(String::ConcatAll(array4)); | 1078 const String& str6 = String::Handle(String::ConcatAll(array4)); |
1124 EXPECT(str6.IsTwoByteString()); | 1079 EXPECT(str6.IsTwoByteString()); |
1125 const int32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1080 const uint32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, |
1126 0x105D9, | 1081 0x105D9, |
1127 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1082 0x105D0, 0x105D9, 0x105D9, 0x105DF, |
1128 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1083 0x105E6, 0x105D5, 0x105D5, 0x105D9, |
1129 0x105D9 }; | 1084 0x105D9 }; |
1130 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]); |
1131 EXPECT_EQ((two_one_two_len * 2), str6.Length()); | 1086 EXPECT_EQ((two_one_two_len * 2), str6.Length()); |
1132 const String& two_one_two_str = | 1087 const String& two_one_two_str = |
1133 String::Handle(String::New(two_one_two, two_one_two_len)); | 1088 String::Handle(String::New(two_one_two, two_one_two_len)); |
1134 EXPECT(str6.Equals(two_one_two_str)); | 1089 EXPECT(str6.Equals(two_one_two_str)); |
1135 } | 1090 } |
1136 | 1091 |
1137 // Concatenate 1-byte strings and 2-byte strings. | 1092 // Concatenate 1-byte strings and 2-byte strings. |
1138 { | 1093 { |
1139 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; | 1094 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1336 // characters. | 1291 // characters. |
1337 { | 1292 { |
1338 const char* src = | 1293 const char* src = |
1339 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1294 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
1340 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1295 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
1341 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1296 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
1342 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1297 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
1343 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1298 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
1344 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1299 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
1345 "\xEE\x80\x80\xEF\x80\x80"; | 1300 "\xEE\x80\x80\xEF\x80\x80"; |
1346 const int32_t expected[] = { | 1301 const intptr_t expected[] = { |
1347 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1302 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, |
1348 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1303 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, |
1349 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 | 1304 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 |
1350 }; | 1305 }; |
1351 const String& str = String::Handle(String::New(src)); | 1306 const String& str = String::Handle(String::New(src)); |
1352 EXPECT(str.IsTwoByteString()); | 1307 EXPECT(str.IsTwoByteString()); |
1353 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1308 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1354 EXPECT_EQ(expected_size, str.Length()); | 1309 EXPECT_EQ(expected_size, str.Length()); |
1355 for (int i = 0; i < str.Length(); ++i) { | 1310 for (int i = 0; i < str.Length(); ++i) { |
1356 EXPECT_EQ(expected[i], str.CharAt(i)); | 1311 EXPECT_EQ(expected[i], str.CharAt(i)); |
1357 } | 1312 } |
1358 } | 1313 } |
1359 | 1314 |
1360 // Create a 2-byte string with supplementary characters from a UTF-8 | 1315 // Create a 2-byte string with supplementary characters from a UTF-8 |
1361 // string literal. | 1316 // string literal. |
1362 { | 1317 { |
1363 const char* src = | 1318 const char* src = |
1364 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" | 1319 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" |
1365 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; | 1320 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; |
1366 const int32_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61, | 1321 const intptr_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61, |
1367 0xd835, 0xdc62, 0xd835, 0xdc63 }; | 1322 0xd835, 0xdc62, 0xd835, 0xdc63 }; |
1368 const String& str = String::Handle(String::New(src)); | 1323 const String& str = String::Handle(String::New(src)); |
1369 EXPECT(str.IsTwoByteString()); | 1324 EXPECT(str.IsTwoByteString()); |
1370 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); | 1325 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); |
1371 EXPECT_EQ(expected_size, str.Length()); | 1326 EXPECT_EQ(expected_size, str.Length()); |
1372 for (int i = 0; i < str.Length(); ++i) { | 1327 for (int i = 0; i < str.Length(); ++i) { |
1373 EXPECT_EQ(expected[i], str.CharAt(i)); | 1328 EXPECT_EQ(expected[i], str.CharAt(i)); |
1374 } | 1329 } |
1375 } | 1330 } |
1376 | 1331 |
1377 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte | 1332 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte |
1378 // characters. | 1333 // characters. |
1379 { | 1334 { |
1380 const char* src = | 1335 const char* src = |
1381 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" | 1336 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" |
1382 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" | 1337 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" |
1383 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" | 1338 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" |
1384 "\xEC\x80\x80\xED\x80\x80\xEE\x80" | 1339 "\xEC\x80\x80\xED\x80\x80\xEE\x80" |
1385 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" | 1340 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" |
1386 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" | 1341 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" |
1387 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; | 1342 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; |
1388 const int32_t expected[] = { | 1343 const intptr_t expected[] = { |
1389 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, | 1344 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, |
1390 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, | 1345 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, |
1391 0xD838, 0xDC00, 0xD83c, 0xDC00, | 1346 0xD838, 0xDC00, 0xD83c, 0xDC00, |
1392 }; | 1347 }; |
1393 const String& str = String::Handle(String::New(src)); | 1348 const String& str = String::Handle(String::New(src)); |
1394 EXPECT(str.IsTwoByteString()); | 1349 EXPECT(str.IsTwoByteString()); |
1395 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1350 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1396 EXPECT_EQ(expected_size, str.Length()); | 1351 EXPECT_EQ(expected_size, str.Length()); |
1397 for (int i = 0; i < str.Length(); ++i) { | 1352 for (int i = 0; i < str.Length(); ++i) { |
1398 EXPECT_EQ(expected[i], str.CharAt(i)); | 1353 EXPECT_EQ(expected[i], str.CharAt(i)); |
1399 } | 1354 } |
1400 } | 1355 } |
1401 | 1356 |
1402 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte | 1357 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte |
1403 // characters. | 1358 // characters. |
1404 { | 1359 { |
1405 const char* src = | 1360 const char* src = |
1406 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1361 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
1407 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1362 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
1408 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1363 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
1409 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1364 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
1410 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1365 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
1411 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1366 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
1412 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" | 1367 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" |
1413 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" | 1368 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" |
1414 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" | 1369 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" |
1415 "\x80\x80"; | 1370 "\x80\x80"; |
1416 const int32_t expected[] = { | 1371 const intptr_t expected[] = { |
1417 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1372 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, |
1418 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1373 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, |
1419 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, | 1374 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, |
1420 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, | 1375 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, |
1421 0xD83c, 0xDC00, | 1376 0xD83c, 0xDC00, |
1422 }; | 1377 }; |
1423 const String& str = String::Handle(String::New(src)); | 1378 const String& str = String::Handle(String::New(src)); |
1424 EXPECT(str.IsTwoByteString()); | 1379 EXPECT(str.IsTwoByteString()); |
1425 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1380 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
1426 EXPECT_EQ(expected_size, str.Length()); | 1381 EXPECT_EQ(expected_size, str.Length()); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1540 EXPECT_EQ(nine.raw(), Symbols::New("Neun")); | 1495 EXPECT_EQ(nine.raw(), Symbols::New("Neun")); |
1541 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); | 1496 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); |
1542 | 1497 |
1543 // Symbols from Strings. | 1498 // Symbols from Strings. |
1544 eins = String::New("Eins"); | 1499 eins = String::New("Eins"); |
1545 EXPECT(!eins.IsSymbol()); | 1500 EXPECT(!eins.IsSymbol()); |
1546 String& ein_symbol = String::Handle(Symbols::New(eins)); | 1501 String& ein_symbol = String::Handle(Symbols::New(eins)); |
1547 EXPECT_EQ(one.raw(), ein_symbol.raw()); | 1502 EXPECT_EQ(one.raw(), ein_symbol.raw()); |
1548 EXPECT(one.raw() != eins.raw()); | 1503 EXPECT(one.raw() != eins.raw()); |
1549 | 1504 |
1550 uint16_t char16[] = { 'E', 'l', 'f' }; | 1505 uint32_t char32[] = { 'E', 'l', 'f' }; |
1551 String& elf = String::Handle(Symbols::New(char16, 3)); | 1506 String& elf = String::Handle(Symbols::New(char32, 3)); |
1552 EXPECT(elf.IsSymbol()); | 1507 EXPECT(elf.IsSymbol()); |
1553 EXPECT_EQ(elf.raw(), Symbols::New("Elf")); | 1508 EXPECT_EQ(elf.raw(), Symbols::New("Elf")); |
1554 | |
1555 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. | |
1556 String& monkey = String::Handle(Symbols::New(monkey_utf16, 2)); | |
1557 EXPECT(monkey.IsSymbol()); | |
1558 EXPECT_EQ(monkey.raw(), Symbols::New("🐵")); | |
1559 | |
1560 int32_t kMonkeyFace = 0x1f435; | |
1561 String& monkey2 = String::Handle(Symbols::FromCharCode(kMonkeyFace)); | |
1562 EXPECT_EQ(monkey.raw(), monkey2.raw()); | |
1563 | |
1564 // Unicode cat face with tears of joy. | |
1565 int32_t kCatFaceWithTearsOfJoy = 0x1f639; | |
1566 String& cat = String::Handle(Symbols::FromCharCode(kCatFaceWithTearsOfJoy)); | |
1567 | |
1568 uint16_t cat_utf16[] = { 0xd83d, 0xde39 }; | |
1569 String& cat2 = String::Handle(Symbols::New(cat_utf16, 2)); | |
1570 EXPECT(cat2.IsSymbol()); | |
1571 EXPECT_EQ(cat2.raw(), cat.raw()); | |
1572 } | 1509 } |
1573 | 1510 |
1574 | 1511 |
1575 TEST_CASE(Bool) { | 1512 TEST_CASE(Bool) { |
1576 const Bool& true_value = Bool::Handle(Bool::True()); | 1513 const Bool& true_value = Bool::Handle(Bool::True()); |
1577 EXPECT(true_value.value()); | 1514 EXPECT(true_value.value()); |
1578 const Bool& false_value = Bool::Handle(Bool::False()); | 1515 const Bool& false_value = Bool::Handle(Bool::False()); |
1579 EXPECT(!false_value.value()); | 1516 EXPECT(!false_value.value()); |
1580 } | 1517 } |
1581 | 1518 |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 const char* source_chars = "This will not compile."; | 2029 const char* source_chars = "This will not compile."; |
2093 const String& url = String::Handle(String::New(url_chars)); | 2030 const String& url = String::Handle(String::New(url_chars)); |
2094 const String& source = String::Handle(String::New(source_chars)); | 2031 const String& source = String::Handle(String::New(source_chars)); |
2095 const Script& script = Script::Handle(Script::New(url, | 2032 const Script& script = Script::Handle(Script::New(url, |
2096 source, | 2033 source, |
2097 RawScript::kSourceTag)); | 2034 RawScript::kSourceTag)); |
2098 EXPECT(!script.IsNull()); | 2035 EXPECT(!script.IsNull()); |
2099 EXPECT(script.IsScript()); | 2036 EXPECT(script.IsScript()); |
2100 String& str = String::Handle(script.url()); | 2037 String& str = String::Handle(script.url()); |
2101 EXPECT_EQ(17, str.Length()); | 2038 EXPECT_EQ(17, str.Length()); |
2102 EXPECT_EQ(ToUChar('b'), str.CharAt(0)); | 2039 EXPECT_EQ('b', str.CharAt(0)); |
2103 EXPECT_EQ(ToUChar(':'), str.CharAt(7)); | 2040 EXPECT_EQ(':', str.CharAt(7)); |
2104 EXPECT_EQ(ToUChar('e'), str.CharAt(16)); | 2041 EXPECT_EQ('e', str.CharAt(16)); |
2105 str = script.Source(); | 2042 str = script.Source(); |
2106 EXPECT_EQ(22, str.Length()); | 2043 EXPECT_EQ(22, str.Length()); |
2107 EXPECT_EQ(ToUChar('T'), str.CharAt(0)); | 2044 EXPECT_EQ('T', str.CharAt(0)); |
2108 EXPECT_EQ(ToUChar('n'), str.CharAt(10)); | 2045 EXPECT_EQ('n', str.CharAt(10)); |
2109 EXPECT_EQ(ToUChar('.'), str.CharAt(21)); | 2046 EXPECT_EQ('.', str.CharAt(21)); |
2110 } | 2047 } |
2111 | 2048 |
2112 | 2049 |
2113 TEST_CASE(Context) { | 2050 TEST_CASE(Context) { |
2114 const int kNumVariables = 5; | 2051 const int kNumVariables = 5; |
2115 const Context& parent_context = Context::Handle(Context::New(0)); | 2052 const Context& parent_context = Context::Handle(Context::New(0)); |
2116 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); | 2053 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); |
2117 const Context& context = Context::Handle(Context::New(kNumVariables)); | 2054 const Context& context = Context::Handle(Context::New(kNumVariables)); |
2118 context.set_parent(parent_context); | 2055 context.set_parent(parent_context); |
2119 const Context& check_parent_context = Context::Handle(context.parent()); | 2056 const Context& check_parent_context = Context::Handle(context.parent()); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2339 Code& code = Code::Handle(Code::FinalizeCode( | 2276 Code& code = Code::Handle(Code::FinalizeCode( |
2340 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); | 2277 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); |
2341 Instructions& instructions = Instructions::Handle(code.instructions()); | 2278 Instructions& instructions = Instructions::Handle(code.instructions()); |
2342 typedef uword (*EmbedStringCode)(); | 2279 typedef uword (*EmbedStringCode)(); |
2343 uword retval = reinterpret_cast<EmbedStringCode>(instructions.EntryPoint())(); | 2280 uword retval = reinterpret_cast<EmbedStringCode>(instructions.EntryPoint())(); |
2344 EXPECT((retval & kSmiTagMask) == kHeapObjectTag); | 2281 EXPECT((retval & kSmiTagMask) == kHeapObjectTag); |
2345 String& string_object = String::Handle(); | 2282 String& string_object = String::Handle(); |
2346 string_object ^= reinterpret_cast<RawInstructions*>(retval); | 2283 string_object ^= reinterpret_cast<RawInstructions*>(retval); |
2347 EXPECT(string_object.Length() == expected_length); | 2284 EXPECT(string_object.Length() == expected_length); |
2348 for (int i = 0; i < expected_length; i ++) { | 2285 for (int i = 0; i < expected_length; i ++) { |
2349 EXPECT(string_object.CharAt(i) == static_cast<int32_t>(kHello[i])); | 2286 EXPECT(string_object.CharAt(i) == kHello[i]); |
2350 } | 2287 } |
2351 } | 2288 } |
2352 | 2289 |
2353 | 2290 |
2354 // Test for Embedded Smi object in the instructions. | 2291 // Test for Embedded Smi object in the instructions. |
2355 TEST_CASE(EmbedSmiInCode) { | 2292 TEST_CASE(EmbedSmiInCode) { |
2356 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); | 2293 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); |
2357 const intptr_t kSmiTestValue = 5; | 2294 const intptr_t kSmiTestValue = 5; |
2358 Assembler _assembler_; | 2295 Assembler _assembler_; |
2359 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); | 2296 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3150 isolate->heap()->CollectAllGarbage(); | 3087 isolate->heap()->CollectAllGarbage(); |
3151 EXPECT(weak1.key() == Object::null()); | 3088 EXPECT(weak1.key() == Object::null()); |
3152 EXPECT(weak1.value() == Object::null()); | 3089 EXPECT(weak1.value() == Object::null()); |
3153 EXPECT(weak2.key() == Object::null()); | 3090 EXPECT(weak2.key() == Object::null()); |
3154 EXPECT(weak2.value() == Object::null()); | 3091 EXPECT(weak2.value() == Object::null()); |
3155 } | 3092 } |
3156 | 3093 |
3157 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3094 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
3158 | 3095 |
3159 } // namespace dart | 3096 } // namespace dart |
OLD | NEW |