| 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 EXPECT(i.IsSmi()); | 455 EXPECT(i.IsSmi()); |
| 456 i = Integer::New(String::Handle(String::New("0"))); | 456 i = Integer::New(String::Handle(String::New("0"))); |
| 457 EXPECT(i.IsSmi()); | 457 EXPECT(i.IsSmi()); |
| 458 i = Integer::New(String::Handle(String::New("12345678901234567890"))); | 458 i = Integer::New(String::Handle(String::New("12345678901234567890"))); |
| 459 EXPECT(i.IsBigint()); | 459 EXPECT(i.IsBigint()); |
| 460 i = Integer::New(String::Handle(String::New("-12345678901234567890111222"))); | 460 i = Integer::New(String::Handle(String::New("-12345678901234567890111222"))); |
| 461 EXPECT(i.IsBigint()); | 461 EXPECT(i.IsBigint()); |
| 462 } | 462 } |
| 463 | 463 |
| 464 | 464 |
| 465 static unsigned char ToUChar(char x) { return static_cast<unsigned char>(x); } |
| 466 |
| 467 |
| 465 TEST_CASE(String) { | 468 TEST_CASE(String) { |
| 466 const char* kHello = "Hello World!"; | 469 const char* kHello = "Hello World!"; |
| 467 int32_t hello_len = strlen(kHello); | 470 int32_t hello_len = strlen(kHello); |
| 468 const String& str = String::Handle(String::New(kHello)); | 471 const String& str = String::Handle(String::New(kHello)); |
| 469 EXPECT(str.IsInstance()); | 472 EXPECT(str.IsInstance()); |
| 470 EXPECT(str.IsString()); | 473 EXPECT(str.IsString()); |
| 471 EXPECT(str.IsOneByteString()); | 474 EXPECT(str.IsOneByteString()); |
| 472 EXPECT(!str.IsTwoByteString()); | 475 EXPECT(!str.IsTwoByteString()); |
| 473 EXPECT(!str.IsNumber()); | 476 EXPECT(!str.IsNumber()); |
| 474 EXPECT_EQ(hello_len, str.Length()); | 477 EXPECT_EQ(hello_len, str.Length()); |
| 475 EXPECT_EQ('H', str.CharAt(0)); | 478 EXPECT_EQ(ToUChar('H'), str.CharAt(0)); |
| 476 EXPECT_EQ('e', str.CharAt(1)); | 479 EXPECT_EQ(ToUChar('e'), str.CharAt(1)); |
| 477 EXPECT_EQ('l', str.CharAt(2)); | 480 EXPECT_EQ(ToUChar('l'), str.CharAt(2)); |
| 478 EXPECT_EQ('l', str.CharAt(3)); | 481 EXPECT_EQ(ToUChar('l'), str.CharAt(3)); |
| 479 EXPECT_EQ('o', str.CharAt(4)); | 482 EXPECT_EQ(ToUChar('o'), str.CharAt(4)); |
| 480 EXPECT_EQ(' ', str.CharAt(5)); | 483 EXPECT_EQ(ToUChar(' '), str.CharAt(5)); |
| 481 EXPECT_EQ('W', str.CharAt(6)); | 484 EXPECT_EQ(ToUChar('W'), str.CharAt(6)); |
| 482 EXPECT_EQ('o', str.CharAt(7)); | 485 EXPECT_EQ(ToUChar('o'), str.CharAt(7)); |
| 483 EXPECT_EQ('r', str.CharAt(8)); | 486 EXPECT_EQ(ToUChar('r'), str.CharAt(8)); |
| 484 EXPECT_EQ('l', str.CharAt(9)); | 487 EXPECT_EQ(ToUChar('l'), str.CharAt(9)); |
| 485 EXPECT_EQ('d', str.CharAt(10)); | 488 EXPECT_EQ(ToUChar('d'), str.CharAt(10)); |
| 486 EXPECT_EQ('!', str.CharAt(11)); | 489 EXPECT_EQ(ToUChar('!'), str.CharAt(11)); |
| 487 | 490 |
| 488 const uint8_t* motto = | 491 const uint8_t* motto = |
| 489 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); | 492 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); |
| 490 const String& str2 = String::Handle(String::New(motto+7, 4)); | 493 const String& str2 = String::Handle(String::New(motto+7, 4)); |
| 491 EXPECT_EQ(4, str2.Length()); | 494 EXPECT_EQ(4, str2.Length()); |
| 492 EXPECT_EQ('b', str2.CharAt(0)); | 495 EXPECT_EQ(ToUChar('b'), str2.CharAt(0)); |
| 493 EXPECT_EQ('e', str2.CharAt(1)); | 496 EXPECT_EQ(ToUChar('e'), str2.CharAt(1)); |
| 494 EXPECT_EQ('s', str2.CharAt(2)); | 497 EXPECT_EQ(ToUChar('s'), str2.CharAt(2)); |
| 495 EXPECT_EQ('c', str2.CharAt(3)); | 498 EXPECT_EQ(ToUChar('c'), str2.CharAt(3)); |
| 496 | 499 |
| 497 const String& str3 = String::Handle(String::New(kHello)); | 500 const String& str3 = String::Handle(String::New(kHello)); |
| 498 EXPECT(str.Equals(str)); | 501 EXPECT(str.Equals(str)); |
| 499 EXPECT_EQ(str.Hash(), str.Hash()); | 502 EXPECT_EQ(str.Hash(), str.Hash()); |
| 500 EXPECT(!str.Equals(str2)); | 503 EXPECT(!str.Equals(str2)); |
| 501 EXPECT(str.Equals(str3)); | 504 EXPECT(str.Equals(str3)); |
| 502 EXPECT_EQ(str.Hash(), str3.Hash()); | 505 EXPECT_EQ(str.Hash(), str3.Hash()); |
| 503 EXPECT(str3.Equals(str)); | 506 EXPECT(str3.Equals(str)); |
| 504 | 507 |
| 505 const String& str4 = String::Handle(String::New("foo")); | 508 const String& str4 = String::Handle(String::New("foo")); |
| 506 const String& str5 = String::Handle(String::New("bar")); | 509 const String& str5 = String::Handle(String::New("bar")); |
| 507 const String& str6 = String::Handle(String::Concat(str4, str5)); | 510 const String& str6 = String::Handle(String::Concat(str4, str5)); |
| 508 const String& str7 = String::Handle(String::New("foobar")); | 511 const String& str7 = String::Handle(String::New("foobar")); |
| 509 EXPECT(str6.Equals(str7)); | 512 EXPECT(str6.Equals(str7)); |
| 510 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4)))); | 513 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4)))); |
| 511 | 514 |
| 512 const String& empty1 = String::Handle(String::New("")); | 515 const String& empty1 = String::Handle(String::New("")); |
| 513 const String& empty2 = String::Handle(String::New("")); | 516 const String& empty2 = String::Handle(String::New("")); |
| 514 EXPECT(empty1.Equals(empty2, 0, 0)); | 517 EXPECT(empty1.Equals(empty2, 0, 0)); |
| 515 | 518 |
| 516 const intptr_t kCharsLen = 8; | 519 const intptr_t kCharsLen = 8; |
| 517 const uint8_t chars[kCharsLen] = { 1, 2, 127, 64, 92, 0, 55, 55 }; | 520 const uint8_t chars[kCharsLen] = { 1, 2, 127, 64, 92, 0, 55, 55 }; |
| 518 const String& str8 = String::Handle(String::New(chars, kCharsLen)); | 521 const String& str8 = String::Handle(String::New(chars, kCharsLen)); |
| 519 EXPECT_EQ(kCharsLen, str8.Length()); | 522 EXPECT_EQ(kCharsLen, str8.Length()); |
| 520 EXPECT_EQ(1, str8.CharAt(0)); | 523 EXPECT_EQ(1u, str8.CharAt(0)); |
| 521 EXPECT_EQ(127, str8.CharAt(2)); | 524 EXPECT_EQ(127u, str8.CharAt(2)); |
| 522 EXPECT_EQ(64, str8.CharAt(3)); | 525 EXPECT_EQ(64u, str8.CharAt(3)); |
| 523 EXPECT_EQ(0, str8.CharAt(5)); | 526 EXPECT_EQ(0u, str8.CharAt(5)); |
| 524 EXPECT_EQ(55, str8.CharAt(6)); | 527 EXPECT_EQ(55u, str8.CharAt(6)); |
| 525 EXPECT_EQ(55, str8.CharAt(7)); | 528 EXPECT_EQ(55u, str8.CharAt(7)); |
| 526 const intptr_t kCharsIndex = 3; | 529 const intptr_t kCharsIndex = 3; |
| 527 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex)); | 530 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex)); |
| 528 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length()); | 531 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length()); |
| 529 EXPECT_EQ(64, sub1.CharAt(0)); | 532 EXPECT_EQ(64u, sub1.CharAt(0)); |
| 530 EXPECT_EQ(92, sub1.CharAt(1)); | 533 EXPECT_EQ(92u, sub1.CharAt(1)); |
| 531 EXPECT_EQ(0, sub1.CharAt(2)); | 534 EXPECT_EQ(0u, sub1.CharAt(2)); |
| 532 EXPECT_EQ(55, sub1.CharAt(3)); | 535 EXPECT_EQ(55u, sub1.CharAt(3)); |
| 533 EXPECT_EQ(55, sub1.CharAt(4)); | 536 EXPECT_EQ(55u, sub1.CharAt(4)); |
| 534 | 537 |
| 535 const intptr_t kWideCharsLen = 7; | 538 const intptr_t kWideCharsLen = 7; |
| 536 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; | 539 uint16_t wide_chars[kWideCharsLen] = { 'H', 'e', 'l', 'l', 'o', 256, '!' }; |
| 537 const String& two_str = String::Handle(String::New(wide_chars, | 540 const String& two_str = String::Handle(String::New(wide_chars, |
| 538 kWideCharsLen)); | 541 kWideCharsLen)); |
| 539 EXPECT(two_str.IsInstance()); | 542 EXPECT(two_str.IsInstance()); |
| 540 EXPECT(two_str.IsString()); | 543 EXPECT(two_str.IsString()); |
| 541 EXPECT(two_str.IsTwoByteString()); | 544 EXPECT(two_str.IsTwoByteString()); |
| 542 EXPECT(!two_str.IsOneByteString()); | 545 EXPECT(!two_str.IsOneByteString()); |
| 543 EXPECT_EQ(kWideCharsLen, two_str.Length()); | 546 EXPECT_EQ(kWideCharsLen, two_str.Length()); |
| 544 EXPECT_EQ('H', two_str.CharAt(0)); | 547 EXPECT_EQ(ToUChar('H'), two_str.CharAt(0)); |
| 545 EXPECT_EQ(256, two_str.CharAt(5)); | 548 EXPECT_EQ(256u, two_str.CharAt(5)); |
| 546 const intptr_t kWideCharsIndex = 3; | 549 const intptr_t kWideCharsIndex = 3; |
| 547 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); | 550 const String& sub2 = String::Handle(String::SubString(two_str, kCharsIndex)); |
| 548 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); | 551 EXPECT_EQ((kWideCharsLen - kWideCharsIndex), sub2.Length()); |
| 549 EXPECT_EQ('l', sub2.CharAt(0)); | 552 EXPECT_EQ(ToUChar('l'), sub2.CharAt(0)); |
| 550 EXPECT_EQ('o', sub2.CharAt(1)); | 553 EXPECT_EQ(ToUChar('o'), sub2.CharAt(1)); |
| 551 EXPECT_EQ(256, sub2.CharAt(2)); | 554 EXPECT_EQ(256u, sub2.CharAt(2)); |
| 552 EXPECT_EQ('!', sub2.CharAt(3)); | 555 EXPECT_EQ(ToUChar('!'), sub2.CharAt(3)); |
| 553 | 556 |
| 554 { | 557 { |
| 555 const String& str1 = String::Handle(String::New("My.create")); | 558 const String& str1 = String::Handle(String::New("My.create")); |
| 556 const String& str2 = String::Handle(String::New("My")); | 559 const String& str2 = String::Handle(String::New("My")); |
| 557 const String& str3 = String::Handle(String::New("create")); | 560 const String& str3 = String::Handle(String::New("create")); |
| 558 EXPECT_EQ(true, str1.StartsWith(str2)); | 561 EXPECT_EQ(true, str1.StartsWith(str2)); |
| 559 EXPECT_EQ(false, str1.StartsWith(str3)); | 562 EXPECT_EQ(false, str1.StartsWith(str3)); |
| 560 } | 563 } |
| 561 | 564 |
| 562 const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; | 565 const uint32_t four_chars[] = { 'C', 0xFF, 'h', 0xFFFF, 'a', 0x10FFFF, 'r' }; |
| 563 const String& four_str = String::Handle(String::New(four_chars, 7)); | 566 const String& four_str = String::Handle(String::New(four_chars, 7)); |
| 564 EXPECT_EQ(four_str.Hash(), four_str.Hash()); | 567 EXPECT_EQ(four_str.Hash(), four_str.Hash()); |
| 565 EXPECT(four_str.IsTwoByteString()); | 568 EXPECT(four_str.IsTwoByteString()); |
| 566 EXPECT(!four_str.IsOneByteString()); | 569 EXPECT(!four_str.IsOneByteString()); |
| 567 EXPECT_EQ(8, four_str.Length()); | 570 EXPECT_EQ(8, four_str.Length()); |
| 568 EXPECT_EQ('C', four_str.CharAt(0)); | 571 EXPECT_EQ(ToUChar('C'), four_str.CharAt(0)); |
| 569 EXPECT_EQ(0xFF, four_str.CharAt(1)); | 572 EXPECT_EQ(0xFFu, four_str.CharAt(1)); |
| 570 EXPECT_EQ('h', four_str.CharAt(2)); | 573 EXPECT_EQ(ToUChar('h'), four_str.CharAt(2)); |
| 571 EXPECT_EQ(0xFFFF, four_str.CharAt(3)); | 574 EXPECT_EQ(0xFFFFu, four_str.CharAt(3)); |
| 572 EXPECT_EQ('a', four_str.CharAt(4)); | 575 EXPECT_EQ(ToUChar('a'), four_str.CharAt(4)); |
| 573 EXPECT_EQ(0xDBFF, four_str.CharAt(5)); | 576 EXPECT_EQ(0xDBFFu, four_str.CharAt(5)); |
| 574 EXPECT_EQ(0xDFFF, four_str.CharAt(6)); | 577 EXPECT_EQ(0xDFFFu, four_str.CharAt(6)); |
| 575 EXPECT_EQ('r', four_str.CharAt(7)); | 578 EXPECT_EQ(ToUChar('r'), four_str.CharAt(7)); |
| 576 | 579 |
| 577 // Create a 1-byte string from an array of 2-byte elements. | 580 // Create a 1-byte string from an array of 2-byte elements. |
| 578 { | 581 { |
| 579 const uint16_t char16[] = { 0x00, 0x1F, 0x7F }; | 582 const uint16_t char16[] = { 0x00, 0x1F, 0x7F }; |
| 580 const String& str8 = String::Handle(String::New(char16, 3)); | 583 const String& str8 = String::Handle(String::New(char16, 3)); |
| 581 EXPECT(str8.IsOneByteString()); | 584 EXPECT(str8.IsOneByteString()); |
| 582 EXPECT(!str8.IsTwoByteString()); | 585 EXPECT(!str8.IsTwoByteString()); |
| 583 EXPECT_EQ(0x00, str8.CharAt(0)); | 586 EXPECT_EQ(0x00u, str8.CharAt(0)); |
| 584 EXPECT_EQ(0x1F, str8.CharAt(1)); | 587 EXPECT_EQ(0x1Fu, str8.CharAt(1)); |
| 585 EXPECT_EQ(0x7F, str8.CharAt(2)); | 588 EXPECT_EQ(0x7Fu, str8.CharAt(2)); |
| 586 } | 589 } |
| 587 | 590 |
| 588 // Create a 1-byte string from an array of 4-byte elements. | 591 // Create a 1-byte string from an array of 4-byte elements. |
| 589 { | 592 { |
| 590 const uint32_t char32[] = { 0x00, 0x1F, 0x7F }; | 593 const uint32_t char32[] = { 0x00, 0x1F, 0x7F }; |
| 591 const String& str8 = String::Handle(String::New(char32, 3)); | 594 const String& str8 = String::Handle(String::New(char32, 3)); |
| 592 EXPECT(str8.IsOneByteString()); | 595 EXPECT(str8.IsOneByteString()); |
| 593 EXPECT(!str8.IsTwoByteString()); | 596 EXPECT(!str8.IsTwoByteString()); |
| 594 EXPECT_EQ(0x00, str8.CharAt(0)); | 597 EXPECT_EQ(0x00u, str8.CharAt(0)); |
| 595 EXPECT_EQ(0x1F, str8.CharAt(1)); | 598 EXPECT_EQ(0x1Fu, str8.CharAt(1)); |
| 596 EXPECT_EQ(0x7F, str8.CharAt(2)); | 599 EXPECT_EQ(0x7Fu, str8.CharAt(2)); |
| 597 } | 600 } |
| 598 | 601 |
| 599 // Create a 2-byte string from an array of 4-byte elements. | 602 // Create a 2-byte string from an array of 4-byte elements. |
| 600 { | 603 { |
| 601 const uint32_t char32[] = { 0, 0x7FFF, 0xFFFF }; | 604 const uint32_t char32[] = { 0, 0x7FFF, 0xFFFF }; |
| 602 const String& str16 = String::Handle(String::New(char32, 3)); | 605 const String& str16 = String::Handle(String::New(char32, 3)); |
| 603 EXPECT(!str16.IsOneByteString()); | 606 EXPECT(!str16.IsOneByteString()); |
| 604 EXPECT(str16.IsTwoByteString()); | 607 EXPECT(str16.IsTwoByteString()); |
| 605 EXPECT_EQ(0x0000, str16.CharAt(0)); | 608 EXPECT_EQ(0x0000u, str16.CharAt(0)); |
| 606 EXPECT_EQ(0x7FFF, str16.CharAt(1)); | 609 EXPECT_EQ(0x7FFFu, str16.CharAt(1)); |
| 607 EXPECT_EQ(0xFFFF, str16.CharAt(2)); | 610 EXPECT_EQ(0xFFFFu, str16.CharAt(2)); |
| 608 } | 611 } |
| 609 } | 612 } |
| 610 | 613 |
| 611 | 614 |
| 612 TEST_CASE(StringFormat) { | 615 TEST_CASE(StringFormat) { |
| 613 const char* hello_str = "Hello World!"; | 616 const char* hello_str = "Hello World!"; |
| 614 const String& str = | 617 const String& str = |
| 615 String::Handle(String::NewFormatted("Hello %s!", "World")); | 618 String::Handle(String::NewFormatted("Hello %s!", "World")); |
| 616 EXPECT(str.IsInstance()); | 619 EXPECT(str.IsInstance()); |
| 617 EXPECT(str.IsString()); | 620 EXPECT(str.IsString()); |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 // characters. | 1294 // characters. |
| 1292 { | 1295 { |
| 1293 const char* src = | 1296 const char* src = |
| 1294 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1297 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
| 1295 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1298 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
| 1296 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1299 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
| 1297 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1300 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
| 1298 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1301 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
| 1299 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1302 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
| 1300 "\xEE\x80\x80\xEF\x80\x80"; | 1303 "\xEE\x80\x80\xEF\x80\x80"; |
| 1301 const intptr_t expected[] = { | 1304 const uint32_t expected[] = { |
| 1302 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1305 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, |
| 1303 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1306 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, |
| 1304 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 | 1307 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000 |
| 1305 }; | 1308 }; |
| 1306 const String& str = String::Handle(String::New(src)); | 1309 const String& str = String::Handle(String::New(src)); |
| 1307 EXPECT(str.IsTwoByteString()); | 1310 EXPECT(str.IsTwoByteString()); |
| 1308 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1311 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
| 1309 EXPECT_EQ(expected_size, str.Length()); | 1312 EXPECT_EQ(expected_size, str.Length()); |
| 1310 for (int i = 0; i < str.Length(); ++i) { | 1313 for (int i = 0; i < str.Length(); ++i) { |
| 1311 EXPECT_EQ(expected[i], str.CharAt(i)); | 1314 EXPECT_EQ(expected[i], str.CharAt(i)); |
| 1312 } | 1315 } |
| 1313 } | 1316 } |
| 1314 | 1317 |
| 1315 // Create a SMP 2-byte string from a UTF-8 string literal. | 1318 // Create a SMP 2-byte string from a UTF-8 string literal. |
| 1316 { | 1319 { |
| 1317 const char* src = | 1320 const char* src = |
| 1318 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" | 1321 "\xF0\x9D\x91\xA0\xF0\x9D\x91\xA1" |
| 1319 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; | 1322 "\xF0\x9D\x91\xA2\xF0\x9D\x91\xA3"; |
| 1320 const intptr_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61, | 1323 const uint32_t expected[] = { 0xd835, 0xdc60, 0xd835, 0xdc61, |
| 1321 0xd835, 0xdc62, 0xd835, 0xdc63 }; | 1324 0xd835, 0xdc62, 0xd835, 0xdc63 }; |
| 1322 const String& str = String::Handle(String::New(src)); | 1325 const String& str = String::Handle(String::New(src)); |
| 1323 EXPECT(str.IsTwoByteString()); | 1326 EXPECT(str.IsTwoByteString()); |
| 1324 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); | 1327 intptr_t expected_size = (sizeof(expected) / sizeof(expected[0])); |
| 1325 EXPECT_EQ(expected_size, str.Length()); | 1328 EXPECT_EQ(expected_size, str.Length()); |
| 1326 for (int i = 0; i < str.Length(); ++i) { | 1329 for (int i = 0; i < str.Length(); ++i) { |
| 1327 EXPECT_EQ(expected[i], str.CharAt(i)); | 1330 EXPECT_EQ(expected[i], str.CodeUnitAt(i)); |
| 1328 } | 1331 } |
| 1329 } | 1332 } |
| 1330 | 1333 |
| 1331 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte | 1334 // Create a 2-byte string from UTF-8 encoded 2- and 4-byte |
| 1332 // characters. | 1335 // characters. |
| 1333 { | 1336 { |
| 1334 const char* src = | 1337 const char* src = |
| 1335 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" | 1338 "\xE0\xA8\x80\xE0\xAC\x80\xE0\xB0" |
| 1336 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" | 1339 "\x80\xE0\xB4\x80\xE0\xB8\x80\xE0" |
| 1337 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" | 1340 "\xBC\x80\xEA\x80\x80\xEB\x80\x80" |
| 1338 "\xEC\x80\x80\xED\x80\x80\xEE\x80" | 1341 "\xEC\x80\x80\xED\x80\x80\xEE\x80" |
| 1339 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" | 1342 "\x80\xEF\x80\x80\xF0\x9A\x80\x80" |
| 1340 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" | 1343 "\xF0\x9B\x80\x80\xF0\x9D\x80\x80" |
| 1341 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; | 1344 "\xF0\x9E\x80\x80\xF0\x9F\x80\x80"; |
| 1342 const intptr_t expected[] = { | 1345 const uint32_t expected[] = { |
| 1343 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, | 1346 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, |
| 1344 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, | 1347 0xD000, 0xE000, 0xF000, 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, |
| 1345 0xD838, 0xDC00, 0xD83c, 0xDC00, | 1348 0xD838, 0xDC00, 0xD83c, 0xDC00, |
| 1346 }; | 1349 }; |
| 1347 const String& str = String::Handle(String::New(src)); | 1350 const String& str = String::Handle(String::New(src)); |
| 1348 EXPECT(str.IsTwoByteString()); | 1351 EXPECT(str.IsTwoByteString()); |
| 1349 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1352 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
| 1350 EXPECT_EQ(expected_size, str.Length()); | 1353 EXPECT_EQ(expected_size, str.Length()); |
| 1351 for (int i = 0; i < str.Length(); ++i) { | 1354 for (int i = 0; i < str.Length(); ++i) { |
| 1352 EXPECT_EQ(expected[i], str.CharAt(i)); | 1355 EXPECT_EQ(expected[i], str.CodeUnitAt(i)); |
| 1353 } | 1356 } |
| 1354 } | 1357 } |
| 1355 | 1358 |
| 1356 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte | 1359 // Create a 2-byte string from UTF-8 encoded 1-, 2- and 4-byte |
| 1357 // characters. | 1360 // characters. |
| 1358 { | 1361 { |
| 1359 const char* src = | 1362 const char* src = |
| 1360 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" | 1363 "\x0A\x0B\x0D\x0C\x0E\x0F\xC2\xA0" |
| 1361 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" | 1364 "\xC2\xB0\xC3\x80\xC3\x90\xC3\xA0" |
| 1362 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" | 1365 "\xC3\xB0\xE0\xA8\x80\xE0\xAC\x80" |
| 1363 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" | 1366 "\xE0\xB0\x80\xE0\xB4\x80\xE0\xB8" |
| 1364 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" | 1367 "\x80\xE0\xBC\x80\xEA\x80\x80\xEB" |
| 1365 "\x80\x80\xEC\x80\x80\xED\x80\x80" | 1368 "\x80\x80\xEC\x80\x80\xED\x80\x80" |
| 1366 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" | 1369 "\xEE\x80\x80\xEF\x80\x80\xF0\x9A" |
| 1367 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" | 1370 "\x80\x80\xF0\x9B\x80\x80\xF0\x9D" |
| 1368 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" | 1371 "\x80\x80\xF0\x9E\x80\x80\xF0\x9F" |
| 1369 "\x80\x80"; | 1372 "\x80\x80"; |
| 1370 const intptr_t expected[] = { | 1373 const uint32_t expected[] = { |
| 1371 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, | 1374 0x000A, 0x000B, 0x000D, 0x000C, 0x000E, 0x000F, 0x00A0, 0x00B0, |
| 1372 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, | 1375 0x00C0, 0x00D0, 0x00E0, 0x00F0, 0x0A00, 0x0B00, 0x0C00, 0x0D00, |
| 1373 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, | 1376 0x0E00, 0x0F00, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, |
| 1374 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, | 1377 0xD828, 0xDC00, 0xD82c, 0xDC00, 0xD834, 0xDC00, 0xD838, 0xDC00, |
| 1375 0xD83c, 0xDC00, | 1378 0xD83c, 0xDC00, |
| 1376 }; | 1379 }; |
| 1377 const String& str = String::Handle(String::New(src)); | 1380 const String& str = String::Handle(String::New(src)); |
| 1378 EXPECT(str.IsTwoByteString()); | 1381 EXPECT(str.IsTwoByteString()); |
| 1379 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); | 1382 intptr_t expected_size = sizeof(expected) / sizeof(expected[0]); |
| 1380 EXPECT_EQ(expected_size, str.Length()); | 1383 EXPECT_EQ(expected_size, str.Length()); |
| 1381 for (int i = 0; i < str.Length(); ++i) { | 1384 for (int i = 0; i < str.Length(); ++i) { |
| 1382 EXPECT_EQ(expected[i], str.CharAt(i)); | 1385 EXPECT_EQ(expected[i], str.CodeUnitAt(i)); |
| 1383 } | 1386 } |
| 1384 } | 1387 } |
| 1385 } | 1388 } |
| 1386 | 1389 |
| 1387 | 1390 |
| 1388 TEST_CASE(ExternalOneByteString) { | 1391 TEST_CASE(ExternalOneByteString) { |
| 1389 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 }; | 1392 uint8_t characters[] = { 0xF6, 0xF1, 0xE9 }; |
| 1390 intptr_t len = ARRAY_SIZE(characters); | 1393 intptr_t len = ARRAY_SIZE(characters); |
| 1391 | 1394 |
| 1392 const String& str = | 1395 const String& str = |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 const char* source_chars = "This will not compile."; | 1976 const char* source_chars = "This will not compile."; |
| 1974 const String& url = String::Handle(String::New(url_chars)); | 1977 const String& url = String::Handle(String::New(url_chars)); |
| 1975 const String& source = String::Handle(String::New(source_chars)); | 1978 const String& source = String::Handle(String::New(source_chars)); |
| 1976 const Script& script = Script::Handle(Script::New(url, | 1979 const Script& script = Script::Handle(Script::New(url, |
| 1977 source, | 1980 source, |
| 1978 RawScript::kSourceTag)); | 1981 RawScript::kSourceTag)); |
| 1979 EXPECT(!script.IsNull()); | 1982 EXPECT(!script.IsNull()); |
| 1980 EXPECT(script.IsScript()); | 1983 EXPECT(script.IsScript()); |
| 1981 String& str = String::Handle(script.url()); | 1984 String& str = String::Handle(script.url()); |
| 1982 EXPECT_EQ(17, str.Length()); | 1985 EXPECT_EQ(17, str.Length()); |
| 1983 EXPECT_EQ('b', str.CharAt(0)); | 1986 EXPECT_EQ(ToUChar('b'), str.CharAt(0)); |
| 1984 EXPECT_EQ(':', str.CharAt(7)); | 1987 EXPECT_EQ(ToUChar(':'), str.CharAt(7)); |
| 1985 EXPECT_EQ('e', str.CharAt(16)); | 1988 EXPECT_EQ(ToUChar('e'), str.CharAt(16)); |
| 1986 str = script.Source(); | 1989 str = script.Source(); |
| 1987 EXPECT_EQ(22, str.Length()); | 1990 EXPECT_EQ(22, str.Length()); |
| 1988 EXPECT_EQ('T', str.CharAt(0)); | 1991 EXPECT_EQ(ToUChar('T'), str.CharAt(0)); |
| 1989 EXPECT_EQ('n', str.CharAt(10)); | 1992 EXPECT_EQ(ToUChar('n'), str.CharAt(10)); |
| 1990 EXPECT_EQ('.', str.CharAt(21)); | 1993 EXPECT_EQ(ToUChar('.'), str.CharAt(21)); |
| 1991 } | 1994 } |
| 1992 | 1995 |
| 1993 | 1996 |
| 1994 TEST_CASE(Context) { | 1997 TEST_CASE(Context) { |
| 1995 const int kNumVariables = 5; | 1998 const int kNumVariables = 5; |
| 1996 const Context& parent_context = Context::Handle(Context::New(0)); | 1999 const Context& parent_context = Context::Handle(Context::New(0)); |
| 1997 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); | 2000 EXPECT_EQ(parent_context.isolate(), Isolate::Current()); |
| 1998 const Context& context = Context::Handle(Context::New(kNumVariables)); | 2001 const Context& context = Context::Handle(Context::New(kNumVariables)); |
| 1999 context.set_parent(parent_context); | 2002 context.set_parent(parent_context); |
| 2000 const Context& check_parent_context = Context::Handle(context.parent()); | 2003 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( | 2223 Code& code = Code::Handle(Code::FinalizeCode( |
| 2221 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); | 2224 *CreateFunction("Test_EmbedStringInCode"), &_assembler_)); |
| 2222 Instructions& instructions = Instructions::Handle(code.instructions()); | 2225 Instructions& instructions = Instructions::Handle(code.instructions()); |
| 2223 typedef uword (*EmbedStringCode)(); | 2226 typedef uword (*EmbedStringCode)(); |
| 2224 uword retval = reinterpret_cast<EmbedStringCode>(instructions.EntryPoint())(); | 2227 uword retval = reinterpret_cast<EmbedStringCode>(instructions.EntryPoint())(); |
| 2225 EXPECT((retval & kSmiTagMask) == kHeapObjectTag); | 2228 EXPECT((retval & kSmiTagMask) == kHeapObjectTag); |
| 2226 String& string_object = String::Handle(); | 2229 String& string_object = String::Handle(); |
| 2227 string_object ^= reinterpret_cast<RawInstructions*>(retval); | 2230 string_object ^= reinterpret_cast<RawInstructions*>(retval); |
| 2228 EXPECT(string_object.Length() == expected_length); | 2231 EXPECT(string_object.Length() == expected_length); |
| 2229 for (int i = 0; i < expected_length; i ++) { | 2232 for (int i = 0; i < expected_length; i ++) { |
| 2230 EXPECT(string_object.CharAt(i) == kHello[i]); | 2233 EXPECT(string_object.CharAt(i) == static_cast<uint32_t>(kHello[i])); |
| 2231 } | 2234 } |
| 2232 } | 2235 } |
| 2233 | 2236 |
| 2234 | 2237 |
| 2235 // Test for Embedded Smi object in the instructions. | 2238 // Test for Embedded Smi object in the instructions. |
| 2236 TEST_CASE(EmbedSmiInCode) { | 2239 TEST_CASE(EmbedSmiInCode) { |
| 2237 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); | 2240 extern void GenerateEmbedSmiInCode(Assembler* assembler, intptr_t value); |
| 2238 const intptr_t kSmiTestValue = 5; | 2241 const intptr_t kSmiTestValue = 5; |
| 2239 Assembler _assembler_; | 2242 Assembler _assembler_; |
| 2240 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); | 2243 GenerateEmbedSmiInCode(&_assembler_, kSmiTestValue); |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3031 isolate->heap()->CollectAllGarbage(); | 3034 isolate->heap()->CollectAllGarbage(); |
| 3032 EXPECT(weak1.key() == Object::null()); | 3035 EXPECT(weak1.key() == Object::null()); |
| 3033 EXPECT(weak1.value() == Object::null()); | 3036 EXPECT(weak1.value() == Object::null()); |
| 3034 EXPECT(weak2.key() == Object::null()); | 3037 EXPECT(weak2.key() == Object::null()); |
| 3035 EXPECT(weak2.value() == Object::null()); | 3038 EXPECT(weak2.value() == Object::null()); |
| 3036 } | 3039 } |
| 3037 | 3040 |
| 3038 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3041 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3039 | 3042 |
| 3040 } // namespace dart | 3043 } // namespace dart |
| OLD | NEW |