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/object.h" | 9 #include "vm/object.h" |
9 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
10 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
11 | 12 |
12 namespace dart { | 13 namespace dart { |
13 | 14 |
14 TEST_CASE(CompileScript) { | 15 TEST_CASE(CompileScript) { |
15 const char* kScriptChars = | 16 const char* kScriptChars = |
16 "class A {\n" | 17 "class A {\n" |
17 " static foo() { return 42; }\n" | 18 " static foo() { return 42; }\n" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()); |
64 } | 65 } |
65 | 66 |
| 67 |
| 68 TEST_CASE(EvalExpression) { |
| 69 const char* kScriptChars = |
| 70 "int ten = 2 * 5; \n" |
| 71 "get dot => '.'; \n" |
| 72 "class A { \n" |
| 73 " var apa = 'Herr Nilsson'; \n" |
| 74 " calc(x) => '${x*ten}'; \n" |
| 75 "} \n" |
| 76 "makeObj() => new A(); \n"; |
| 77 |
| 78 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 79 Dart_Handle obj_handle = |
| 80 Dart_Invoke(lib, Dart_NewStringFromCString("makeObj"), 0, NULL); |
| 81 EXPECT(!Dart_IsNull(obj_handle)); |
| 82 EXPECT(!Dart_IsError(obj_handle)); |
| 83 const Object& obj = Object::Handle(Api::UnwrapHandle(obj_handle)); |
| 84 EXPECT(!obj.IsNull()); |
| 85 EXPECT(obj.IsInstance()); |
| 86 |
| 87 String& expr_text = String::Handle(); |
| 88 expr_text = String::New("apa + ' ${calc(10)}' + dot"); |
| 89 Object& val = Object::Handle(); |
| 90 val = Instance::Cast(obj).Evaluate(expr_text); |
| 91 EXPECT(!val.IsNull()); |
| 92 EXPECT(!val.IsError()); |
| 93 EXPECT(val.IsString()); |
| 94 EXPECT_STREQ("Herr Nilsson 100.", val.ToCString()); |
| 95 } |
| 96 |
66 } // namespace dart | 97 } // namespace dart |
OLD | NEW |