OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/json.h" | 10 #include "platform/json.h" |
(...skipping 8195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8206 Dart_Handle result = Dart_Invoke(lib, | 8206 Dart_Handle result = Dart_Invoke(lib, |
8207 NewString("main"), | 8207 NewString("main"), |
8208 0, | 8208 0, |
8209 NULL); | 8209 NULL); |
8210 int64_t value = 0; | 8210 int64_t value = 0; |
8211 result = Dart_IntegerToInt64(result, &value); | 8211 result = Dart_IntegerToInt64(result, &value); |
8212 EXPECT_VALID(result); | 8212 EXPECT_VALID(result); |
8213 EXPECT_EQ(8, value); | 8213 EXPECT_EQ(8, value); |
8214 } | 8214 } |
8215 | 8215 |
| 8216 |
| 8217 TEST_CASE(AmbiguousReference) { |
| 8218 const char* kImportedScript1Chars = |
| 8219 "library library1.dart;\n" |
| 8220 "var foo;\n" |
| 8221 "var foo1;\n" |
| 8222 "bar() => 'library1.dart bar()';\n" |
| 8223 "bar1() => 'library1.dart bar1()';\n" |
| 8224 "baz() => 'library1.dart baz()';\n" |
| 8225 "var bay;\n" |
| 8226 "typedef int bax(int a, int b);\n" |
| 8227 "class baw {}\n"; |
| 8228 const char* kImportedScript2Chars = |
| 8229 "library library2.dart;\n" |
| 8230 "var foo;\n" |
| 8231 "var foo2;\n" |
| 8232 "bar() => 'library2.dart bar()';\n" |
| 8233 "bar2() => 'library2.dart bar2()';\n" |
| 8234 "var baz;\n" |
| 8235 "bay() => 'library2.dart bay()';\n" |
| 8236 "typedef double bax(int a, int b);\n" |
| 8237 "var baw;\n"; |
| 8238 const char* kScriptChars = |
| 8239 "import 'library1.dart';\n" |
| 8240 "import 'library2.dart';\n"; |
| 8241 |
| 8242 // Load imported libs. |
| 8243 Dart_Handle url1 = NewString("library1.dart"); |
| 8244 Dart_Handle source1 = NewString(kImportedScript1Chars); |
| 8245 Dart_Handle imported_lib1 = Dart_LoadLibrary(url1, source1); |
| 8246 EXPECT_VALID(imported_lib1); |
| 8247 Dart_Handle url2 = NewString("library2.dart"); |
| 8248 Dart_Handle source2 = NewString(kImportedScript2Chars); |
| 8249 Dart_Handle imported_lib2 = Dart_LoadLibrary(url2, source2); |
| 8250 EXPECT_VALID(imported_lib2); |
| 8251 // Load main script. |
| 8252 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 8253 EXPECT_VALID(lib); |
| 8254 // Expect an error for ambiguous references. |
| 8255 EXPECT(Dart_IsError(Dart_LookupVariable(lib, NewString("foo")))); |
| 8256 EXPECT(Dart_IsError(Dart_LookupFunction(lib, NewString("bar")))); |
| 8257 EXPECT(Dart_IsError(Dart_LookupFunction(lib, NewString("baz")))); |
| 8258 EXPECT(Dart_IsError(Dart_LookupVariable(lib, NewString("bay")))); |
| 8259 EXPECT(Dart_IsError(Dart_GetClass(lib, NewString("bax")))); |
| 8260 EXPECT(Dart_IsError(Dart_GetClass(lib, NewString("baw")))); |
| 8261 // Variables foo1 and foo2 are unambiguous. |
| 8262 EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo1")))); |
| 8263 EXPECT(!Dart_IsError(Dart_LookupVariable(lib, NewString("foo2")))); |
| 8264 // Functions bar1 and bar2 are unambiguous. |
| 8265 EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar1")))); |
| 8266 EXPECT(!Dart_IsError(Dart_LookupFunction(lib, NewString("bar2")))); |
| 8267 } |
| 8268 |
8216 } // namespace dart | 8269 } // namespace dart |
OLD | NEW |