OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/constant/value.dart'; | 10 import 'package:analyzer/dart/constant/value.dart'; |
(...skipping 3012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3023 addLibrarySource('/a.dart', 'class C {}'); | 3023 addLibrarySource('/a.dart', 'class C {}'); |
3024 checkLibrary('export "a.dart";'); | 3024 checkLibrary('export "a.dart";'); |
3025 } | 3025 } |
3026 | 3026 |
3027 test_export_class_type_alias() { | 3027 test_export_class_type_alias() { |
3028 addLibrarySource( | 3028 addLibrarySource( |
3029 '/a.dart', 'class C {} exends _D with _E; class _D {} class _E {}'); | 3029 '/a.dart', 'class C {} exends _D with _E; class _D {} class _E {}'); |
3030 checkLibrary('export "a.dart";'); | 3030 checkLibrary('export "a.dart";'); |
3031 } | 3031 } |
3032 | 3032 |
| 3033 test_export_configurations_useDefault() { |
| 3034 context.declaredVariables.define('dart.library.io', 'false'); |
| 3035 addLibrarySource('/foo.dart', 'class A {}'); |
| 3036 addLibrarySource('/foo_io.dart', 'class A {}'); |
| 3037 addLibrarySource('/foo_html.dart', 'class A {}'); |
| 3038 LibraryElementImpl library = checkLibrary(r''' |
| 3039 export 'foo.dart' |
| 3040 if (dart.library.io) 'foo_io.dart' |
| 3041 if (dart.library.html) 'foo_html.dart'; |
| 3042 '''); |
| 3043 expect(library.exports[0].uri, 'foo.dart'); |
| 3044 expect(library.exports[0].exportedLibrary.source.shortName, 'foo.dart'); |
| 3045 } |
| 3046 |
| 3047 test_export_configurations_useFirst() { |
| 3048 context.declaredVariables.define('dart.library.io', 'true'); |
| 3049 context.declaredVariables.define('dart.library.html', 'true'); |
| 3050 addLibrarySource('/foo.dart', 'class A {}'); |
| 3051 addLibrarySource('/foo_io.dart', 'class A {}'); |
| 3052 addLibrarySource('/foo_html.dart', 'class A {}'); |
| 3053 LibraryElementImpl library = checkLibrary(r''' |
| 3054 export 'foo.dart' |
| 3055 if (dart.library.io) 'foo_io.dart' |
| 3056 if (dart.library.html) 'foo_html.dart'; |
| 3057 '''); |
| 3058 expect(library.exports[0].uri, 'foo_io.dart'); |
| 3059 expect(library.exports[0].exportedLibrary.source.shortName, 'foo_io.dart'); |
| 3060 } |
| 3061 |
| 3062 test_export_configurations_useSecond() { |
| 3063 context.declaredVariables.define('dart.library.io', 'false'); |
| 3064 context.declaredVariables.define('dart.library.html', 'true'); |
| 3065 addLibrarySource('/foo.dart', 'class A {}'); |
| 3066 addLibrarySource('/foo_io.dart', 'class A {}'); |
| 3067 addLibrarySource('/foo_html.dart', 'class A {}'); |
| 3068 LibraryElementImpl library = checkLibrary(r''' |
| 3069 export 'foo.dart' |
| 3070 if (dart.library.io) 'foo_io.dart' |
| 3071 if (dart.library.html) 'foo_html.dart'; |
| 3072 '''); |
| 3073 ExportElement export = library.exports[0]; |
| 3074 expect(export.uri, 'foo_html.dart'); |
| 3075 expect(export.exportedLibrary.source.shortName, 'foo_html.dart'); |
| 3076 } |
| 3077 |
3033 test_export_function() { | 3078 test_export_function() { |
3034 addLibrarySource('/a.dart', 'f() {}'); | 3079 addLibrarySource('/a.dart', 'f() {}'); |
3035 checkLibrary('export "a.dart";'); | 3080 checkLibrary('export "a.dart";'); |
3036 } | 3081 } |
3037 | 3082 |
3038 test_export_getter() { | 3083 test_export_getter() { |
3039 addLibrarySource('/a.dart', 'get f() => null;'); | 3084 addLibrarySource('/a.dart', 'get f() => null;'); |
3040 checkLibrary('export "a.dart";'); | 3085 checkLibrary('export "a.dart";'); |
3041 } | 3086 } |
3042 | 3087 |
(...skipping 30 matching lines...) Expand all Loading... |
3073 test_export_variable_const() { | 3118 test_export_variable_const() { |
3074 addLibrarySource('/a.dart', 'const x = 0;'); | 3119 addLibrarySource('/a.dart', 'const x = 0;'); |
3075 checkLibrary('export "a.dart";'); | 3120 checkLibrary('export "a.dart";'); |
3076 } | 3121 } |
3077 | 3122 |
3078 test_export_variable_final() { | 3123 test_export_variable_final() { |
3079 addLibrarySource('/a.dart', 'final x = 0;'); | 3124 addLibrarySource('/a.dart', 'final x = 0;'); |
3080 checkLibrary('export "a.dart";'); | 3125 checkLibrary('export "a.dart";'); |
3081 } | 3126 } |
3082 | 3127 |
| 3128 test_exportImport_configurations_useDefault() { |
| 3129 context.declaredVariables.define('dart.library.io', 'false'); |
| 3130 addLibrarySource('/foo.dart', 'class A {}'); |
| 3131 addLibrarySource('/foo_io.dart', 'class A {}'); |
| 3132 addLibrarySource('/foo_html.dart', 'class A {}'); |
| 3133 addLibrarySource( |
| 3134 '/bar.dart', |
| 3135 r''' |
| 3136 export 'foo.dart' |
| 3137 if (dart.library.io) 'foo_io.dart' |
| 3138 if (dart.library.html) 'foo_html.dart'; |
| 3139 '''); |
| 3140 LibraryElementImpl library = checkLibrary(r''' |
| 3141 import 'bar.dart'; |
| 3142 class B extends A {} |
| 3143 '''); |
| 3144 var typeA = library.definingCompilationUnit.getType('B').supertype; |
| 3145 expect(typeA.element.source.shortName, 'foo.dart'); |
| 3146 } |
| 3147 |
| 3148 test_exportImport_configurations_useFirst() { |
| 3149 context.declaredVariables.define('dart.library.io', 'true'); |
| 3150 context.declaredVariables.define('dart.library.html', 'true'); |
| 3151 addLibrarySource('/foo.dart', 'class A {}'); |
| 3152 addLibrarySource('/foo_io.dart', 'class A {}'); |
| 3153 addLibrarySource('/foo_html.dart', 'class A {}'); |
| 3154 addLibrarySource( |
| 3155 '/bar.dart', |
| 3156 r''' |
| 3157 export 'foo.dart' |
| 3158 if (dart.library.io) 'foo_io.dart' |
| 3159 if (dart.library.html) 'foo_html.dart'; |
| 3160 '''); |
| 3161 var library = checkLibrary(r''' |
| 3162 import 'bar.dart'; |
| 3163 class B extends A {} |
| 3164 '''); |
| 3165 var typeA = library.definingCompilationUnit.getType('B').supertype; |
| 3166 expect(typeA.element.source.shortName, 'foo_io.dart'); |
| 3167 } |
| 3168 |
3083 test_exports() { | 3169 test_exports() { |
3084 addLibrarySource('/a.dart', 'library a;'); | 3170 addLibrarySource('/a.dart', 'library a;'); |
3085 addLibrarySource('/b.dart', 'library b;'); | 3171 addLibrarySource('/b.dart', 'library b;'); |
3086 checkLibrary('export "a.dart"; export "b.dart";'); | 3172 checkLibrary('export "a.dart"; export "b.dart";'); |
3087 } | 3173 } |
3088 | 3174 |
3089 test_field_documented() { | 3175 test_field_documented() { |
3090 checkLibrary(''' | 3176 checkLibrary(''' |
3091 class C { | 3177 class C { |
3092 /** | 3178 /** |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3387 } | 3473 } |
3388 | 3474 |
3389 test_implicitTopLevelVariable_getterFirst() { | 3475 test_implicitTopLevelVariable_getterFirst() { |
3390 checkLibrary('int get x => 0; void set x(int value) {}'); | 3476 checkLibrary('int get x => 0; void set x(int value) {}'); |
3391 } | 3477 } |
3392 | 3478 |
3393 test_implicitTopLevelVariable_setterFirst() { | 3479 test_implicitTopLevelVariable_setterFirst() { |
3394 checkLibrary('void set x(int value) {} int get x => 0;'); | 3480 checkLibrary('void set x(int value) {} int get x => 0;'); |
3395 } | 3481 } |
3396 | 3482 |
| 3483 test_import_configurations_useDefault() { |
| 3484 context.declaredVariables.define('dart.library.io', 'false'); |
| 3485 addLibrarySource('/foo.dart', 'class A {}'); |
| 3486 addLibrarySource('/foo_io.dart', 'class A {}'); |
| 3487 addLibrarySource('/foo_html.dart', 'class A {}'); |
| 3488 var library = checkLibrary(r''' |
| 3489 import 'foo.dart' |
| 3490 if (dart.library.io) 'foo_io.dart' |
| 3491 if (dart.library.html) 'foo_html.dart'; |
| 3492 |
| 3493 class B extends A {} |
| 3494 '''); |
| 3495 var typeA = library.definingCompilationUnit.getType('B').supertype; |
| 3496 expect(typeA.element.source.shortName, 'foo.dart'); |
| 3497 } |
| 3498 |
| 3499 test_import_configurations_useFirst() { |
| 3500 context.declaredVariables.define('dart.library.io', 'true'); |
| 3501 context.declaredVariables.define('dart.library.html', 'true'); |
| 3502 addLibrarySource('/foo.dart', 'class A {}'); |
| 3503 addLibrarySource('/foo_io.dart', 'class A {}'); |
| 3504 addLibrarySource('/foo_html.dart', 'class A {}'); |
| 3505 var library = checkLibrary(r''' |
| 3506 import 'foo.dart' |
| 3507 if (dart.library.io) 'foo_io.dart' |
| 3508 if (dart.library.html) 'foo_html.dart'; |
| 3509 |
| 3510 class B extends A {} |
| 3511 '''); |
| 3512 var typeA = library.definingCompilationUnit.getType('B').supertype; |
| 3513 expect(typeA.element.source.shortName, 'foo_io.dart'); |
| 3514 } |
| 3515 |
3397 test_import_deferred() { | 3516 test_import_deferred() { |
3398 addLibrarySource('/a.dart', 'f() {}'); | 3517 addLibrarySource('/a.dart', 'f() {}'); |
3399 checkLibrary('import "a.dart" deferred as p; main() { p.f(); }'); | 3518 checkLibrary('import "a.dart" deferred as p; main() { p.f(); }'); |
3400 } | 3519 } |
3401 | 3520 |
3402 test_import_hide() { | 3521 test_import_hide() { |
3403 addLibrary('dart:async'); | 3522 addLibrary('dart:async'); |
3404 checkLibrary('import "dart:async" hide Stream, Completer; Future f;'); | 3523 checkLibrary('import "dart:async" hide Stream, Completer; Future f;'); |
3405 } | 3524 } |
3406 | 3525 |
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4681 fail('Unexpectedly tried to get unlinked summary for $uri'); | 4800 fail('Unexpectedly tried to get unlinked summary for $uri'); |
4682 } | 4801 } |
4683 return serializedUnit; | 4802 return serializedUnit; |
4684 } | 4803 } |
4685 | 4804 |
4686 @override | 4805 @override |
4687 bool hasLibrarySummary(String uri) { | 4806 bool hasLibrarySummary(String uri) { |
4688 return true; | 4807 return true; |
4689 } | 4808 } |
4690 } | 4809 } |
OLD | NEW |