Chromium Code Reviews| 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 |