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/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 Mint& mint1 = Mint::Handle(); | 331 Mint& mint1 = Mint::Handle(); |
332 mint1 ^= Integer::New(DART_2PART_UINT64_C(0x7FFFFFFF, 100)); | 332 mint1 ^= Integer::New(DART_2PART_UINT64_C(0x7FFFFFFF, 100)); |
333 Mint& mint2 = Mint::Handle(); | 333 Mint& mint2 = Mint::Handle(); |
334 mint2 ^= Integer::New(-DART_2PART_UINT64_C(0x7FFFFFFF, 100)); | 334 mint2 ^= Integer::New(-DART_2PART_UINT64_C(0x7FFFFFFF, 100)); |
335 EXPECT_EQ(-1, a.CompareWith(mint1)); | 335 EXPECT_EQ(-1, a.CompareWith(mint1)); |
336 EXPECT_EQ(1, a.CompareWith(mint2)); | 336 EXPECT_EQ(1, a.CompareWith(mint2)); |
337 EXPECT_EQ(-1, c.CompareWith(mint1)); | 337 EXPECT_EQ(-1, c.CompareWith(mint1)); |
338 EXPECT_EQ(1, c.CompareWith(mint2)); | 338 EXPECT_EQ(1, c.CompareWith(mint2)); |
339 | 339 |
340 if (!Bigint::IsDisabled()) { | 340 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); |
341 Bigint& big1 = | 341 Bigint& big2 = |
342 Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); | 342 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); |
343 Bigint& big2 = | 343 EXPECT_EQ(-1, a.CompareWith(big1)); |
344 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); | 344 EXPECT_EQ(1, a.CompareWith(big2)); |
345 EXPECT_EQ(-1, a.CompareWith(big1)); | 345 EXPECT_EQ(-1, c.CompareWith(big1)); |
346 EXPECT_EQ(1, a.CompareWith(big2)); | 346 EXPECT_EQ(1, c.CompareWith(big2)); |
347 EXPECT_EQ(-1, c.CompareWith(big1)); | |
348 EXPECT_EQ(1, c.CompareWith(big2)); | |
349 } | |
350 } | 347 } |
351 | 348 |
352 ISOLATE_UNIT_TEST_CASE(StringCompareTo) { | 349 ISOLATE_UNIT_TEST_CASE(StringCompareTo) { |
353 const String& abcd = String::Handle(String::New("abcd")); | 350 const String& abcd = String::Handle(String::New("abcd")); |
354 const String& abce = String::Handle(String::New("abce")); | 351 const String& abce = String::Handle(String::New("abce")); |
355 EXPECT_EQ(0, abcd.CompareTo(abcd)); | 352 EXPECT_EQ(0, abcd.CompareTo(abcd)); |
356 EXPECT_EQ(0, abce.CompareTo(abce)); | 353 EXPECT_EQ(0, abce.CompareTo(abce)); |
357 EXPECT(abcd.CompareTo(abce) < 0); | 354 EXPECT(abcd.CompareTo(abce) < 0); |
358 EXPECT(abce.CompareTo(abcd) > 0); | 355 EXPECT(abce.CompareTo(abcd) > 0); |
359 | 356 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 | 485 |
489 Mint& c = Mint::Handle(); | 486 Mint& c = Mint::Handle(); |
490 c ^= Integer::New(-DART_2PART_UINT64_C(3, 0)); | 487 c ^= Integer::New(-DART_2PART_UINT64_C(3, 0)); |
491 Smi& smi1 = Smi::Handle(Smi::New(4)); | 488 Smi& smi1 = Smi::Handle(Smi::New(4)); |
492 Smi& smi2 = Smi::Handle(Smi::New(-4)); | 489 Smi& smi2 = Smi::Handle(Smi::New(-4)); |
493 EXPECT_EQ(1, a.CompareWith(smi1)); | 490 EXPECT_EQ(1, a.CompareWith(smi1)); |
494 EXPECT_EQ(1, a.CompareWith(smi2)); | 491 EXPECT_EQ(1, a.CompareWith(smi2)); |
495 EXPECT_EQ(-1, c.CompareWith(smi1)); | 492 EXPECT_EQ(-1, c.CompareWith(smi1)); |
496 EXPECT_EQ(-1, c.CompareWith(smi2)); | 493 EXPECT_EQ(-1, c.CompareWith(smi2)); |
497 | 494 |
498 if (!Bigint::IsDisabled()) { | 495 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); |
499 Bigint& big1 = | 496 Bigint& big2 = |
500 Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); | 497 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); |
501 Bigint& big2 = | 498 EXPECT_EQ(-1, a.CompareWith(big1)); |
502 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); | 499 EXPECT_EQ(1, a.CompareWith(big2)); |
503 EXPECT_EQ(-1, a.CompareWith(big1)); | 500 EXPECT_EQ(-1, c.CompareWith(big1)); |
504 EXPECT_EQ(1, a.CompareWith(big2)); | 501 EXPECT_EQ(1, c.CompareWith(big2)); |
505 EXPECT_EQ(-1, c.CompareWith(big1)); | |
506 EXPECT_EQ(1, c.CompareWith(big2)); | |
507 } | |
508 | 502 |
509 int64_t mint_value = DART_2PART_UINT64_C(0x7FFFFFFF, 64); | 503 int64_t mint_value = DART_2PART_UINT64_C(0x7FFFFFFF, 64); |
510 const String& mint_string = String::Handle(String::New("0x7FFFFFFF00000064")); | 504 const String& mint_string = String::Handle(String::New("0x7FFFFFFF00000064")); |
511 Mint& mint1 = Mint::Handle(); | 505 Mint& mint1 = Mint::Handle(); |
512 mint1 ^= Integer::NewCanonical(mint_string); | 506 mint1 ^= Integer::NewCanonical(mint_string); |
513 Mint& mint2 = Mint::Handle(); | 507 Mint& mint2 = Mint::Handle(); |
514 mint2 ^= Integer::NewCanonical(mint_string); | 508 mint2 ^= Integer::NewCanonical(mint_string); |
515 EXPECT_EQ(mint1.value(), mint_value); | 509 EXPECT_EQ(mint1.value(), mint_value); |
516 EXPECT_EQ(mint2.value(), mint_value); | 510 EXPECT_EQ(mint2.value(), mint_value); |
517 EXPECT_EQ(mint1.raw(), mint2.raw()); | 511 EXPECT_EQ(mint1.raw(), mint2.raw()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 EXPECT_EQ(2.0, dbl1.value()); | 589 EXPECT_EQ(2.0, dbl1.value()); |
596 | 590 |
597 // Disallow legacy form. | 591 // Disallow legacy form. |
598 const String& dbl_str2 = String::Handle(String::New("2.0d")); | 592 const String& dbl_str2 = String::Handle(String::New("2.0d")); |
599 const Double& dbl2 = Double::Handle(Double::New(dbl_str2)); | 593 const Double& dbl2 = Double::Handle(Double::New(dbl_str2)); |
600 EXPECT(dbl2.IsNull()); | 594 EXPECT(dbl2.IsNull()); |
601 } | 595 } |
602 } | 596 } |
603 | 597 |
604 ISOLATE_UNIT_TEST_CASE(Bigint) { | 598 ISOLATE_UNIT_TEST_CASE(Bigint) { |
605 if (Bigint::IsDisabled()) { | |
606 return; | |
607 } | |
608 | |
609 Bigint& b = Bigint::Handle(); | 599 Bigint& b = Bigint::Handle(); |
610 EXPECT(b.IsNull()); | 600 EXPECT(b.IsNull()); |
611 const char* cstr = "18446744073709551615000"; | 601 const char* cstr = "18446744073709551615000"; |
612 const String& test = String::Handle(String::New(cstr)); | 602 const String& test = String::Handle(String::New(cstr)); |
613 b ^= Integer::NewCanonical(test); | 603 b ^= Integer::NewCanonical(test); |
614 const char* str = b.ToCString(); | 604 const char* str = b.ToCString(); |
615 EXPECT_STREQ(cstr, str); | 605 EXPECT_STREQ(cstr, str); |
616 | 606 |
617 int64_t t64 = DART_2PART_UINT64_C(1, 0); | 607 int64_t t64 = DART_2PART_UINT64_C(1, 0); |
618 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64)); | 608 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64)); |
(...skipping 27 matching lines...) Expand all Loading... |
646 ISOLATE_UNIT_TEST_CASE(Integer) { | 636 ISOLATE_UNIT_TEST_CASE(Integer) { |
647 Integer& i = Integer::Handle(); | 637 Integer& i = Integer::Handle(); |
648 i = Integer::NewCanonical(String::Handle(String::New("12"))); | 638 i = Integer::NewCanonical(String::Handle(String::New("12"))); |
649 EXPECT(i.IsSmi()); | 639 EXPECT(i.IsSmi()); |
650 i = Integer::NewCanonical(String::Handle(String::New("-120"))); | 640 i = Integer::NewCanonical(String::Handle(String::New("-120"))); |
651 EXPECT(i.IsSmi()); | 641 EXPECT(i.IsSmi()); |
652 i = Integer::NewCanonical(String::Handle(String::New("0"))); | 642 i = Integer::NewCanonical(String::Handle(String::New("0"))); |
653 EXPECT(i.IsSmi()); | 643 EXPECT(i.IsSmi()); |
654 i = Integer::NewCanonical( | 644 i = Integer::NewCanonical( |
655 String::Handle(String::New("12345678901234567890"))); | 645 String::Handle(String::New("12345678901234567890"))); |
656 EXPECT(FLAG_limit_ints_to_64_bits ? i.IsNull() : i.IsBigint()); | 646 EXPECT(i.IsBigint()); |
657 i = Integer::NewCanonical( | 647 i = Integer::NewCanonical( |
658 String::Handle(String::New("-12345678901234567890111222"))); | 648 String::Handle(String::New("-12345678901234567890111222"))); |
659 EXPECT(FLAG_limit_ints_to_64_bits ? i.IsNull() : i.IsBigint()); | 649 EXPECT(i.IsBigint()); |
660 } | 650 } |
661 | 651 |
662 ISOLATE_UNIT_TEST_CASE(String) { | 652 ISOLATE_UNIT_TEST_CASE(String) { |
663 const char* kHello = "Hello World!"; | 653 const char* kHello = "Hello World!"; |
664 int32_t hello_len = strlen(kHello); | 654 int32_t hello_len = strlen(kHello); |
665 const String& str = String::Handle(String::New(kHello)); | 655 const String& str = String::Handle(String::New(kHello)); |
666 EXPECT(str.IsInstance()); | 656 EXPECT(str.IsInstance()); |
667 EXPECT(str.IsString()); | 657 EXPECT(str.IsString()); |
668 EXPECT(str.IsOneByteString()); | 658 EXPECT(str.IsOneByteString()); |
669 EXPECT(!str.IsTwoByteString()); | 659 EXPECT(!str.IsTwoByteString()); |
(...skipping 3497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4167 EXPECT_STREQ( | 4157 EXPECT_STREQ( |
4168 "{\"type\":\"@Instance\"," | 4158 "{\"type\":\"@Instance\"," |
4169 "\"_vmType\":\"Mint\"," | 4159 "\"_vmType\":\"Mint\"," |
4170 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," | 4160 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," |
4171 "\"name\":\"_Mint\",\"_vmName\":\"\"}," | 4161 "\"name\":\"_Mint\",\"_vmName\":\"\"}," |
4172 "\"kind\":\"Int\"," | 4162 "\"kind\":\"Int\"," |
4173 "\"id\":\"\",\"valueAsString\":\"-9223372036854775808\"}", | 4163 "\"id\":\"\",\"valueAsString\":\"-9223372036854775808\"}", |
4174 buffer); | 4164 buffer); |
4175 } | 4165 } |
4176 // Bigint reference | 4166 // Bigint reference |
4177 if (!Bigint::IsDisabled()) { | 4167 { |
4178 JSONStream js; | 4168 JSONStream js; |
4179 const String& bigint_str = | 4169 const String& bigint_str = |
4180 String::Handle(String::New("44444444444444444444444444444444")); | 4170 String::Handle(String::New("44444444444444444444444444444444")); |
4181 const Integer& bigint = Integer::Handle(Integer::New(bigint_str)); | 4171 const Integer& bigint = Integer::Handle(Integer::New(bigint_str)); |
4182 bigint.PrintJSON(&js, true); | 4172 bigint.PrintJSON(&js, true); |
4183 ElideJSONSubstring("classes", js.ToCString(), buffer); | 4173 ElideJSONSubstring("classes", js.ToCString(), buffer); |
4184 ElideJSONSubstring("objects", buffer, buffer); | 4174 ElideJSONSubstring("objects", buffer, buffer); |
4185 ElideJSONSubstring("_Bigint@", buffer, buffer); | 4175 ElideJSONSubstring("_Bigint@", buffer, buffer); |
4186 EXPECT_STREQ( | 4176 EXPECT_STREQ( |
4187 "{\"type\":\"@Instance\"," | 4177 "{\"type\":\"@Instance\"," |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4642 // utf32->utf16 conversion. | 4632 // utf32->utf16 conversion. |
4643 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, | 4633 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, |
4644 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; | 4634 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; |
4645 | 4635 |
4646 const String& str = | 4636 const String& str = |
4647 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); | 4637 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); |
4648 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); | 4638 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); |
4649 } | 4639 } |
4650 | 4640 |
4651 } // namespace dart | 4641 } // namespace dart |
OLD | NEW |