| 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 |
| 276 TEST_CASE(Mint) { | 318 TEST_CASE(Mint) { |
| 277 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot | 319 // On 64-bit architectures a Smi is stored in a 64 bit word. A Midint cannot |
| 278 // be allocated if it does fit into a Smi. | 320 // be allocated if it does fit into a Smi. |
| 279 #if !defined(ARCH_IS_64_BIT) | 321 #if !defined(ARCH_IS_64_BIT) |
| 280 { Mint& med = Mint::Handle(); | 322 { Mint& med = Mint::Handle(); |
| 281 EXPECT(med.IsNull()); | 323 EXPECT(med.IsNull()); |
| 282 int64_t v = DART_2PART_UINT64_C(1, 0); | 324 int64_t v = DART_2PART_UINT64_C(1, 0); |
| 283 med = Mint::New(v); | 325 med = Mint::New(v); |
| 284 EXPECT_EQ(v, med.value()); | 326 EXPECT_EQ(v, med.value()); |
| 285 const String& smi_str = String::Handle(String::New("1")); | 327 const String& smi_str = String::Handle(String::New("1")); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 EXPECT(i.IsSmi()); | 497 EXPECT(i.IsSmi()); |
| 456 i = Integer::New(String::Handle(String::New("0"))); | 498 i = Integer::New(String::Handle(String::New("0"))); |
| 457 EXPECT(i.IsSmi()); | 499 EXPECT(i.IsSmi()); |
| 458 i = Integer::New(String::Handle(String::New("12345678901234567890"))); | 500 i = Integer::New(String::Handle(String::New("12345678901234567890"))); |
| 459 EXPECT(i.IsBigint()); | 501 EXPECT(i.IsBigint()); |
| 460 i = Integer::New(String::Handle(String::New("-12345678901234567890111222"))); | 502 i = Integer::New(String::Handle(String::New("-12345678901234567890111222"))); |
| 461 EXPECT(i.IsBigint()); | 503 EXPECT(i.IsBigint()); |
| 462 } | 504 } |
| 463 | 505 |
| 464 | 506 |
| 507 static unsigned char ToUChar(char x) { return static_cast<unsigned char>(x); } |
| 508 |
| 509 |
| 465 TEST_CASE(String) { | 510 TEST_CASE(String) { |
| 466 const char* kHello = "Hello World!"; | 511 const char* kHello = "Hello World!"; |
| 467 int32_t hello_len = strlen(kHello); | 512 int32_t hello_len = strlen(kHello); |
| 468 const String& str = String::Handle(String::New(kHello)); | 513 const String& str = String::Handle(String::New(kHello)); |
| 469 EXPECT(str.IsInstance()); | 514 EXPECT(str.IsInstance()); |
| 470 EXPECT(str.IsString()); | 515 EXPECT(str.IsString()); |
| 471 EXPECT(str.IsOneByteString()); | 516 EXPECT(str.IsOneByteString()); |
| 472 EXPECT(!str.IsTwoByteString()); | 517 EXPECT(!str.IsTwoByteString()); |
| 473 EXPECT(!str.IsNumber()); | 518 EXPECT(!str.IsNumber()); |
| 474 EXPECT_EQ(hello_len, str.Length()); | 519 EXPECT_EQ(hello_len, str.Length()); |
| 475 EXPECT_EQ('H', str.CharAt(0)); | 520 EXPECT_EQ(ToUChar('H'), str.CharAt(0)); |
| 476 EXPECT_EQ('e', str.CharAt(1)); | 521 EXPECT_EQ(ToUChar('e'), str.CharAt(1)); |
| 477 EXPECT_EQ('l', str.CharAt(2)); | 522 EXPECT_EQ(ToUChar('l'), str.CharAt(2)); |
| 478 EXPECT_EQ('l', str.CharAt(3)); | 523 EXPECT_EQ(ToUChar('l'), str.CharAt(3)); |
| 479 EXPECT_EQ('o', str.CharAt(4)); | 524 EXPECT_EQ(ToUChar('o'), str.CharAt(4)); |
| 480 EXPECT_EQ(' ', str.CharAt(5)); | 525 EXPECT_EQ(ToUChar(' '), str.CharAt(5)); |
| 481 EXPECT_EQ('W', str.CharAt(6)); | 526 EXPECT_EQ(ToUChar('W'), str.CharAt(6)); |
| 482 EXPECT_EQ('o', str.CharAt(7)); | 527 EXPECT_EQ(ToUChar('o'), str.CharAt(7)); |
| 483 EXPECT_EQ('r', str.CharAt(8)); | 528 EXPECT_EQ(ToUChar('r'), str.CharAt(8)); |
| 484 EXPECT_EQ('l', str.CharAt(9)); | 529 EXPECT_EQ(ToUChar('l'), str.CharAt(9)); |
| 485 EXPECT_EQ('d', str.CharAt(10)); | 530 EXPECT_EQ(ToUChar('d'), str.CharAt(10)); |
| 486 EXPECT_EQ('!', str.CharAt(11)); | 531 EXPECT_EQ(ToUChar('!'), str.CharAt(11)); |
| 487 | 532 |
| 488 const uint8_t* motto = | 533 const uint8_t* motto = |
| 489 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); | 534 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); |
| 490 const String& str2 = String::Handle(String::New(motto+7, 4)); | 535 const String& str2 = String::Handle(String::New(motto+7, 4)); |
| 491 EXPECT_EQ(4, str2.Length()); | 536 EXPECT_EQ(4, str2.Length()); |
| 492 EXPECT_EQ('b', str2.CharAt(0)); | 537 EXPECT_EQ(ToUChar('b'), str2.CharAt(0)); |
| 493 EXPECT_EQ('e', str2.CharAt(1)); | 538 EXPECT_EQ(ToUChar('e'), str2.CharAt(1)); |
| 494 EXPECT_EQ('s', str2.CharAt(2)); | 539 EXPECT_EQ(ToUChar('s'), str2.CharAt(2)); |
| 495 EXPECT_EQ('c', str2.CharAt(3)); | 540 EXPECT_EQ(ToUChar('c'), str2.CharAt(3)); |
| 496 | 541 |
| 497 const String& str3 = String::Handle(String::New(kHello)); | 542 const String& str3 = String::Handle(String::New(kHello)); |
| 498 EXPECT(str.Equals(str)); | 543 EXPECT(str.Equals(str)); |
| 499 EXPECT_EQ(str.Hash(), str.Hash()); | 544 EXPECT_EQ(str.Hash(), str.Hash()); |
| 500 EXPECT(!str.Equals(str2)); | 545 EXPECT(!str.Equals(str2)); |
| 501 EXPECT(str.Equals(str3)); | 546 EXPECT(str.Equals(str3)); |
| 502 EXPECT_EQ(str.Hash(), str3.Hash()); | 547 EXPECT_EQ(str.Hash(), str3.Hash()); |
| 503 EXPECT(str3.Equals(str)); | 548 EXPECT(str3.Equals(str)); |
| 504 | 549 |
| 505 const String& str4 = String::Handle(String::New("foo")); | 550 const String& str4 = String::Handle(String::New("foo")); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 534 | 579 |
| 535 const intptr_t kWideCharsLen = 7; | 580 const intptr_t kWideCharsLen = 7; |
| 536 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; | 581 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; |
| 537 const String& two_str = String::Handle(String::New(wide_chars, | 582 const String& two_str = String::Handle(String::New(wide_chars, |
| 538 kWideCharsLen)); | 583 kWideCharsLen)); |
| 539 EXPECT(two_str.IsInstance()); | 584 EXPECT(two_str.IsInstance()); |
| 540 EXPECT(two_str.IsString()); | 585 EXPECT(two_str.IsString()); |
| 541 EXPECT(two_str.IsTwoByteString()); | 586 EXPECT(two_str.IsTwoByteString()); |
| 542 EXPECT(!two_str.IsOneByteString()); | 587 EXPECT(!two_str.IsOneByteString()); |
| 543 EXPECT_EQ(kWideCharsLen, two_str.Length()); | 588 EXPECT_EQ(kWideCharsLen, two_str.Length()); |
| 544 EXPECT_EQ('H', two_str.CharAt(0)); | 589 EXPECT_EQ(ToUChar('H'), two_str.CharAt(0)); |
| 545 EXPECT_EQ(256, two_str.CharAt(5)); | 590 EXPECT_EQ(256, two_str.CharAt(5)); |
| 546 const intptr_t kWideCharsIndex = 3; | 591 const intptr_t kWideCharsIndex = 3; |
| 547 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); | 592 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); |
| 548 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); | 593 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); |
| 549 EXPECT_EQ('l', sub2.CharAt(0)); | 594 EXPECT_EQ(ToUChar('l'), sub2.CharAt(0)); |
| 550 EXPECT_EQ('o', sub2.CharAt(1)); | 595 EXPECT_EQ(ToUChar('o'), sub2.CharAt(1)); |
| 551 EXPECT_EQ(256, sub2.CharAt(2)); | 596 EXPECT_EQ(256, sub2.CharAt(2)); |
| 552 EXPECT_EQ('!', sub2.CharAt(3)); | 597 EXPECT_EQ(ToUChar('!'), sub2.CharAt(3)); |
| 553 | 598 |
| 554 { | 599 { |
| 555 const String& str1 = String::Handle(String::New("My.create")); | 600 const String& str1 = String::Handle(String::New("My.create")); |
| 556 const String& str2 = String::Handle(String::New("My")); | 601 const String& str2 = String::Handle(String::New("My")); |
| 557 const String& str3 = String::Handle(String::New("create")); | 602 const String& str3 = String::Handle(String::New("create")); |
| 558 EXPECT_EQ(true, str1.StartsWith(str2)); | 603 EXPECT_EQ(true, str1.StartsWith(str2)); |
| 559 EXPECT_EQ(false, str1.StartsWith(str3)); | 604 EXPECT_EQ(false, str1.StartsWith(str3)); |
| 560 } | 605 } |
| 561 | 606 |
| 562 const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; | 607 const int32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; |
| 563 const String& four_str = String::Handle(String::New(four_chars, 7)); | 608 const String& four_str = String::Handle(String::New(four_chars, 7)); |
| 564 EXPECT_EQ(four_str.Hash(), four_str.Hash()); | 609 EXPECT_EQ(four_str.Hash(), four_str.Hash()); |
| 565 EXPECT(four_str.IsTwoByteString()); | 610 EXPECT(four_str.IsTwoByteString()); |
| 566 EXPECT(!four_str.IsOneByteString()); | 611 EXPECT(!four_str.IsOneByteString()); |
| 567 EXPECT_EQ(8, four_str.Length()); | 612 EXPECT_EQ(8, four_str.Length()); |
| 568 EXPECT_EQ('C', four_str.CharAt(0)); | 613 EXPECT_EQ(ToUChar('C'), four_str.CharAt(0)); |
| 569 EXPECT_EQ(0xFF, four_str.CharAt(1)); | 614 EXPECT_EQ(0xFF, four_str.CharAt(1)); |
| 570 EXPECT_EQ('h', four_str.CharAt(2)); | 615 EXPECT_EQ(ToUChar('h'), four_str.CharAt(2)); |
| 571 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); | 616 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); |
| 572 EXPECT_EQ('a', four_str.CharAt(4)); | 617 EXPECT_EQ(ToUChar('a'), four_str.CharAt(4)); |
| 573 EXPECT_EQ(0xDBFF, four_str.CharAt(5)); | 618 EXPECT_EQ(0xDBFF, four_str.CharAt(5)); |
| 574 EXPECT_EQ(0xDFFF, four_str.CharAt(6)); | 619 EXPECT_EQ(0xDFFF, four_str.CharAt(6)); |
| 575 EXPECT_EQ('r', four_str.CharAt(7)); | 620 EXPECT_EQ(ToUChar('r'), four_str.CharAt(7)); |
| 576 | 621 |
| 577 // Create a 1-byte string from an array of 2-byte elements. | 622 // Create a 1-byte string from an array of 2-byte elements. |
| 578 { | 623 { |
| 579 const uint16_t char16[] = { 0x00, 0x7F, 0xFF }; | 624 const uint16_t char16[] = { 0x00, 0x7F, 0xFF }; |
| 580 const String& str8 = String::Handle(String::New(char16, 3)); | 625 const String& str8 = String::Handle(String::New(char16, 3)); |
| 581 EXPECT(str8.IsOneByteString()); | 626 EXPECT(str8.IsOneByteString()); |
| 582 EXPECT(!str8.IsTwoByteString()); | 627 EXPECT(!str8.IsTwoByteString()); |
| 583 EXPECT_EQ(0x00, str8.CharAt(0)); | 628 EXPECT_EQ(0x00, str8.CharAt(0)); |
| 584 EXPECT_EQ(0x7F, str8.CharAt(1)); | 629 EXPECT_EQ(0x7F, str8.CharAt(1)); |
| 585 EXPECT_EQ(0xFF, str8.CharAt(2)); | 630 EXPECT_EQ(0xFF, str8.CharAt(2)); |
| 586 } | 631 } |
| 587 | 632 |
| 588 // Create a 1-byte string from an array of 4-byte elements. | 633 // Create a 1-byte string from an array of 4-byte elements. |
| 589 { | 634 { |
| 590 const uint32_t char32[] = { 0x00, 0x1F, 0x7F }; | 635 const int32_t char32[] = { 0x00, 0x1F, 0x7F }; |
| 591 const String& str8 = String::Handle(String::New(char32, 3)); | 636 const String& str8 = String::Handle(String::New(char32, 3)); |
| 592 EXPECT(str8.IsOneByteString()); | 637 EXPECT(str8.IsOneByteString()); |
| 593 EXPECT(!str8.IsTwoByteString()); | 638 EXPECT(!str8.IsTwoByteString()); |
| 594 EXPECT_EQ(0x00, str8.CharAt(0)); | 639 EXPECT_EQ(0x00, str8.CharAt(0)); |
| 595 EXPECT_EQ(0x1F, str8.CharAt(1)); | 640 EXPECT_EQ(0x1F, str8.CharAt(1)); |
| 596 EXPECT_EQ(0x7F, str8.CharAt(2)); | 641 EXPECT_EQ(0x7F, str8.CharAt(2)); |
| 597 } | 642 } |
| 598 | 643 |
| 599 // Create a 2-byte string from an array of 4-byte elements. | 644 // Create a 2-byte string from an array of 4-byte elements. |
| 600 { | 645 { |
| 601 const uint32_t char32[] = { 0, 0x7FFF, 0xFFFF }; | 646 const int32_t char32[] = { 0, 0x7FFF, 0xFFFF }; |
| 602 const String& str16 = String::Handle(String::New(char32, 3)); | 647 const String& str16 = String::Handle(String::New(char32, 3)); |
| 603 EXPECT(!str16.IsOneByteString()); | 648 EXPECT(!str16.IsOneByteString()); |
| 604 EXPECT(str16.IsTwoByteString()); | 649 EXPECT(str16.IsTwoByteString()); |
| 605 EXPECT_EQ(0x0000, str16.CharAt(0)); | 650 EXPECT_EQ(0x0000, str16.CharAt(0)); |
| 606 EXPECT_EQ(0x7FFF, str16.CharAt(1)); | 651 EXPECT_EQ(0x7FFF, str16.CharAt(1)); |
| 607 EXPECT_EQ(0xFFFF, str16.CharAt(2)); | 652 EXPECT_EQ(0xFFFF, str16.CharAt(2)); |
| 608 } | 653 } |
| 609 } | 654 } |
| 610 | 655 |
| 611 | 656 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 EXPECT_EQ(two_one_two_len, str6.Length()); | 981 EXPECT_EQ(two_one_two_len, str6.Length()); |
| 937 EXPECT(str6.Equals(two_one_two, two_one_two_len)); | 982 EXPECT(str6.Equals(two_one_two, two_one_two_len)); |
| 938 } | 983 } |
| 939 | 984 |
| 940 // Concatenated emtpy and non-empty strings built from 4-byte elements. | 985 // Concatenated emtpy and non-empty strings built from 4-byte elements. |
| 941 { | 986 { |
| 942 const String& str1 = String::Handle(String::New("")); | 987 const String& str1 = String::Handle(String::New("")); |
| 943 EXPECT(str1.IsOneByteString()); | 988 EXPECT(str1.IsOneByteString()); |
| 944 EXPECT_EQ(0, str1.Length()); | 989 EXPECT_EQ(0, str1.Length()); |
| 945 | 990 |
| 946 uint32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; | 991 int32_t four[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; |
| 947 intptr_t four_len = sizeof(four) / sizeof(four[0]); | 992 intptr_t four_len = sizeof(four) / sizeof(four[0]); |
| 948 intptr_t expected_len = (four_len * 2); | 993 intptr_t expected_len = (four_len * 2); |
| 949 const String& str2 = String::Handle(String::New(four, four_len)); | 994 const String& str2 = String::Handle(String::New(four, four_len)); |
| 950 EXPECT(str2.IsTwoByteString()); | 995 EXPECT(str2.IsTwoByteString()); |
| 951 EXPECT_EQ(expected_len, str2.Length()); | 996 EXPECT_EQ(expected_len, str2.Length()); |
| 952 | 997 |
| 953 // Concat | 998 // Concat |
| 954 | 999 |
| 955 const String& str3 = String::Handle(String::Concat(str1, str2)); | 1000 const String& str3 = String::Handle(String::Concat(str1, str2)); |
| 956 EXPECT_EQ(expected_len, str3.Length()); | 1001 EXPECT_EQ(expected_len, str3.Length()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 981 EXPECT_EQ(expected_len, str6.Length()); | 1026 EXPECT_EQ(expected_len, str6.Length()); |
| 982 EXPECT(str6.Equals(str2)); | 1027 EXPECT(str6.Equals(str2)); |
| 983 | 1028 |
| 984 const Array& array3 = Array::Handle(Array::New(3)); | 1029 const Array& array3 = Array::Handle(Array::New(3)); |
| 985 EXPECT_EQ(3, array3.Length()); | 1030 EXPECT_EQ(3, array3.Length()); |
| 986 array3.SetAt(0, str2); | 1031 array3.SetAt(0, str2); |
| 987 array3.SetAt(1, str1); | 1032 array3.SetAt(1, str1); |
| 988 array3.SetAt(2, str2); | 1033 array3.SetAt(2, str2); |
| 989 const String& str7 = String::Handle(String::ConcatAll(array3)); | 1034 const String& str7 = String::Handle(String::ConcatAll(array3)); |
| 990 EXPECT(str7.IsTwoByteString()); | 1035 EXPECT(str7.IsTwoByteString()); |
| 991 uint32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, | 1036 int32_t fourfour[] = { 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1, |
| 992 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; | 1037 0x1D4D5, 0x1D4DE, 0x1D4E4, 0x1D4E1 }; |
| 993 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]); | 1038 intptr_t fourfour_len = sizeof(fourfour) / sizeof(fourfour[0]); |
| 994 EXPECT_EQ((fourfour_len * 2), str7.Length()); | 1039 EXPECT_EQ((fourfour_len * 2), str7.Length()); |
| 995 const String& fourfour_str = | 1040 const String& fourfour_str = |
| 996 String::Handle(String::New(fourfour, fourfour_len)); | 1041 String::Handle(String::New(fourfour, fourfour_len)); |
| 997 EXPECT(str7.Equals(fourfour_str)); | 1042 EXPECT(str7.Equals(fourfour_str)); |
| 998 } | 1043 } |
| 999 | 1044 |
| 1000 // Concatenate non-empty strings built from 4-byte elements. | 1045 // Concatenate non-empty strings built from 4-byte elements. |
| 1001 { | 1046 { |
| 1002 const uint32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1047 const int32_t one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF }; |
| 1003 intptr_t one_len = sizeof(one) / sizeof(one[0]); | 1048 intptr_t one_len = sizeof(one) / sizeof(one[0]); |
| 1004 const String& onestr = String::Handle(String::New(one, one_len)); | 1049 const String& onestr = String::Handle(String::New(one, one_len)); |
| 1005 EXPECT(onestr.IsTwoByteString()); | 1050 EXPECT(onestr.IsTwoByteString()); |
| 1006 EXPECT_EQ((one_len *2), onestr.Length()); | 1051 EXPECT_EQ((one_len *2), onestr.Length()); |
| 1007 | 1052 |
| 1008 const uint32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; | 1053 const int32_t two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; |
| 1009 intptr_t two_len = sizeof(two) / sizeof(two[0]); | 1054 intptr_t two_len = sizeof(two) / sizeof(two[0]); |
| 1010 const String& twostr = String::Handle(String::New(two, two_len)); | 1055 const String& twostr = String::Handle(String::New(two, two_len)); |
| 1011 EXPECT(twostr.IsTwoByteString()); | 1056 EXPECT(twostr.IsTwoByteString()); |
| 1012 EXPECT_EQ((two_len * 2), twostr.Length()); | 1057 EXPECT_EQ((two_len * 2), twostr.Length()); |
| 1013 | 1058 |
| 1014 // Concat | 1059 // Concat |
| 1015 | 1060 |
| 1016 const String& str1 = String::Handle(String::Concat(onestr, twostr)); | 1061 const String& str1 = String::Handle(String::Concat(onestr, twostr)); |
| 1017 EXPECT(str1.IsTwoByteString()); | 1062 EXPECT(str1.IsTwoByteString()); |
| 1018 const uint32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1063 const int32_t one_two[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, |
| 1019 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; | 1064 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9 }; |
| 1020 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); | 1065 intptr_t one_two_len = sizeof(one_two) / sizeof(one_two[0]); |
| 1021 EXPECT_EQ((one_two_len * 2), str1.Length()); | 1066 EXPECT_EQ((one_two_len * 2), str1.Length()); |
| 1022 const String& one_two_str = | 1067 const String& one_two_str = |
| 1023 String::Handle(String::New(one_two, one_two_len)); | 1068 String::Handle(String::New(one_two, one_two_len)); |
| 1024 EXPECT(str1.Equals(one_two_str)); | 1069 EXPECT(str1.Equals(one_two_str)); |
| 1025 | 1070 |
| 1026 const String& str2 = String::Handle(String::Concat(twostr, onestr)); | 1071 const String& str2 = String::Handle(String::Concat(twostr, onestr)); |
| 1027 EXPECT(str2.IsTwoByteString()); | 1072 EXPECT(str2.IsTwoByteString()); |
| 1028 const uint32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, | 1073 const int32_t two_one[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, 0x105D9, |
| 1029 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1074 0x105D0, 0x105D9, 0x105D9, 0x105DF }; |
| 1030 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); | 1075 intptr_t two_one_len = sizeof(two_one) / sizeof(two_one[0]); |
| 1031 EXPECT_EQ((two_one_len * 2), str2.Length()); | 1076 EXPECT_EQ((two_one_len * 2), str2.Length()); |
| 1032 const String& two_one_str = | 1077 const String& two_one_str = |
| 1033 String::Handle(String::New(two_one, two_one_len)); | 1078 String::Handle(String::New(two_one, two_one_len)); |
| 1034 EXPECT(str2.Equals(two_one_str)); | 1079 EXPECT(str2.Equals(two_one_str)); |
| 1035 | 1080 |
| 1036 // ConcatAll | 1081 // ConcatAll |
| 1037 | 1082 |
| 1038 const Array& array1 = Array::Handle(Array::New(2)); | 1083 const Array& array1 = Array::Handle(Array::New(2)); |
| 1039 EXPECT_EQ(2, array1.Length()); | 1084 EXPECT_EQ(2, array1.Length()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1053 EXPECT_EQ((two_one_len * 2), str4.Length()); | 1098 EXPECT_EQ((two_one_len * 2), str4.Length()); |
| 1054 EXPECT(str4.Equals(two_one_str)); | 1099 EXPECT(str4.Equals(two_one_str)); |
| 1055 | 1100 |
| 1056 const Array& array3 = Array::Handle(Array::New(3)); | 1101 const Array& array3 = Array::Handle(Array::New(3)); |
| 1057 EXPECT_EQ(3, array3.Length()); | 1102 EXPECT_EQ(3, array3.Length()); |
| 1058 array3.SetAt(0, onestr); | 1103 array3.SetAt(0, onestr); |
| 1059 array3.SetAt(1, twostr); | 1104 array3.SetAt(1, twostr); |
| 1060 array3.SetAt(2, onestr); | 1105 array3.SetAt(2, onestr); |
| 1061 const String& str5 = String::Handle(String::ConcatAll(array3)); | 1106 const String& str5 = String::Handle(String::ConcatAll(array3)); |
| 1062 EXPECT(str5.IsTwoByteString()); | 1107 EXPECT(str5.IsTwoByteString()); |
| 1063 const uint32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1108 const int32_t one_two_one[] = { 0x105D0, 0x105D9, 0x105D9, 0x105DF, |
| 1064 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1109 0x105E6, 0x105D5, 0x105D5, 0x105D9, |
| 1065 0x105D9, | 1110 0x105D9, |
| 1066 0x105D0, 0x105D9, 0x105D9, 0x105DF }; | 1111 0x105D0, 0x105D9, 0x105D9, 0x105DF }; |
| 1067 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); | 1112 intptr_t one_two_one_len = sizeof(one_two_one) / sizeof(one_two_one[0]); |
| 1068 EXPECT_EQ((one_two_one_len * 2), str5.Length()); | 1113 EXPECT_EQ((one_two_one_len * 2), str5.Length()); |
| 1069 const String& one_two_one_str = | 1114 const String& one_two_one_str = |
| 1070 String::Handle(String::New(one_two_one, one_two_one_len)); | 1115 String::Handle(String::New(one_two_one, one_two_one_len)); |
| 1071 EXPECT(str5.Equals(one_two_one_str)); | 1116 EXPECT(str5.Equals(one_two_one_str)); |
| 1072 | 1117 |
| 1073 const Array& array4 = Array::Handle(Array::New(3)); | 1118 const Array& array4 = Array::Handle(Array::New(3)); |
| 1074 EXPECT_EQ(3, array4.Length()); | 1119 EXPECT_EQ(3, array4.Length()); |
| 1075 array4.SetAt(0, twostr); | 1120 array4.SetAt(0, twostr); |
| 1076 array4.SetAt(1, onestr); | 1121 array4.SetAt(1, onestr); |
| 1077 array4.SetAt(2, twostr); | 1122 array4.SetAt(2, twostr); |
| 1078 const String& str6 = String::Handle(String::ConcatAll(array4)); | 1123 const String& str6 = String::Handle(String::ConcatAll(array4)); |
| 1079 EXPECT(str6.IsTwoByteString()); | 1124 EXPECT(str6.IsTwoByteString()); |
| 1080 const uint32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1125 const int32_t two_one_two[] = { 0x105E6, 0x105D5, 0x105D5, 0x105D9, |
| 1081 0x105D9, | 1126 0x105D9, |
| 1082 0x105D0, 0x105D9, 0x105D9, 0x105DF, | 1127 0x105D0, 0x105D9, 0x105D9, 0x105DF, |
| 1083 0x105E6, 0x105D5, 0x105D5, 0x105D9, | 1128 0x105E6, 0x105D5, 0x105D5, 0x105D9, |
| 1084 0x105D9 }; | 1129 0x105D9 }; |
| 1085 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); | 1130 intptr_t two_one_two_len = sizeof(two_one_two) / sizeof(two_one_two[0]); |
| 1086 EXPECT_EQ((two_one_two_len * 2), str6.Length()); | 1131 EXPECT_EQ((two_one_two_len * 2), str6.Length()); |
| 1087 const String& two_one_two_str = | 1132 const String& two_one_two_str = |
| 1088 String::Handle(String::New(two_one_two, two_one_two_len)); | 1133 String::Handle(String::New(two_one_two, two_one_two_len)); |
| 1089 EXPECT(str6.Equals(two_one_two_str)); | 1134 EXPECT(str6.Equals(two_one_two_str)); |
| 1090 } | 1135 } |
| 1091 | 1136 |
| 1092 // Concatenate 1-byte strings and 2-byte strings. | 1137 // Concatenate 1-byte strings and 2-byte strings. |
| 1093 { | 1138 { |
| 1094 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; | 1139 const uint8_t one[] = { 'o', 'n', 'e', ' ', 'b', 'y', 't', 'e' }; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 // characters. | 1336 // characters. |
| 1292 { | 1337 { |
| 1293 const char* src = | 1338 const char* src = |
| 1294 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1339 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
| 1295 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1340 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
| 1296 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1341 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
| 1297 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1342 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
| 1298 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1343 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
| 1299 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1344 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
| 1300 "\xEE\x80\x80\xEF\x80\x80"; | 1345 "\xEE\x80\x80\xEF\x80\x80"; |
| 1301 const intptr_t expected[] = { | 1346 const int32_t expected[] = { |
| 1302 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1347 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, |
| 1303 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1348 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, |
| 1304 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 | 1349 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 |
| 1305 }; | 1350 }; |
| 1306 const String& str = String::Handle(String::New(src)); | 1351 const String& str = String::Handle(String::New(src)); |
| 1307 EXPECT(str.IsTwoByteString()); | 1352 EXPECT(str.IsTwoByteString()); |
| 1308 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1353 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
| 1309 EXPECT_EQ(expected_size, str.Length()); | 1354 EXPECT_EQ(expected_size, str.Length()); |
| 1310 for (int i = 0; i < str.Length(); ++i) { | 1355 for (int i = 0; i < str.Length(); ++i) { |
| 1311 EXPECT_EQ(expected[i], str.CharAt(i)); | 1356 EXPECT_EQ(expected[i], str.CharAt(i)); |
| 1312 } | 1357 } |
| 1313 } | 1358 } |
| 1314 | 1359 |
| 1315 // Create a SMP 2-byte string from a UTF-8 string literal. | 1360 // Create a SMP 2-byte string from a UTF-8 string literal. |
| 1316 { | 1361 { |
| 1317 const char* src = | 1362 const char* src = |
| 1318 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" | 1363 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" |
| 1319 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; | 1364 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; |
| 1320 const intptr_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61, | 1365 const int32_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61, |
| 1321 0xd835, 0xdc62, 0xd835, 0xdc63 }; | 1366 0xd835, 0xdc62, 0xd835, 0xdc63 }; |
| 1322 const String& str = String::Handle(String::New(src)); | 1367 const String& str = String::Handle(String::New(src)); |
| 1323 EXPECT(str.IsTwoByteString()); | 1368 EXPECT(str.IsTwoByteString()); |
| 1324 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); | 1369 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); |
| 1325 EXPECT_EQ(expected_size, str.Length()); | 1370 EXPECT_EQ(expected_size, str.Length()); |
| 1326 for (int i = 0; i < str.Length(); ++i) { | 1371 for (int i = 0; i < str.Length(); ++i) { |
| 1327 EXPECT_EQ(expected[i], str.CharAt(i)); | 1372 EXPECT_EQ(expected[i], str.CharAt(i)); |
| 1328 } | 1373 } |
| 1329 } | 1374 } |
| 1330 | 1375 |
| 1331 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte | 1376 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte |
| 1332 // characters. | 1377 // characters. |
| 1333 { | 1378 { |
| 1334 const char* src = | 1379 const char* src = |
| 1335 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" | 1380 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" |
| 1336 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" | 1381 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" |
| 1337 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" | 1382 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" |
| 1338 "\xEC\x80\x80\xED\x80\x80\xEE\x80" | 1383 "\xEC\x80\x80\xED\x80\x80\xEE\x80" |
| 1339 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" | 1384 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" |
| 1340 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" | 1385 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" |
| 1341 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; | 1386 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; |
| 1342 const intptr_t expected[] = { | 1387 const int32_t expected[] = { |
| 1343 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, | 1388 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, |
| 1344 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, | 1389 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, |
| 1345 0xD838, 0xDC00, 0xD83c, 0xDC00, | 1390 0xD838, 0xDC00, 0xD83c, 0xDC00, |
| 1346 }; | 1391 }; |
| 1347 const String& str = String::Handle(String::New(src)); | 1392 const String& str = String::Handle(String::New(src)); |
| 1348 EXPECT(str.IsTwoByteString()); | 1393 EXPECT(str.IsTwoByteString()); |
| 1349 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1394 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
| 1350 EXPECT_EQ(expected_size, str.Length()); | 1395 EXPECT_EQ(expected_size, str.Length()); |
| 1351 for (int i = 0; i < str.Length(); ++i) { | 1396 for (int i = 0; i < str.Length(); ++i) { |
| 1352 EXPECT_EQ(expected[i], str.CharAt(i)); | 1397 EXPECT_EQ(expected[i], str.CharAt(i)); |
| 1353 } | 1398 } |
| 1354 } | 1399 } |
| 1355 | 1400 |
| 1356 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte | 1401 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte |
| 1357 // characters. | 1402 // characters. |
| 1358 { | 1403 { |
| 1359 const char* src = | 1404 const char* src = |
| 1360 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1405 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
| 1361 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1406 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
| 1362 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1407 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
| 1363 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1408 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
| 1364 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1409 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
| 1365 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1410 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
| 1366 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" | 1411 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" |
| 1367 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" | 1412 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" |
| 1368 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" | 1413 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" |
| 1369 "\x80\x80"; | 1414 "\x80\x80"; |
| 1370 const intptr_t expected[] = { | 1415 const int32_t expected[] = { |
| 1371 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1416 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, |
| 1372 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1417 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, |
| 1373 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, | 1418 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, |
| 1374 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, | 1419 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, |
| 1375 0xD83c, 0xDC00, | 1420 0xD83c, 0xDC00, |
| 1376 }; | 1421 }; |
| 1377 const String& str = String::Handle(String::New(src)); | 1422 const String& str = String::Handle(String::New(src)); |
| 1378 EXPECT(str.IsTwoByteString()); | 1423 EXPECT(str.IsTwoByteString()); |
| 1379 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1424 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
| 1380 EXPECT_EQ(expected_size, str.Length()); | 1425 EXPECT_EQ(expected_size, str.Length()); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 EXPECT_EQ(nine.raw(), Symbols::New("Neun")); | 1539 EXPECT_EQ(nine.raw(), Symbols::New("Neun")); |
| 1495 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); | 1540 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); |
| 1496 | 1541 |
| 1497 // Symbols from Strings. | 1542 // Symbols from Strings. |
| 1498 eins = String::New("Eins"); | 1543 eins = String::New("Eins"); |
| 1499 EXPECT(!eins.IsSymbol()); | 1544 EXPECT(!eins.IsSymbol()); |
| 1500 String& ein_symbol = String::Handle(Symbols::New(eins)); | 1545 String& ein_symbol = String::Handle(Symbols::New(eins)); |
| 1501 EXPECT_EQ(one.raw(), ein_symbol.raw()); | 1546 EXPECT_EQ(one.raw(), ein_symbol.raw()); |
| 1502 EXPECT(one.raw() != eins.raw()); | 1547 EXPECT(one.raw() != eins.raw()); |
| 1503 | 1548 |
| 1504 uint32_t char32[] = { 'E', 'l', 'f' }; | 1549 uint16_t char16[] = { 'E', 'l', 'f' }; |
| 1505 String& elf = String::Handle(Symbols::New(char32, 3)); | 1550 String& elf = String::Handle(Symbols::New(char16, 3)); |
| 1506 EXPECT(elf.IsSymbol()); | 1551 EXPECT(elf.IsSymbol()); |
| 1507 EXPECT_EQ(elf.raw(), Symbols::New("Elf")); | 1552 EXPECT_EQ(elf.raw(), Symbols::New("Elf")); |
| 1553 |
| 1554 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. |
| 1555 String& monkey = String::Handle(Symbols::New(monkey_utf16, 2)); |
| 1556 EXPECT(monkey.IsSymbol()); |
| 1557 EXPECT_EQ(monkey.raw(), Symbols::New("🐵")); |
| 1508 } | 1558 } |
| 1509 | 1559 |
| 1510 | 1560 |
| 1511 TEST_CASE(Bool) { | 1561 TEST_CASE(Bool) { |
| 1512 const Bool& true_value = Bool::Handle(Bool::True()); | 1562 const Bool& true_value = Bool::Handle(Bool::True()); |
| 1513 EXPECT(true_value.value()); | 1563 EXPECT(true_value.value()); |
| 1514 const Bool& false_value = Bool::Handle(Bool::False()); | 1564 const Bool& false_value = Bool::Handle(Bool::False()); |
| 1515 EXPECT(!false_value.value()); | 1565 EXPECT(!false_value.value()); |
| 1516 } | 1566 } |
| 1517 | 1567 |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 const char* source_chars = "This will not compile."; | 2023 const char* source_chars = "This will not compile."; |
| 1974 const String& url = String::Handle(String::New(url_chars)); | 2024 const String& url = String::Handle(String::New(url_chars)); |
| 1975 const String& source = String::Handle(String::New(source_chars)); | 2025 const String& source = String::Handle(String::New(source_chars)); |
| 1976 const Script& script = Script::Handle(Script::New(url, | 2026 const Script& script = Script::Handle(Script::New(url, |
| 1977 source, | 2027 source, |
| 1978 RawScript::kSourceTag)); | 2028 RawScript::kSourceTag)); |
| 1979 EXPECT(!script.IsNull()); | 2029 EXPECT(!script.IsNull()); |
| 1980 EXPECT(script.IsScript()); | 2030 EXPECT(script.IsScript()); |
| 1981 String& str = String::Handle(script.url()); | 2031 String& str = String::Handle(script.url()); |
| 1982 EXPECT_EQ(17, str.Length()); | 2032 EXPECT_EQ(17, str.Length()); |
| 1983 EXPECT_EQ('b', str.CharAt(0)); | 2033 EXPECT_EQ(ToUChar('b'), str.CharAt(0)); |
| 1984 EXPECT_EQ(':', str.CharAt(7)); | 2034 EXPECT_EQ(ToUChar(':'), str.CharAt(7)); |
| 1985 EXPECT_EQ('e', str.CharAt(16)); | 2035 EXPECT_EQ(ToUChar('e'), str.CharAt(16)); |
| 1986 str = script.Source(); | 2036 str = script.Source(); |
| 1987 EXPECT_EQ(22, str.Length()); | 2037 EXPECT_EQ(22, str.Length()); |
| 1988 EXPECT_EQ('T', str.CharAt(0)); | 2038 EXPECT_EQ(ToUChar('T'), str.CharAt(0)); |
| 1989 EXPECT_EQ('n', str.CharAt(10)); | 2039 EXPECT_EQ(ToUChar('n'), str.CharAt(10)); |
| 1990 EXPECT_EQ('.', str.CharAt(21)); | 2040 EXPECT_EQ(ToUChar('.'), str.CharAt(21)); |
| 1991 } | 2041 } |
| 1992 | 2042 |
| 1993 | 2043 |
| 1994 TEST_CASE(Context) { | 2044 TEST_CASE(Context) { |
| 1995 const int kNumVariables = 5; | 2045 const int kNumVariables = 5; |
| 1996 const Context& parent_context = Context::Handle(Context::New(0)); | 2046 const Context& parent_context = Context::Handle(Context::New(0)); |
| 1997 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); | 2047 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); |
| 1998 const Context& context = Context::Handle(Context::New(kNumVariables)); | 2048 const Context& context = Context::Handle(Context::New(kNumVariables)); |
| 1999 context.set_parent(parent_context); | 2049 context.set_parent(parent_context); |
| 2000 const Context& check_parent_context = Context::Handle(context.parent()); | 2050 const Context& check_parent_context = Context::Handle(context.parent()); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 Code& code = Code::Handle(Code::FinalizeCode( | 2270 Code& code = Code::Handle(Code::FinalizeCode( |
| 2221 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); | 2271 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); |
| 2222 Instructions& instructions = Instructions::Handle(code.instructions()); | 2272 Instructions& instructions = Instructions::Handle(code.instructions()); |
| 2223 typedef uword (*EmbedStringCode)(); | 2273 typedef uword (*EmbedStringCode)(); |
| 2224 uword retval = reinterpret_cast<EmbedStringCode>(instructions.EntryPoint())(); | 2274 uword retval = reinterpret_cast<EmbedStringCode>(instructions.EntryPoint())(); |
| 2225 EXPECT((retval & kSmiTagMask) == kHeapObjectTag); | 2275 EXPECT((retval & kSmiTagMask) == kHeapObjectTag); |
| 2226 String& string_object = String::Handle(); | 2276 String& string_object = String::Handle(); |
| 2227 string_object ^= reinterpret_cast<RawInstructions*>(retval); | 2277 string_object ^= reinterpret_cast<RawInstructions*>(retval); |
| 2228 EXPECT(string_object.Length() == expected_length); | 2278 EXPECT(string_object.Length() == expected_length); |
| 2229 for (int i = 0; i < expected_length; i ++) { | 2279 for (int i = 0; i < expected_length; i ++) { |
| 2230 EXPECT(string_object.CharAt(i) == kHello[i]); | 2280 EXPECT(string_object.CharAt(i) == static_cast<int32_t>(kHello[i])); |
| 2231 } | 2281 } |
| 2232 } | 2282 } |
| 2233 | 2283 |
| 2234 | 2284 |
| 2235 // Test for Embedded Smi object in the instructions. | 2285 // Test for Embedded Smi object in the instructions. |
| 2236 TEST_CASE(EmbedSmiInCode) { | 2286 TEST_CASE(EmbedSmiInCode) { |
| 2237 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); | 2287 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); |
| 2238 const intptr_t kSmiTestValue = 5; | 2288 const intptr_t kSmiTestValue = 5; |
| 2239 Assembler _assembler_; | 2289 Assembler _assembler_; |
| 2240 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); | 2290 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3031 isolate->heap()->CollectAllGarbage(); | 3081 isolate->heap()->CollectAllGarbage(); |
| 3032 EXPECT(weak1.key() == Object::null()); | 3082 EXPECT(weak1.key() == Object::null()); |
| 3033 EXPECT(weak1.value() == Object::null()); | 3083 EXPECT(weak1.value() == Object::null()); |
| 3034 EXPECT(weak2.key() == Object::null()); | 3084 EXPECT(weak2.key() == Object::null()); |
| 3035 EXPECT(weak2.value() == Object::null()); | 3085 EXPECT(weak2.value() == Object::null()); |
| 3036 } | 3086 } |
| 3037 | 3087 |
| 3038 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3088 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3039 | 3089 |
| 3040 } // namespace dart | 3090 } // namespace dart |
| OLD | NEW |