Chromium Code Reviews| Index: runtime/vm/dart_api_impl_test.cc |
| diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc |
| index 309c0f96c3a437191e071fafe463ee86b859ceef..7a9640ccd754f8623b8b7cadf64a93aef937a71b 100644 |
| --- a/runtime/vm/dart_api_impl_test.cc |
| +++ b/runtime/vm/dart_api_impl_test.cc |
| @@ -2608,8 +2608,9 @@ TEST_CASE(FieldAccess) { |
| Dart_Handle url = Dart_NewString("library_url"); |
| Dart_Handle source = Dart_NewString(kImportedScriptChars); |
| Dart_Handle imported_lib = Dart_LoadLibrary(url, source); |
| + Dart_Handle prefix = Dart_NewString(""); |
| EXPECT_VALID(imported_lib); |
| - Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib); |
| + Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); |
| EXPECT_VALID(result); |
| result = Dart_Invoke(imported_lib, Dart_NewString("test2"), 0, NULL); |
| EXPECT_VALID(result); |
| @@ -3696,10 +3697,11 @@ TEST_CASE(Invoke_CrossLibrary) { |
| url = Dart_NewString("library2_url"); |
| source = Dart_NewString(kLibrary2Chars); |
| Dart_Handle lib2 = Dart_LoadLibrary(url, source); |
| + Dart_Handle prefix = Dart_NewString(""); |
| EXPECT_VALID(lib2); |
| // Import lib2 from lib1 |
| - Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2); |
| + Dart_Handle result = Dart_LibraryImportLibrary(lib1, lib2, prefix); |
| EXPECT_VALID(result); |
| // We can invoke both private and non-private local functions. |
| @@ -5243,45 +5245,76 @@ TEST_CASE(LibraryImportLibrary) { |
| url = Dart_NewString("library2_url"); |
| source = Dart_NewString(kLibrary2Chars); |
| Dart_Handle lib2 = Dart_LoadLibrary(url, source); |
| + Dart_Handle prefix = Dart_NewString(""); |
| EXPECT_VALID(lib2); |
| - result = Dart_LibraryImportLibrary(Dart_Null(), lib2); |
| + result = Dart_LibraryImportLibrary(Dart_Null(), lib2, prefix); |
| EXPECT(Dart_IsError(result)); |
| EXPECT_STREQ( |
| "Dart_LibraryImportLibrary expects argument 'library' to be non-null.", |
| Dart_GetError(result)); |
| - result = Dart_LibraryImportLibrary(Dart_True(), lib2); |
| + result = Dart_LibraryImportLibrary(Dart_True(), lib2, prefix); |
| EXPECT(Dart_IsError(result)); |
| EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'library' to be of " |
| "type Library.", |
| Dart_GetError(result)); |
| - result = Dart_LibraryImportLibrary(error, lib2); |
| + result = Dart_LibraryImportLibrary(error, lib2, prefix); |
| EXPECT(Dart_IsError(result)); |
| EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| - result = Dart_LibraryImportLibrary(lib1, Dart_Null()); |
| + result = Dart_LibraryImportLibrary(lib1, Dart_Null(), prefix); |
| EXPECT(Dart_IsError(result)); |
| EXPECT_STREQ( |
| "Dart_LibraryImportLibrary expects argument 'import' to be non-null.", |
| Dart_GetError(result)); |
| - result = Dart_LibraryImportLibrary(lib1, Dart_True()); |
| + result = Dart_LibraryImportLibrary(lib1, Dart_True(), prefix); |
| EXPECT(Dart_IsError(result)); |
| EXPECT_STREQ("Dart_LibraryImportLibrary expects argument 'import' to be of " |
| "type Library.", |
| Dart_GetError(result)); |
| - result = Dart_LibraryImportLibrary(lib1, error); |
| + result = Dart_LibraryImportLibrary(lib1, error, prefix); |
| EXPECT(Dart_IsError(result)); |
| EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| - result = Dart_LibraryImportLibrary(lib1, lib2); |
| + result = Dart_LibraryImportLibrary(lib1, lib2, prefix); |
| EXPECT_VALID(result); |
| } |
| +TEST_CASE(ImportLibraryWithPrefix) { |
| + const char* kLibrary1Chars = |
| + "#library('library1_name');" |
| + "int foo() => 42;"; |
| + Dart_Handle url1 = Dart_NewString("library1_url"); |
| + Dart_Handle source1 = Dart_NewString(kLibrary1Chars); |
| + Dart_Handle lib1 = Dart_LoadLibrary(url1, source1); |
| + EXPECT_VALID(lib1); |
| + EXPECT(Dart_IsLibrary(lib1)); |
| + |
| + const char* kLibrary2Chars = |
| + "#library('library2_name');"; |
|
Ivan Posva
2012/08/28 23:22:02
Also add a test that something in the prefixed lib
Mads Ager (google)
2012/08/29 05:52:10
Done.
|
| + Dart_Handle url2 = Dart_NewString("library2_url"); |
| + Dart_Handle source2 = Dart_NewString(kLibrary2Chars); |
| + Dart_Handle lib2 = Dart_LoadLibrary(url2, source2); |
| + EXPECT_VALID(lib2); |
| + EXPECT(Dart_IsLibrary(lib2)); |
| + |
| + Dart_Handle prefix = Dart_NewString("bar"); |
| + Dart_Handle result = Dart_LibraryImportLibrary(lib2, lib1, prefix); |
| + EXPECT_VALID(result); |
| + |
| + // Lib1 is imported under a library prefix and therefore 'foo' should |
| + // not be found directly in lib2. |
| + Dart_Handle method_name = Dart_NewString("foo"); |
| + result = Dart_Invoke(lib2, method_name, 0, NULL); |
| + EXPECT_ERROR(result, "Dart_Invoke: did not find top-level function 'foo'"); |
| +} |
| + |
| + |
| TEST_CASE(LoadLibrary) { |
| const char* kLibrary1Chars = |