| 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 "vm/assembler.h" | 5 #include "vm/assembler.h" |
| 6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
| 7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| (...skipping 3609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3620 | 3620 |
| 3621 cls = Object::dynamic_class(); | 3621 cls = Object::dynamic_class(); |
| 3622 array = cls.fields(); | 3622 array = cls.fields(); |
| 3623 EXPECT(!array.IsNull()); | 3623 EXPECT(!array.IsNull()); |
| 3624 EXPECT(array.IsArray()); | 3624 EXPECT(array.IsArray()); |
| 3625 array = cls.functions(); | 3625 array = cls.functions(); |
| 3626 EXPECT(!array.IsNull()); | 3626 EXPECT(!array.IsNull()); |
| 3627 EXPECT(array.IsArray()); | 3627 EXPECT(array.IsArray()); |
| 3628 } | 3628 } |
| 3629 | 3629 |
| 3630 |
| 3631 TEST_CASE(ToUserCString) { |
| 3632 const char* kScriptChars = |
| 3633 "var simple = 'simple';\n" |
| 3634 "var escapes = 'stuff\\n\\r\\f\\b\\t\\v\\'\"\\$stuff';\n" |
| 3635 "var uescapes = 'stuff\\u0001\\u0002stuff';\n" |
| 3636 "var toolong = " |
| 3637 "'01234567890123456789012345678901234567890123456789howdy';\n" |
| 3638 "var toolong2 = " |
| 3639 "'0123456789012345678901234567890123\\t567890123456789howdy';\n" |
| 3640 "var toolong3 = " |
| 3641 "'012345678901234567890123456789\\u0001567890123456789howdy';\n" |
| 3642 "\n" |
| 3643 "class _Cobra { }\n" |
| 3644 "var instance = new _Cobra();\n" |
| 3645 "\n" |
| 3646 "var simple_list = [1,2,'otter'];\n" |
| 3647 "\n" |
| 3648 "var simple_map = {1: 2, 2: 'otter'};\n"; |
| 3649 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3650 EXPECT_VALID(lib); |
| 3651 |
| 3652 Instance& obj = Instance::Handle(); |
| 3653 Dart_Handle result; |
| 3654 |
| 3655 // Simple string. |
| 3656 result = Dart_GetField(lib, NewString("simple")); |
| 3657 EXPECT_VALID(result); |
| 3658 obj ^= Api::UnwrapHandle(result); |
| 3659 EXPECT_STREQ("\"simple\"", obj.ToUserCString()); |
| 3660 |
| 3661 // Escaped chars. |
| 3662 result = Dart_GetField(lib, NewString("escapes")); |
| 3663 EXPECT_VALID(result); |
| 3664 obj ^= Api::UnwrapHandle(result); |
| 3665 EXPECT_STREQ("\"stuff\\n\\r\\f\\b\\t\\v'\\\"\\$stuff\"", |
| 3666 obj.ToUserCString()); |
| 3667 |
| 3668 // U-escaped chars. |
| 3669 result = Dart_GetField(lib, NewString("uescapes")); |
| 3670 EXPECT_VALID(result); |
| 3671 obj ^= Api::UnwrapHandle(result); |
| 3672 EXPECT_STREQ("\"stuff\\u0001\\u0002stuff\"", obj.ToUserCString()); |
| 3673 |
| 3674 // Truncation. |
| 3675 result = Dart_GetField(lib, NewString("toolong")); |
| 3676 EXPECT_VALID(result); |
| 3677 obj ^= Api::UnwrapHandle(result); |
| 3678 EXPECT_STREQ("\"01234567890123456789012345678901234\"...", |
| 3679 obj.ToUserCString()); |
| 3680 |
| 3681 // Truncation. Custom limit. |
| 3682 result = Dart_GetField(lib, NewString("toolong")); |
| 3683 EXPECT_VALID(result); |
| 3684 obj ^= Api::UnwrapHandle(result); |
| 3685 EXPECT_STREQ("\"01234\"...", obj.ToUserCString(10)); |
| 3686 |
| 3687 // Truncation, limit is in escape. |
| 3688 result = Dart_GetField(lib, NewString("toolong2")); |
| 3689 EXPECT_VALID(result); |
| 3690 obj ^= Api::UnwrapHandle(result); |
| 3691 EXPECT_STREQ("\"0123456789012345678901234567890123\"...", |
| 3692 obj.ToUserCString()); |
| 3693 |
| 3694 // Truncation, limit is in u-escape |
| 3695 result = Dart_GetField(lib, NewString("toolong3")); |
| 3696 EXPECT_VALID(result); |
| 3697 obj ^= Api::UnwrapHandle(result); |
| 3698 EXPECT_STREQ("\"012345678901234567890123456789\"...", |
| 3699 obj.ToUserCString()); |
| 3700 |
| 3701 // Instance of a class. |
| 3702 result = Dart_GetField(lib, NewString("instance")); |
| 3703 EXPECT_VALID(result); |
| 3704 obj ^= Api::UnwrapHandle(result); |
| 3705 EXPECT_STREQ("Instance of '_Cobra'", obj.ToUserCString()); |
| 3706 |
| 3707 // Simple list. |
| 3708 // |
| 3709 // TODO(turnidge): Consider showing something like: [1, 2, 'otter']. |
| 3710 result = Dart_GetField(lib, NewString("simple_list")); |
| 3711 EXPECT_VALID(result); |
| 3712 obj ^= Api::UnwrapHandle(result); |
| 3713 EXPECT_STREQ("Instance(length:3) of '_GrowableList'", |
| 3714 obj.ToUserCString()); |
| 3715 |
| 3716 // Simple map. |
| 3717 // |
| 3718 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'} |
| 3719 result = Dart_GetField(lib, NewString("simple_map")); |
| 3720 EXPECT_VALID(result); |
| 3721 obj ^= Api::UnwrapHandle(result); |
| 3722 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString()); |
| 3723 } |
| 3724 |
| 3630 } // namespace dart | 3725 } // namespace dart |
| OLD | NEW |