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

Unified Diff: vm/dart_api_impl_test.cc

Issue 8342046: Add an imported into list for libraries so that it is possible to lookup (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « vm/dart_api_impl.cc ('k') | vm/isolate.cc » ('j') | vm/object.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/dart_api_impl_test.cc
===================================================================
--- vm/dart_api_impl_test.cc (revision 557)
+++ vm/dart_api_impl_test.cc (working copy)
@@ -1420,6 +1420,230 @@
Dart_ShutdownIsolate();
}
+
+static Dart_Result library_handler(Dart_LibraryTag tag,
+ Dart_Handle library,
+ Dart_Handle url) {
+ if (tag == kCanonicalizeUrl) {
+ return Dart_ResultAsObject(url);
+ }
+ return Dart_ResultAsObject(Dart_NewBoolean(true));
+}
+
+
+UNIT_TEST_CASE(ImportLibrary1) {
+ const char* kScriptChars =
+ "#import(\"library1.dart\");\n"
Ivan Posva 2011/10/20 08:46:04 This would become a little bit more readable if it
siva 2011/10/20 23:08:47 Done.
+ "#import(\"library2.dart\");\n"
+ "var foo; // library2 defines foo, so should be error.\n"
+ "main() {}\n";
+ const char* kLibrary1Chars =
+ "#library(\"library1.dart\");\n"
+ "#import(\"library2.dart\");\n"
+ "var foo1;\n";
+ const char* kLibrary2Chars =
+ "#library(\"library2.dart\");\n"
+ "var foo;\n";
+ Dart_Result result;
+
+ Dart_CreateIsolate(NULL, NULL);
+ {
+ Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
+
+ // Create a test library and Load up a test script in it.
+ Dart_Handle url = Dart_NewString(TestCase::url());
+ Dart_Handle source = Dart_NewString(kScriptChars);
+ result = Dart_LoadScript(url, source, library_handler);
+
+ url = Dart_NewString("library1.dart");
+ source = Dart_NewString(kLibrary1Chars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("library2.dart");
+ source = Dart_NewString(kLibrary2Chars);
+ Dart_LoadLibrary(url, source);
+
+ result = Dart_InvokeStatic(Dart_GetResult(result),
+ Dart_NewString(""),
+ Dart_NewString("main"),
+ 0,
+ NULL);
+ assert(!Dart_IsValidResult(result));
Ivan Posva 2011/10/20 08:46:04 Could you check that there is a complaint about "f
siva 2011/10/20 23:08:47 Done.
+
+ Dart_ExitScope(); // Exit the Dart API scope.
+ }
+ Dart_ShutdownIsolate();
+}
+
+
+UNIT_TEST_CASE(ImportLibrary2) {
+ const char* kScriptChars =
+ "#import(\"library1.dart\");\n"
+ "var foo;\n"
+ "main() {}\n";
+ const char* kLibrary1Chars =
+ "#library(\"library1.dart\");\n"
+ "#import(\"library2.dart\");\n"
+ "var foo1;\n";
+ const char* kLibrary2Chars =
+ "#library(\"library2.dart\");\n"
+ "#import(\"library1.dart\");\n"
+ "var foo;\n";
+ Dart_Result result;
+
+ Dart_CreateIsolate(NULL, NULL);
+ {
+ Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
+
+ // Create a test library and Load up a test script in it.
+ Dart_Handle url = Dart_NewString(TestCase::url());
+ Dart_Handle source = Dart_NewString(kScriptChars);
+ result = Dart_LoadScript(url, source, library_handler);
+
+ url = Dart_NewString("library1.dart");
+ source = Dart_NewString(kLibrary1Chars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("library2.dart");
+ source = Dart_NewString(kLibrary2Chars);
+ Dart_LoadLibrary(url, source);
+
+ result = Dart_InvokeStatic(Dart_GetResult(result),
+ Dart_NewString(""),
+ Dart_NewString("main"),
+ 0,
+ NULL);
+ assert(Dart_IsValidResult(result));
+
+ Dart_ExitScope(); // Exit the Dart API scope.
+ }
+ Dart_ShutdownIsolate();
+}
+
+
+UNIT_TEST_CASE(ImportLibrary3) {
+ const char* kScriptChars =
+ "#import(\"library2.dart\");\n"
+ "#import(\"library1.dart\");\n"
+ "var foo_top = 10; // foo has dup def. So should be an error.\n"
+ "main() {}\n";
+ const char* kLibrary1Chars =
+ "#library(\"library1.dart\");\n"
+ "#import(\"library2.dart\");\n"
+ "var foo;\n";
+ const char* kLibrary2Chars =
+ "#library(\"library2.dart\");\n"
+ "var foo;\n";
+ Dart_Result result;
+
+ Dart_CreateIsolate(NULL, NULL);
+ {
+ Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
+
+ // Create a test library and Load up a test script in it.
+ Dart_Handle url = Dart_NewString(TestCase::url());
+ Dart_Handle source = Dart_NewString(kScriptChars);
+ result = Dart_LoadScript(url, source, library_handler);
+
+ url = Dart_NewString("library2.dart");
+ source = Dart_NewString(kLibrary2Chars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("library1.dart");
+ source = Dart_NewString(kLibrary1Chars);
+ Dart_LoadLibrary(url, source);
+
+ result = Dart_InvokeStatic(Dart_GetResult(result),
+ Dart_NewString(""),
+ Dart_NewString("main"),
+ 0,
+ NULL);
+ assert(!Dart_IsValidResult(result));
+
+ Dart_ExitScope(); // Exit the Dart API scope.
+ }
+ Dart_ShutdownIsolate();
+}
+
+
+UNIT_TEST_CASE(ImportLibrary4) {
+ const char* kScriptChars =
+ "#import(\"libraryA.dart\");\n"
+ "#import(\"libraryB.dart\");\n"
+ "#import(\"libraryD.dart\");\n"
+ "#import(\"libraryE.dart\");\n"
+ "var fooApp;\n"
+ "main() {}\n";
+ const char* kLibraryAChars =
+ "#library(\"libraryA.dart\");\n"
+ "#import(\"libraryC.dart\");\n"
+ "var fooA;\n";
+ const char* kLibraryBChars =
+ "#library(\"library2.dart\");\n"
Ivan Posva 2011/10/20 08:46:04 library2.dart?
siva 2011/10/20 23:08:47 Changed to libraryB.dart On 2011/10/20 08:46:04, I
+ "#import(\"libraryC.dart\");\n"
+ "var fooB;\n";
+ const char* kLibraryCChars =
+ "#library(\"libraryC.dart\");\n"
+ "var fooC;\n";
+ const char* kLibraryDChars =
+ "#library(\"libraryD.dart\");\n"
+ "#import(\"libraryF.dart\");\n"
+ "var fooD;\n";
+ const char* kLibraryEChars =
+ "#library(\"libraryE.dart\");\n"
+ "#import(\"libraryC.dart\");\n"
+ "#import(\"libraryF.dart\");\n"
+ "var fooE = 10; //fooC has duplicate def. so should be an error.\n";
+ const char* kLibraryFChars =
+ "#library(\"libraryF.dart\");\n"
+ "var fooC;\n";
+ Dart_Result result;
+
+ Dart_CreateIsolate(NULL, NULL);
+ {
+ Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
+
+ // Create a test library and Load up a test script in it.
+ Dart_Handle url = Dart_NewString(TestCase::url());
+ Dart_Handle source = Dart_NewString(kScriptChars);
+ result = Dart_LoadScript(url, source, library_handler);
+
+ url = Dart_NewString("libraryA.dart");
+ source = Dart_NewString(kLibraryAChars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("libraryC.dart");
+ source = Dart_NewString(kLibraryCChars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("libraryB.dart");
+ source = Dart_NewString(kLibraryBChars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("libraryD.dart");
+ source = Dart_NewString(kLibraryDChars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("libraryF.dart");
+ source = Dart_NewString(kLibraryFChars);
+ Dart_LoadLibrary(url, source);
+
+ url = Dart_NewString("libraryE.dart");
+ source = Dart_NewString(kLibraryEChars);
+ Dart_LoadLibrary(url, source);
+
+ result = Dart_InvokeStatic(Dart_GetResult(result),
+ Dart_NewString(""),
+ Dart_NewString("main"),
+ 0,
+ NULL);
+ assert(!Dart_IsValidResult(result));
+
+ Dart_ExitScope(); // Exit the Dart API scope.
+ }
+ Dart_ShutdownIsolate();
+}
+
#endif // TARGET_ARCH_IA32.
} // namespace dart
« no previous file with comments | « vm/dart_api_impl.cc ('k') | vm/isolate.cc » ('j') | vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698