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/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/class_finalizer.h" | 6 #include "vm/class_finalizer.h" |
7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 Library& lib = Library::Handle(Library::CoreLibrary()); | 43 Library& lib = Library::Handle(Library::CoreLibrary()); |
44 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 44 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
45 EXPECT(ClassFinalizer::FinalizePendingClasses()); | 45 EXPECT(ClassFinalizer::FinalizePendingClasses()); |
46 Class& cls = Class::Handle( | 46 Class& cls = Class::Handle( |
47 lib.LookupClass(String::Handle(Symbols::New("A")))); | 47 lib.LookupClass(String::Handle(Symbols::New("A")))); |
48 EXPECT(!cls.IsNull()); | 48 EXPECT(!cls.IsNull()); |
49 String& function_foo_name = String::Handle(String::New("foo")); | 49 String& function_foo_name = String::Handle(String::New("foo")); |
50 Function& function_foo = | 50 Function& function_foo = |
51 Function::Handle(cls.LookupStaticFunction(function_foo_name)); | 51 Function::Handle(cls.LookupStaticFunction(function_foo_name)); |
52 EXPECT(!function_foo.IsNull()); | 52 EXPECT(!function_foo.IsNull()); |
53 | 53 String& function_source = String::Handle(function_foo.GetSource()); |
| 54 EXPECT_STREQ("static foo() { return 42; }\n ", function_source.ToCString()); |
54 EXPECT(CompilerTest::TestCompileFunction(function_foo)); | 55 EXPECT(CompilerTest::TestCompileFunction(function_foo)); |
55 EXPECT(function_foo.HasCode()); | 56 EXPECT(function_foo.HasCode()); |
56 | 57 |
57 String& function_moo_name = String::Handle(String::New("moo")); | 58 String& function_moo_name = String::Handle(String::New("moo")); |
58 Function& function_moo = | 59 Function& function_moo = |
59 Function::Handle(cls.LookupStaticFunction(function_moo_name)); | 60 Function::Handle(cls.LookupStaticFunction(function_moo_name)); |
60 EXPECT(!function_moo.IsNull()); | 61 EXPECT(!function_moo.IsNull()); |
61 | 62 |
62 EXPECT(CompilerTest::TestCompileFunction(function_moo)); | 63 EXPECT(CompilerTest::TestCompileFunction(function_moo)); |
63 EXPECT(function_moo.HasCode()); | 64 EXPECT(function_moo.HasCode()); |
| 65 function_source = function_moo.GetSource(); |
| 66 EXPECT_STREQ("static moo() {\n // A.foo();\n }\n", |
| 67 function_source.ToCString()); |
64 } | 68 } |
65 | 69 |
66 | 70 |
67 TEST_CASE(EvalExpression) { | 71 TEST_CASE(EvalExpression) { |
68 const char* kScriptChars = | 72 const char* kScriptChars = |
69 "int ten = 2 * 5; \n" | 73 "int ten = 2 * 5; \n" |
70 "get dot => '.'; \n" | 74 "get dot => '.'; \n" |
71 "class A { \n" | 75 "class A { \n" |
72 " var apa = 'Herr Nilsson'; \n" | 76 " var apa = 'Herr Nilsson'; \n" |
73 " calc(x) => '${x*ten}'; \n" | 77 " calc(x) => '${x*ten}'; \n" |
(...skipping 13 matching lines...) Expand all Loading... |
87 expr_text = String::New("apa + ' ${calc(10)}' + dot"); | 91 expr_text = String::New("apa + ' ${calc(10)}' + dot"); |
88 Object& val = Object::Handle(); | 92 Object& val = Object::Handle(); |
89 val = Instance::Cast(obj).Evaluate(expr_text); | 93 val = Instance::Cast(obj).Evaluate(expr_text); |
90 EXPECT(!val.IsNull()); | 94 EXPECT(!val.IsNull()); |
91 EXPECT(!val.IsError()); | 95 EXPECT(!val.IsError()); |
92 EXPECT(val.IsString()); | 96 EXPECT(val.IsString()); |
93 EXPECT_STREQ("Herr Nilsson 100.", val.ToCString()); | 97 EXPECT_STREQ("Herr Nilsson 100.", val.ToCString()); |
94 } | 98 } |
95 | 99 |
96 } // namespace dart | 100 } // namespace dart |
OLD | NEW |