Index: runtime/vm/compiler_test.cc |
=================================================================== |
--- runtime/vm/compiler_test.cc (revision 26326) |
+++ runtime/vm/compiler_test.cc (working copy) |
@@ -5,6 +5,7 @@ |
#include "platform/assert.h" |
#include "vm/class_finalizer.h" |
#include "vm/compiler.h" |
+#include "vm/dart_api_impl.h" |
#include "vm/object.h" |
#include "vm/symbols.h" |
#include "vm/unit_test.h" |
@@ -63,4 +64,34 @@ |
EXPECT(function_moo.HasCode()); |
} |
+ |
+TEST_CASE(EvalExpression) { |
+ const char* kScriptChars = |
+ "int ten = 2 * 5; \n" |
+ "get dot => '.'; \n" |
+ "class A { \n" |
+ " var apa = 'Herr Nilsson'; \n" |
+ " calc(x) => '${x*ten}'; \n" |
+ "} \n" |
+ "makeObj() => new A(); \n"; |
+ |
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
+ Dart_Handle obj_handle = |
+ Dart_Invoke(lib, Dart_NewStringFromCString("makeObj"), 0, NULL); |
+ EXPECT(!Dart_IsNull(obj_handle)); |
+ EXPECT(!Dart_IsError(obj_handle)); |
+ const Object& obj = Object::Handle(Api::UnwrapHandle(obj_handle)); |
+ EXPECT(!obj.IsNull()); |
+ EXPECT(obj.IsInstance()); |
+ |
+ String& expr_text = String::Handle(); |
+ expr_text = String::New("apa + ' ${calc(10)}' + dot"); |
+ Object& val = Object::Handle(); |
+ val = Instance::Cast(obj).Evaluate(expr_text); |
+ EXPECT(!val.IsNull()); |
+ EXPECT(!val.IsError()); |
+ EXPECT(val.IsString()); |
+ EXPECT_STREQ("Herr Nilsson 100.", val.ToCString()); |
+} |
+ |
} // namespace dart |