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 // TODO(zra): Remove when tests are ready to enable. | 5 // TODO(zra): Remove when tests are ready to enable. |
6 #include "platform/globals.h" | 6 #include "platform/globals.h" |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 EXPECT_EQ(dbl_const, dbl2.value()); | 509 EXPECT_EQ(dbl_const, dbl2.value()); |
510 EXPECT_EQ(dbl_const, dbl3.value()); | 510 EXPECT_EQ(dbl_const, dbl3.value()); |
511 EXPECT_EQ(dbl1.raw(), dbl2.raw()); | 511 EXPECT_EQ(dbl1.raw(), dbl2.raw()); |
512 EXPECT_EQ(dbl1.raw(), dbl3.raw()); | 512 EXPECT_EQ(dbl1.raw(), dbl3.raw()); |
513 } | 513 } |
514 | 514 |
515 { | 515 { |
516 const double dbl_const = 2.0; | 516 const double dbl_const = 2.0; |
517 const Double& dbl1 = Double::Handle(Double::New(dbl_const)); | 517 const Double& dbl1 = Double::Handle(Double::New(dbl_const)); |
518 const Double& dbl2 = Double::Handle(Double::New(dbl_const)); | 518 const Double& dbl2 = Double::Handle(Double::New(dbl_const)); |
519 EXPECT(dbl1.Equals(dbl2)); | 519 EXPECT(dbl1.OperatorEquals(dbl2)); |
| 520 EXPECT(dbl1.IsIdenticalTo(dbl2)); |
| 521 EXPECT(dbl1.CanonicalizeEquals(dbl2)); |
520 const Double& dbl3 = Double::Handle(Double::New(3.3)); | 522 const Double& dbl3 = Double::Handle(Double::New(3.3)); |
521 EXPECT(!dbl1.Equals(dbl3)); | 523 EXPECT(!dbl1.OperatorEquals(dbl3)); |
522 EXPECT(!dbl1.Equals(Smi::Handle(Smi::New(3)))); | 524 EXPECT(!dbl1.OperatorEquals(Smi::Handle(Smi::New(3)))); |
523 EXPECT(!dbl1.Equals(Double::Handle())); | 525 EXPECT(!dbl1.OperatorEquals(Double::Handle())); |
| 526 const Double& nan0 = Double::Handle(Double::New(NAN)); |
| 527 EXPECT(nan0.IsIdenticalTo(nan0)); |
| 528 EXPECT(nan0.CanonicalizeEquals(nan0)); |
| 529 EXPECT(!nan0.OperatorEquals(nan0)); |
| 530 // TODO(18738): Test bitwise different NaNs after agreement on spec. |
524 } | 531 } |
525 { | 532 { |
526 const String& dbl_str0 = String::Handle(String::New("bla")); | 533 const String& dbl_str0 = String::Handle(String::New("bla")); |
527 const Double& dbl0 = Double::Handle(Double::New(dbl_str0)); | 534 const Double& dbl0 = Double::Handle(Double::New(dbl_str0)); |
528 EXPECT(dbl0.IsNull()); | 535 EXPECT(dbl0.IsNull()); |
529 | 536 |
530 const String& dbl_str1 = String::Handle(String::New("2.0")); | 537 const String& dbl_str1 = String::Handle(String::New("2.0")); |
531 const Double& dbl1 = Double::Handle(Double::New(dbl_str1)); | 538 const Double& dbl1 = Double::Handle(Double::New(dbl_str1)); |
532 EXPECT_EQ(2.0, dbl1.value()); | 539 EXPECT_EQ(2.0, dbl1.value()); |
533 | 540 |
(...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 EXPECT_EQ(array.raw(), element.raw()); | 1838 EXPECT_EQ(array.raw(), element.raw()); |
1832 element = array.At(1); | 1839 element = array.At(1); |
1833 EXPECT(element.IsNull()); | 1840 EXPECT(element.IsNull()); |
1834 element = array.At(2); | 1841 element = array.At(2); |
1835 EXPECT_EQ(array.raw(), element.raw()); | 1842 EXPECT_EQ(array.raw(), element.raw()); |
1836 | 1843 |
1837 Array& other_array = Array::Handle(Array::New(kArrayLen)); | 1844 Array& other_array = Array::Handle(Array::New(kArrayLen)); |
1838 other_array.SetAt(0, array); | 1845 other_array.SetAt(0, array); |
1839 other_array.SetAt(2, array); | 1846 other_array.SetAt(2, array); |
1840 | 1847 |
1841 EXPECT(array.Equals(array)); | 1848 EXPECT(array.CanonicalizeEquals(array)); |
1842 EXPECT(array.Equals(other_array)); | 1849 EXPECT(array.CanonicalizeEquals(other_array)); |
1843 | 1850 |
1844 other_array.SetAt(1, other_array); | 1851 other_array.SetAt(1, other_array); |
1845 EXPECT(!array.Equals(other_array)); | 1852 EXPECT(!array.CanonicalizeEquals(other_array)); |
1846 | 1853 |
1847 other_array = Array::New(kArrayLen - 1); | 1854 other_array = Array::New(kArrayLen - 1); |
1848 other_array.SetAt(0, array); | 1855 other_array.SetAt(0, array); |
1849 other_array.SetAt(2, array); | 1856 other_array.SetAt(2, array); |
1850 EXPECT(!array.Equals(other_array)); | 1857 EXPECT(!array.CanonicalizeEquals(other_array)); |
1851 | 1858 |
1852 EXPECT_EQ(0, Object::empty_array().Length()); | 1859 EXPECT_EQ(0, Object::empty_array().Length()); |
1853 | 1860 |
1854 EXPECT_EQ(1, Object::zero_array().Length()); | 1861 EXPECT_EQ(1, Object::zero_array().Length()); |
1855 element = Object::zero_array().At(0); | 1862 element = Object::zero_array().At(0); |
1856 EXPECT(Smi::Cast(element).IsZero()); | 1863 EXPECT(Smi::Cast(element).IsZero()); |
1857 | 1864 |
1858 array.MakeImmutable(); | 1865 array.MakeImmutable(); |
1859 Object& obj = Object::Handle(array.raw()); | 1866 Object& obj = Object::Handle(array.raw()); |
1860 EXPECT(obj.IsArray()); | 1867 EXPECT(obj.IsArray()); |
(...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4011 }; | 4018 }; |
4012 | 4019 |
4013 | 4020 |
4014 TEST_CASE(PrintJSON) { | 4021 TEST_CASE(PrintJSON) { |
4015 Heap* heap = Isolate::Current()->heap(); | 4022 Heap* heap = Isolate::Current()->heap(); |
4016 heap->CollectAllGarbage(); | 4023 heap->CollectAllGarbage(); |
4017 JSONTypeVerifier verifier; | 4024 JSONTypeVerifier verifier; |
4018 heap->IterateObjects(&verifier); | 4025 heap->IterateObjects(&verifier); |
4019 } | 4026 } |
4020 | 4027 |
| 4028 |
| 4029 TEST_CASE(InstanceEquality) { |
| 4030 // Test that Instance::OperatorEquals can call a user-defined operator==. |
| 4031 const char* kScript = |
| 4032 "class A {\n" |
| 4033 " bool operator==(A other) { return true; }\n" |
| 4034 "}\n" |
| 4035 "main() {\n" |
| 4036 " A a = new A();\n" |
| 4037 "}"; |
| 4038 |
| 4039 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
| 4040 EXPECT_VALID(h_lib); |
| 4041 Library& lib = Library::Handle(); |
| 4042 lib ^= Api::UnwrapHandle(h_lib); |
| 4043 EXPECT(!lib.IsNull()); |
| 4044 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 4045 EXPECT_VALID(result); |
| 4046 const Class& clazz = Class::Handle(GetClass(lib, "A")); |
| 4047 EXPECT(!clazz.IsNull()); |
| 4048 const Instance& a0 = Instance::Handle(Instance::New(clazz)); |
| 4049 const Instance& a1 = Instance::Handle(Instance::New(clazz)); |
| 4050 EXPECT(a0.raw() != a1.raw()); |
| 4051 EXPECT(a0.OperatorEquals(a0)); |
| 4052 EXPECT(a0.OperatorEquals(a1)); |
| 4053 EXPECT(a0.IsIdenticalTo(a0)); |
| 4054 EXPECT(!a0.IsIdenticalTo(a1)); |
| 4055 } |
| 4056 |
4021 } // namespace dart | 4057 } // namespace dart |
OLD | NEW |