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

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

Issue 100833005: Add Instance::ToUserCString. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | Annotate | Revision Log
« runtime/vm/object.h ('K') | « runtime/vm/object.cc ('k') | no next file » | 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 "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
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, limit is in escape.
3682 result = Dart_GetField(lib, NewString("toolong2"));
3683 EXPECT_VALID(result);
3684 obj ^= Api::UnwrapHandle(result);
3685 EXPECT_STREQ("\"0123456789012345678901234567890123\"...",
3686 obj.ToUserCString());
3687
3688 // Truncation, limit is in u-escape
3689 result = Dart_GetField(lib, NewString("toolong3"));
3690 EXPECT_VALID(result);
3691 obj ^= Api::UnwrapHandle(result);
3692 EXPECT_STREQ("\"012345678901234567890123456789\"...",
3693 obj.ToUserCString());
3694
3695 // Instance of a class.
3696 result = Dart_GetField(lib, NewString("instance"));
3697 EXPECT_VALID(result);
3698 obj ^= Api::UnwrapHandle(result);
3699 EXPECT_STREQ("Instance of '_Cobra'", obj.ToUserCString());
3700
3701 // Simple list.
3702 //
3703 // TODO(turnidge): Consider showing something like: [1, 2, 'otter'].
3704 result = Dart_GetField(lib, NewString("simple_list"));
3705 EXPECT_VALID(result);
3706 obj ^= Api::UnwrapHandle(result);
3707 EXPECT_STREQ("Instance(length:3) of '_GrowableList'",
3708 obj.ToUserCString());
3709
3710 // Simple map.
3711 //
3712 // TODO(turnidge): Consider showing something like: {1: 2, 2: 'otter'}
3713 result = Dart_GetField(lib, NewString("simple_map"));
3714 EXPECT_VALID(result);
3715 obj ^= Api::UnwrapHandle(result);
3716 EXPECT_STREQ("Instance of '_LinkedHashMap'", obj.ToUserCString());
3717 }
3718
3630 } // namespace dart 3719 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698