2012-01-16 12:28:10 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
2011-10-05 05:20:07 +00:00
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2012-01-16 12:28:10 +00:00
|
|
|
#include "platform/assert.h"
|
2012-04-11 18:12:28 +00:00
|
|
|
#include "vm/class_finalizer.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
#include "vm/compiler.h"
|
|
|
|
#include "vm/object.h"
|
2012-07-24 00:01:50 +00:00
|
|
|
#include "vm/symbols.h"
|
2011-10-05 05:20:07 +00:00
|
|
|
#include "vm/unit_test.h"
|
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
|
|
|
TEST_CASE(CompileScript) {
|
|
|
|
const char* kScriptChars =
|
|
|
|
"class A {\n"
|
|
|
|
" static foo() { return 42; }\n"
|
|
|
|
"}\n";
|
|
|
|
String& url = String::Handle(String::New("dart-test:CompileScript"));
|
|
|
|
String& source = String::Handle(String::New(kScriptChars));
|
2012-07-20 22:24:49 +00:00
|
|
|
Script& script = Script::Handle(Script::New(url,
|
|
|
|
source,
|
2013-05-01 20:46:48 +00:00
|
|
|
RawScript::kScriptTag));
|
2011-10-05 05:20:07 +00:00
|
|
|
Library& lib = Library::Handle(Library::CoreLibrary());
|
|
|
|
EXPECT(CompilerTest::TestCompileScript(lib, script));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_CASE(CompileFunction) {
|
|
|
|
const char* kScriptChars =
|
|
|
|
"class A {\n"
|
|
|
|
" static foo() { return 42; }\n"
|
|
|
|
" static moo() {\n"
|
|
|
|
" // A.foo();\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n";
|
|
|
|
String& url = String::Handle(String::New("dart-test:CompileFunction"));
|
|
|
|
String& source = String::Handle(String::New(kScriptChars));
|
2012-07-20 22:24:49 +00:00
|
|
|
Script& script = Script::Handle(Script::New(url,
|
|
|
|
source,
|
2013-05-01 20:46:48 +00:00
|
|
|
RawScript::kScriptTag));
|
2011-10-05 05:20:07 +00:00
|
|
|
Library& lib = Library::Handle(Library::CoreLibrary());
|
|
|
|
EXPECT(CompilerTest::TestCompileScript(lib, script));
|
2012-04-11 18:12:28 +00:00
|
|
|
EXPECT(ClassFinalizer::FinalizePendingClasses());
|
2013-07-23 00:19:39 +00:00
|
|
|
String& ambiguity_error_msg = String::Handle();
|
2011-10-05 05:20:07 +00:00
|
|
|
Class& cls = Class::Handle(
|
2013-07-23 00:19:39 +00:00
|
|
|
lib.LookupClass(String::Handle(Symbols::New("A")), &ambiguity_error_msg));
|
|
|
|
EXPECT(!cls.IsNull()); // No ambiguity error expected.
|
2011-10-05 05:20:07 +00:00
|
|
|
String& function_foo_name = String::Handle(String::New("foo"));
|
|
|
|
Function& function_foo =
|
|
|
|
Function::Handle(cls.LookupStaticFunction(function_foo_name));
|
|
|
|
EXPECT(!function_foo.IsNull());
|
|
|
|
|
|
|
|
EXPECT(CompilerTest::TestCompileFunction(function_foo));
|
|
|
|
EXPECT(function_foo.HasCode());
|
|
|
|
|
|
|
|
String& function_moo_name = String::Handle(String::New("moo"));
|
|
|
|
Function& function_moo =
|
|
|
|
Function::Handle(cls.LookupStaticFunction(function_moo_name));
|
|
|
|
EXPECT(!function_moo.IsNull());
|
|
|
|
|
|
|
|
EXPECT(CompilerTest::TestCompileFunction(function_moo));
|
|
|
|
EXPECT(function_moo.HasCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dart
|