Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: runtime/vm/object_test.cc

Issue 2980223002: Reapply CL "Option to truncate integers to 64 bits, part 2" (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/regexp_assembler_ir.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); 340 if (!Bigint::IsDisabled()) {
341 Bigint& big2 = 341 Bigint& big1 =
342 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); 342 Bigint::Handle(Bigint::NewFromCString("10000000000000000000"));
343 EXPECT_EQ(-1, a.CompareWith(big1)); 343 Bigint& big2 =
344 EXPECT_EQ(1, a.CompareWith(big2)); 344 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000"));
345 EXPECT_EQ(-1, c.CompareWith(big1)); 345 EXPECT_EQ(-1, a.CompareWith(big1));
346 EXPECT_EQ(1, c.CompareWith(big2)); 346 EXPECT_EQ(1, a.CompareWith(big2));
347 EXPECT_EQ(-1, c.CompareWith(big1));
348 EXPECT_EQ(1, c.CompareWith(big2));
349 }
347 } 350 }
348 351
349 ISOLATE_UNIT_TEST_CASE(StringCompareTo) { 352 ISOLATE_UNIT_TEST_CASE(StringCompareTo) {
350 const String& abcd = String::Handle(String::New("abcd")); 353 const String& abcd = String::Handle(String::New("abcd"));
351 const String& abce = String::Handle(String::New("abce")); 354 const String& abce = String::Handle(String::New("abce"));
352 EXPECT_EQ(0, abcd.CompareTo(abcd)); 355 EXPECT_EQ(0, abcd.CompareTo(abcd));
353 EXPECT_EQ(0, abce.CompareTo(abce)); 356 EXPECT_EQ(0, abce.CompareTo(abce));
354 EXPECT(abcd.CompareTo(abce) < 0); 357 EXPECT(abcd.CompareTo(abce) < 0);
355 EXPECT(abce.CompareTo(abcd) > 0); 358 EXPECT(abce.CompareTo(abcd) > 0);
356 359
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 488
486 Mint& c = Mint::Handle(); 489 Mint& c = Mint::Handle();
487 c ^= Integer::New(-DART_2PART_UINT64_C(3, 0)); 490 c ^= Integer::New(-DART_2PART_UINT64_C(3, 0));
488 Smi& smi1 = Smi::Handle(Smi::New(4)); 491 Smi& smi1 = Smi::Handle(Smi::New(4));
489 Smi& smi2 = Smi::Handle(Smi::New(-4)); 492 Smi& smi2 = Smi::Handle(Smi::New(-4));
490 EXPECT_EQ(1, a.CompareWith(smi1)); 493 EXPECT_EQ(1, a.CompareWith(smi1));
491 EXPECT_EQ(1, a.CompareWith(smi2)); 494 EXPECT_EQ(1, a.CompareWith(smi2));
492 EXPECT_EQ(-1, c.CompareWith(smi1)); 495 EXPECT_EQ(-1, c.CompareWith(smi1));
493 EXPECT_EQ(-1, c.CompareWith(smi2)); 496 EXPECT_EQ(-1, c.CompareWith(smi2));
494 497
495 Bigint& big1 = Bigint::Handle(Bigint::NewFromCString("10000000000000000000")); 498 if (!Bigint::IsDisabled()) {
496 Bigint& big2 = 499 Bigint& big1 =
497 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000")); 500 Bigint::Handle(Bigint::NewFromCString("10000000000000000000"));
498 EXPECT_EQ(-1, a.CompareWith(big1)); 501 Bigint& big2 =
499 EXPECT_EQ(1, a.CompareWith(big2)); 502 Bigint::Handle(Bigint::NewFromCString("-10000000000000000000"));
500 EXPECT_EQ(-1, c.CompareWith(big1)); 503 EXPECT_EQ(-1, a.CompareWith(big1));
501 EXPECT_EQ(1, c.CompareWith(big2)); 504 EXPECT_EQ(1, a.CompareWith(big2));
505 EXPECT_EQ(-1, c.CompareWith(big1));
506 EXPECT_EQ(1, c.CompareWith(big2));
507 }
502 508
503 int64_t mint_value = DART_2PART_UINT64_C(0x7FFFFFFF, 64); 509 int64_t mint_value = DART_2PART_UINT64_C(0x7FFFFFFF, 64);
504 const String& mint_string = String::Handle(String::New("0x7FFFFFFF00000064")); 510 const String& mint_string = String::Handle(String::New("0x7FFFFFFF00000064"));
505 Mint& mint1 = Mint::Handle(); 511 Mint& mint1 = Mint::Handle();
506 mint1 ^= Integer::NewCanonical(mint_string); 512 mint1 ^= Integer::NewCanonical(mint_string);
507 Mint& mint2 = Mint::Handle(); 513 Mint& mint2 = Mint::Handle();
508 mint2 ^= Integer::NewCanonical(mint_string); 514 mint2 ^= Integer::NewCanonical(mint_string);
509 EXPECT_EQ(mint1.value(), mint_value); 515 EXPECT_EQ(mint1.value(), mint_value);
510 EXPECT_EQ(mint2.value(), mint_value); 516 EXPECT_EQ(mint2.value(), mint_value);
511 EXPECT_EQ(mint1.raw(), mint2.raw()); 517 EXPECT_EQ(mint1.raw(), mint2.raw());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 EXPECT_EQ(2.0, dbl1.value()); 595 EXPECT_EQ(2.0, dbl1.value());
590 596
591 // Disallow legacy form. 597 // Disallow legacy form.
592 const String& dbl_str2 = String::Handle(String::New("2.0d")); 598 const String& dbl_str2 = String::Handle(String::New("2.0d"));
593 const Double& dbl2 = Double::Handle(Double::New(dbl_str2)); 599 const Double& dbl2 = Double::Handle(Double::New(dbl_str2));
594 EXPECT(dbl2.IsNull()); 600 EXPECT(dbl2.IsNull());
595 } 601 }
596 } 602 }
597 603
598 ISOLATE_UNIT_TEST_CASE(Bigint) { 604 ISOLATE_UNIT_TEST_CASE(Bigint) {
605 if (Bigint::IsDisabled()) {
606 return;
607 }
608
599 Bigint& b = Bigint::Handle(); 609 Bigint& b = Bigint::Handle();
600 EXPECT(b.IsNull()); 610 EXPECT(b.IsNull());
601 const char* cstr = "18446744073709551615000"; 611 const char* cstr = "18446744073709551615000";
602 const String& test = String::Handle(String::New(cstr)); 612 const String& test = String::Handle(String::New(cstr));
603 b ^= Integer::NewCanonical(test); 613 b ^= Integer::NewCanonical(test);
604 const char* str = b.ToCString(); 614 const char* str = b.ToCString();
605 EXPECT_STREQ(cstr, str); 615 EXPECT_STREQ(cstr, str);
606 616
607 int64_t t64 = DART_2PART_UINT64_C(1, 0); 617 int64_t t64 = DART_2PART_UINT64_C(1, 0);
608 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64)); 618 Bigint& big = Bigint::Handle(Bigint::NewFromInt64(t64));
(...skipping 27 matching lines...) Expand all
636 ISOLATE_UNIT_TEST_CASE(Integer) { 646 ISOLATE_UNIT_TEST_CASE(Integer) {
637 Integer& i = Integer::Handle(); 647 Integer& i = Integer::Handle();
638 i = Integer::NewCanonical(String::Handle(String::New("12"))); 648 i = Integer::NewCanonical(String::Handle(String::New("12")));
639 EXPECT(i.IsSmi()); 649 EXPECT(i.IsSmi());
640 i = Integer::NewCanonical(String::Handle(String::New("-120"))); 650 i = Integer::NewCanonical(String::Handle(String::New("-120")));
641 EXPECT(i.IsSmi()); 651 EXPECT(i.IsSmi());
642 i = Integer::NewCanonical(String::Handle(String::New("0"))); 652 i = Integer::NewCanonical(String::Handle(String::New("0")));
643 EXPECT(i.IsSmi()); 653 EXPECT(i.IsSmi());
644 i = Integer::NewCanonical( 654 i = Integer::NewCanonical(
645 String::Handle(String::New("12345678901234567890"))); 655 String::Handle(String::New("12345678901234567890")));
646 EXPECT(i.IsBigint()); 656 EXPECT(FLAG_limit_ints_to_64_bits ? i.IsNull() : i.IsBigint());
647 i = Integer::NewCanonical( 657 i = Integer::NewCanonical(
648 String::Handle(String::New("-12345678901234567890111222"))); 658 String::Handle(String::New("-12345678901234567890111222")));
649 EXPECT(i.IsBigint()); 659 EXPECT(FLAG_limit_ints_to_64_bits ? i.IsNull() : i.IsBigint());
650 } 660 }
651 661
652 ISOLATE_UNIT_TEST_CASE(String) { 662 ISOLATE_UNIT_TEST_CASE(String) {
653 const char* kHello = "Hello World!"; 663 const char* kHello = "Hello World!";
654 int32_t hello_len = strlen(kHello); 664 int32_t hello_len = strlen(kHello);
655 const String& str = String::Handle(String::New(kHello)); 665 const String& str = String::Handle(String::New(kHello));
656 EXPECT(str.IsInstance()); 666 EXPECT(str.IsInstance());
657 EXPECT(str.IsString()); 667 EXPECT(str.IsString());
658 EXPECT(str.IsOneByteString()); 668 EXPECT(str.IsOneByteString());
659 EXPECT(!str.IsTwoByteString()); 669 EXPECT(!str.IsTwoByteString());
(...skipping 3497 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 EXPECT_STREQ( 4167 EXPECT_STREQ(
4158 "{\"type\":\"@Instance\"," 4168 "{\"type\":\"@Instance\","
4159 "\"_vmType\":\"Mint\"," 4169 "\"_vmType\":\"Mint\","
4160 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\"," 4170 "\"class\":{\"type\":\"@Class\",\"fixedId\":true,\"id\":\"\","
4161 "\"name\":\"_Mint\",\"_vmName\":\"\"}," 4171 "\"name\":\"_Mint\",\"_vmName\":\"\"},"
4162 "\"kind\":\"Int\"," 4172 "\"kind\":\"Int\","
4163 "\"id\":\"\",\"valueAsString\":\"-9223372036854775808\"}", 4173 "\"id\":\"\",\"valueAsString\":\"-9223372036854775808\"}",
4164 buffer); 4174 buffer);
4165 } 4175 }
4166 // Bigint reference 4176 // Bigint reference
4167 { 4177 if (!Bigint::IsDisabled()) {
4168 JSONStream js; 4178 JSONStream js;
4169 const String& bigint_str = 4179 const String& bigint_str =
4170 String::Handle(String::New("44444444444444444444444444444444")); 4180 String::Handle(String::New("44444444444444444444444444444444"));
4171 const Integer& bigint = Integer::Handle(Integer::New(bigint_str)); 4181 const Integer& bigint = Integer::Handle(Integer::New(bigint_str));
4172 bigint.PrintJSON(&js, true); 4182 bigint.PrintJSON(&js, true);
4173 ElideJSONSubstring("classes", js.ToCString(), buffer); 4183 ElideJSONSubstring("classes", js.ToCString(), buffer);
4174 ElideJSONSubstring("objects", buffer, buffer); 4184 ElideJSONSubstring("objects", buffer, buffer);
4175 ElideJSONSubstring("_Bigint@", buffer, buffer); 4185 ElideJSONSubstring("_Bigint@", buffer, buffer);
4176 EXPECT_STREQ( 4186 EXPECT_STREQ(
4177 "{\"type\":\"@Instance\"," 4187 "{\"type\":\"@Instance\","
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
4632 // utf32->utf16 conversion. 4642 // utf32->utf16 conversion.
4633 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff, 4643 int32_t char_codes[] = {0, 0x0a, 0x0d, 0x7f, 0xff,
4634 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff}; 4644 0xffff, 0xd800, 0xdc00, 0xdbff, 0xdfff};
4635 4645
4636 const String& str = 4646 const String& str =
4637 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes))); 4647 String::Handle(String::FromUTF32(char_codes, ARRAY_SIZE(char_codes)));
4638 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes))); 4648 EXPECT(str.Equals(char_codes, ARRAY_SIZE(char_codes)));
4639 } 4649 }
4640 4650
4641 } // namespace dart 4651 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/regexp_assembler_ir.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698