| 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/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 const String& abcd = String::Handle(String::New("abcd")); | 261 const String& abcd = String::Handle(String::New("abcd")); |
| 262 const String& abce = String::Handle(String::New("abce")); | 262 const String& abce = String::Handle(String::New("abce")); |
| 263 EXPECT_EQ(0, abcd.CompareTo(abcd)); | 263 EXPECT_EQ(0, abcd.CompareTo(abcd)); |
| 264 EXPECT_EQ(0, abce.CompareTo(abce)); | 264 EXPECT_EQ(0, abce.CompareTo(abce)); |
| 265 EXPECT(abcd.CompareTo(abce) < 0); | 265 EXPECT(abcd.CompareTo(abce) < 0); |
| 266 EXPECT(abce.CompareTo(abcd) > 0); | 266 EXPECT(abce.CompareTo(abcd) > 0); |
| 267 | 267 |
| 268 const int kMonkeyLen = 4; | 268 const int kMonkeyLen = 4; |
| 269 const uint8_t monkey_utf8[kMonkeyLen] = { 0xf0, 0x9f, 0x90, 0xb5 }; | 269 const uint8_t monkey_utf8[kMonkeyLen] = { 0xf0, 0x9f, 0x90, 0xb5 }; |
| 270 const String& monkey_face = | 270 const String& monkey_face = |
| 271 String::Handle(String::New(monkey_utf8, kMonkeyLen)); | 271 String::Handle(String::FromUTF8(monkey_utf8, kMonkeyLen)); |
| 272 const int kDogLen = 4; | 272 const int kDogLen = 4; |
| 273 // 0x1f436 DOG FACE. | 273 // 0x1f436 DOG FACE. |
| 274 const uint8_t dog_utf8[kDogLen] = { 0xf0, 0x9f, 0x90, 0xb6 }; | 274 const uint8_t dog_utf8[kDogLen] = { 0xf0, 0x9f, 0x90, 0xb6 }; |
| 275 const String& dog_face = String::Handle(String::New(dog_utf8, kDogLen)); | 275 const String& dog_face = |
| 276 String::Handle(String::FromUTF8(dog_utf8, kDogLen)); |
| 276 EXPECT_EQ(0, monkey_face.CompareTo(monkey_face)); | 277 EXPECT_EQ(0, monkey_face.CompareTo(monkey_face)); |
| 277 EXPECT_EQ(0, dog_face.CompareTo(dog_face)); | 278 EXPECT_EQ(0, dog_face.CompareTo(dog_face)); |
| 278 EXPECT(monkey_face.CompareTo(dog_face) < 0); | 279 EXPECT(monkey_face.CompareTo(dog_face) < 0); |
| 279 EXPECT(dog_face.CompareTo(monkey_face) > 0); | 280 EXPECT(dog_face.CompareTo(monkey_face) > 0); |
| 280 | 281 |
| 281 const int kDominoLen = 4; | 282 const int kDominoLen = 4; |
| 282 // 0x1f036 DOMINO TILE HORIZONTAL-00-05. | 283 // 0x1f036 DOMINO TILE HORIZONTAL-00-05. |
| 283 const uint8_t domino_utf8[kDominoLen] = { 0xf0, 0x9f, 0x80, 0xb6 }; | 284 const uint8_t domino_utf8[kDominoLen] = { 0xf0, 0x9f, 0x80, 0xb6 }; |
| 284 const String& domino = String::Handle(String::New(domino_utf8, kDominoLen)); | 285 const String& domino = |
| 286 String::Handle(String::FromUTF8(domino_utf8, kDominoLen)); |
| 285 EXPECT_EQ(0, domino.CompareTo(domino)); | 287 EXPECT_EQ(0, domino.CompareTo(domino)); |
| 286 EXPECT(domino.CompareTo(dog_face) < 0); | 288 EXPECT(domino.CompareTo(dog_face) < 0); |
| 287 EXPECT(domino.CompareTo(monkey_face) < 0); | 289 EXPECT(domino.CompareTo(monkey_face) < 0); |
| 288 EXPECT(dog_face.CompareTo(domino) > 0); | 290 EXPECT(dog_face.CompareTo(domino) > 0); |
| 289 EXPECT(monkey_face.CompareTo(domino) > 0); | 291 EXPECT(monkey_face.CompareTo(domino) > 0); |
| 290 | 292 |
| 291 EXPECT(abcd.CompareTo(monkey_face) < 0); | 293 EXPECT(abcd.CompareTo(monkey_face) < 0); |
| 292 EXPECT(abce.CompareTo(monkey_face) < 0); | 294 EXPECT(abce.CompareTo(monkey_face) < 0); |
| 293 EXPECT(abcd.CompareTo(domino) < 0); | 295 EXPECT(abcd.CompareTo(domino) < 0); |
| 294 EXPECT(abce.CompareTo(domino) < 0); | 296 EXPECT(abce.CompareTo(domino) < 0); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 EXPECT_EQ(' ', str.CharAt(5)); | 511 EXPECT_EQ(' ', str.CharAt(5)); |
| 510 EXPECT_EQ('W', str.CharAt(6)); | 512 EXPECT_EQ('W', str.CharAt(6)); |
| 511 EXPECT_EQ('o', str.CharAt(7)); | 513 EXPECT_EQ('o', str.CharAt(7)); |
| 512 EXPECT_EQ('r', str.CharAt(8)); | 514 EXPECT_EQ('r', str.CharAt(8)); |
| 513 EXPECT_EQ('l', str.CharAt(9)); | 515 EXPECT_EQ('l', str.CharAt(9)); |
| 514 EXPECT_EQ('d', str.CharAt(10)); | 516 EXPECT_EQ('d', str.CharAt(10)); |
| 515 EXPECT_EQ('!', str.CharAt(11)); | 517 EXPECT_EQ('!', str.CharAt(11)); |
| 516 | 518 |
| 517 const uint8_t* motto = | 519 const uint8_t* motto = |
| 518 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); | 520 reinterpret_cast<const uint8_t*>("Dart's bescht wos je hets gits"); |
| 519 const String& str2 = String::Handle(String::New(motto+7, 4)); | 521 const String& str2 = String::Handle(String::FromUTF8(motto+7, 4)); |
| 520 EXPECT_EQ(4, str2.Length()); | 522 EXPECT_EQ(4, str2.Length()); |
| 521 EXPECT_EQ('b', str2.CharAt(0)); | 523 EXPECT_EQ('b', str2.CharAt(0)); |
| 522 EXPECT_EQ('e', str2.CharAt(1)); | 524 EXPECT_EQ('e', str2.CharAt(1)); |
| 523 EXPECT_EQ('s', str2.CharAt(2)); | 525 EXPECT_EQ('s', str2.CharAt(2)); |
| 524 EXPECT_EQ('c', str2.CharAt(3)); | 526 EXPECT_EQ('c', str2.CharAt(3)); |
| 525 | 527 |
| 526 const String& str3 = String::Handle(String::New(kHello)); | 528 const String& str3 = String::Handle(String::New(kHello)); |
| 527 EXPECT(str.Equals(str)); | 529 EXPECT(str.Equals(str)); |
| 528 EXPECT_EQ(str.Hash(), str.Hash()); | 530 EXPECT_EQ(str.Hash(), str.Hash()); |
| 529 EXPECT(!str.Equals(str2)); | 531 EXPECT(!str.Equals(str2)); |
| 530 EXPECT(str.Equals(str3)); | 532 EXPECT(str.Equals(str3)); |
| 531 EXPECT_EQ(str.Hash(), str3.Hash()); | 533 EXPECT_EQ(str.Hash(), str3.Hash()); |
| 532 EXPECT(str3.Equals(str)); | 534 EXPECT(str3.Equals(str)); |
| 533 | 535 |
| 534 const String& str4 = String::Handle(String::New("foo")); | 536 const String& str4 = String::Handle(String::New("foo")); |
| 535 const String& str5 = String::Handle(String::New("bar")); | 537 const String& str5 = String::Handle(String::New("bar")); |
| 536 const String& str6 = String::Handle(String::Concat(str4, str5)); | 538 const String& str6 = String::Handle(String::Concat(str4, str5)); |
| 537 const String& str7 = String::Handle(String::New("foobar")); | 539 const String& str7 = String::Handle(String::New("foobar")); |
| 538 EXPECT(str6.Equals(str7)); | 540 EXPECT(str6.Equals(str7)); |
| 539 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4)))); | 541 EXPECT(!str6.Equals(Smi::Handle(Smi::New(4)))); |
| 540 | 542 |
| 541 const String& empty1 = String::Handle(String::New("")); | 543 const String& empty1 = String::Handle(String::New("")); |
| 542 const String& empty2 = String::Handle(String::New("")); | 544 const String& empty2 = String::Handle(String::New("")); |
| 543 EXPECT(empty1.Equals(empty2, 0, 0)); | 545 EXPECT(empty1.Equals(empty2, 0, 0)); |
| 544 | 546 |
| 545 const intptr_t kCharsLen = 8; | 547 const intptr_t kCharsLen = 8; |
| 546 const uint8_t chars[kCharsLen] = { 1, 2, 127, 64, 92, 0, 55, 55 }; | 548 const uint8_t chars[kCharsLen] = { 1, 2, 127, 64, 92, 0, 55, 55 }; |
| 547 const String& str8 = String::Handle(String::New(chars, kCharsLen)); | 549 const String& str8 = String::Handle(String::FromUTF8(chars, kCharsLen)); |
| 548 EXPECT_EQ(kCharsLen, str8.Length()); | 550 EXPECT_EQ(kCharsLen, str8.Length()); |
| 549 EXPECT_EQ(1, str8.CharAt(0)); | 551 EXPECT_EQ(1, str8.CharAt(0)); |
| 550 EXPECT_EQ(127, str8.CharAt(2)); | 552 EXPECT_EQ(127, str8.CharAt(2)); |
| 551 EXPECT_EQ(64, str8.CharAt(3)); | 553 EXPECT_EQ(64, str8.CharAt(3)); |
| 552 EXPECT_EQ(0, str8.CharAt(5)); | 554 EXPECT_EQ(0, str8.CharAt(5)); |
| 553 EXPECT_EQ(55, str8.CharAt(6)); | 555 EXPECT_EQ(55, str8.CharAt(6)); |
| 554 EXPECT_EQ(55, str8.CharAt(7)); | 556 EXPECT_EQ(55, str8.CharAt(7)); |
| 555 const intptr_t kCharsIndex = 3; | 557 const intptr_t kCharsIndex = 3; |
| 556 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex)); | 558 const String& sub1 = String::Handle(String::SubString(str8, kCharsIndex)); |
| 557 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length()); | 559 EXPECT_EQ((kCharsLen - kCharsIndex), sub1.Length()); |
| (...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); | 1558 EXPECT_EQ(ten.raw(), Symbols::New("Zehn")); |
| 1557 | 1559 |
| 1558 // Symbols from Strings. | 1560 // Symbols from Strings. |
| 1559 eins = String::New("Eins"); | 1561 eins = String::New("Eins"); |
| 1560 EXPECT(!eins.IsSymbol()); | 1562 EXPECT(!eins.IsSymbol()); |
| 1561 String& ein_symbol = String::Handle(Symbols::New(eins)); | 1563 String& ein_symbol = String::Handle(Symbols::New(eins)); |
| 1562 EXPECT_EQ(one.raw(), ein_symbol.raw()); | 1564 EXPECT_EQ(one.raw(), ein_symbol.raw()); |
| 1563 EXPECT(one.raw() != eins.raw()); | 1565 EXPECT(one.raw() != eins.raw()); |
| 1564 | 1566 |
| 1565 uint16_t char16[] = { 'E', 'l', 'f' }; | 1567 uint16_t char16[] = { 'E', 'l', 'f' }; |
| 1566 String& elf1 = String::Handle(Symbols::New(char16, 3)); | 1568 String& elf1 = String::Handle(Symbols::FromUTF16(char16, 3)); |
| 1567 int32_t char32[] = { 'E', 'l', 'f' }; | 1569 int32_t char32[] = { 'E', 'l', 'f' }; |
| 1568 String& elf2 = String::Handle(Symbols::New(char32, 3)); | 1570 String& elf2 = String::Handle(Symbols::FromUTF32(char32, 3)); |
| 1569 EXPECT(elf1.IsSymbol()); | 1571 EXPECT(elf1.IsSymbol()); |
| 1570 EXPECT(elf2.IsSymbol()); | 1572 EXPECT(elf2.IsSymbol()); |
| 1571 EXPECT_EQ(elf1.raw(), Symbols::New("Elf")); | 1573 EXPECT_EQ(elf1.raw(), Symbols::New("Elf")); |
| 1572 EXPECT_EQ(elf2.raw(), Symbols::New("Elf")); | 1574 EXPECT_EQ(elf2.raw(), Symbols::New("Elf")); |
| 1573 } | 1575 } |
| 1574 | 1576 |
| 1575 | 1577 |
| 1576 TEST_CASE(SymbolUnicode) { | 1578 TEST_CASE(SymbolUnicode) { |
| 1577 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. | 1579 uint16_t monkey_utf16[] = { 0xd83d, 0xdc35 }; // Unicode Monkey Face. |
| 1578 String& monkey = String::Handle(Symbols::New(monkey_utf16, 2)); | 1580 String& monkey = String::Handle(Symbols::FromUTF16(monkey_utf16, 2)); |
| 1579 EXPECT(monkey.IsSymbol()); | 1581 EXPECT(monkey.IsSymbol()); |
| 1580 const char monkey_utf8[] = {0xf0, 0x9f, 0x90, 0xb5, 0}; | 1582 const char monkey_utf8[] = {0xf0, 0x9f, 0x90, 0xb5, 0}; |
| 1581 EXPECT_EQ(monkey.raw(), Symbols::New(monkey_utf8)); | 1583 EXPECT_EQ(monkey.raw(), Symbols::New(monkey_utf8)); |
| 1582 | 1584 |
| 1583 int32_t kMonkeyFace = 0x1f435; | 1585 int32_t kMonkeyFace = 0x1f435; |
| 1584 String& monkey2 = String::Handle(Symbols::FromCharCode(kMonkeyFace)); | 1586 String& monkey2 = String::Handle(Symbols::FromCharCode(kMonkeyFace)); |
| 1585 EXPECT_EQ(monkey.raw(), monkey2.raw()); | 1587 EXPECT_EQ(monkey.raw(), monkey2.raw()); |
| 1586 | 1588 |
| 1587 // Unicode cat face with tears of joy. | 1589 // Unicode cat face with tears of joy. |
| 1588 int32_t kCatFaceWithTearsOfJoy = 0x1f639; | 1590 int32_t kCatFaceWithTearsOfJoy = 0x1f639; |
| 1589 String& cat = String::Handle(Symbols::FromCharCode(kCatFaceWithTearsOfJoy)); | 1591 String& cat = String::Handle(Symbols::FromCharCode(kCatFaceWithTearsOfJoy)); |
| 1590 | 1592 |
| 1591 uint16_t cat_utf16[] = { 0xd83d, 0xde39 }; | 1593 uint16_t cat_utf16[] = { 0xd83d, 0xde39 }; |
| 1592 String& cat2 = String::Handle(Symbols::New(cat_utf16, 2)); | 1594 String& cat2 = String::Handle(Symbols::FromUTF16(cat_utf16, 2)); |
| 1593 EXPECT(cat2.IsSymbol()); | 1595 EXPECT(cat2.IsSymbol()); |
| 1594 EXPECT_EQ(cat2.raw(), cat.raw()); | 1596 EXPECT_EQ(cat2.raw(), cat.raw()); |
| 1595 } | 1597 } |
| 1596 | 1598 |
| 1597 | 1599 |
| 1598 TEST_CASE(Bool) { | 1600 TEST_CASE(Bool) { |
| 1599 const Bool& true_value = Bool::Handle(Bool::True()); | 1601 const Bool& true_value = Bool::Handle(Bool::True()); |
| 1600 EXPECT(true_value.value()); | 1602 EXPECT(true_value.value()); |
| 1601 const Bool& false_value = Bool::Handle(Bool::False()); | 1603 const Bool& false_value = Bool::Handle(Bool::False()); |
| 1602 EXPECT(!false_value.value()); | 1604 EXPECT(!false_value.value()); |
| (...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3248 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); | 3250 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); |
| 3249 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); | 3251 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); |
| 3250 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); | 3252 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); |
| 3251 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); | 3253 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); |
| 3252 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); | 3254 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); |
| 3253 } | 3255 } |
| 3254 | 3256 |
| 3255 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3257 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3256 | 3258 |
| 3257 } // namespace dart | 3259 } // namespace dart |
| OLD | NEW |