| Index: pkg/analyzer/test/src/task/dart_test.dart
|
| diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart
|
| index 951ee79779aa39a329cbe8480c6ca1ed8d8653bf..a95d933015c97bc3da152204503062e17057a624 100644
|
| --- a/pkg/analyzer/test/src/task/dart_test.dart
|
| +++ b/pkg/analyzer/test/src/task/dart_test.dart
|
| @@ -3238,6 +3238,108 @@ class A {''');
|
| expect(outputs[UNITS], hasLength(2));
|
| }
|
|
|
| + test_perform_library_configurations_bool1() {
|
| + context.declaredVariables.define('dart.library.io', 'true');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + newSource('/bar.dart', '');
|
| + newSource('/bar_io.dart', '');
|
| + newSource('/bar_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +export 'bar.dart'
|
| + if (dart.library.io) 'bar_io.dart'
|
| + if (dart.library.html) 'bar_html.dart';
|
| +''');
|
| + var unit = outputs[PARSED_UNIT] as CompilationUnit;
|
| +
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_io.dart');
|
| +
|
| + var import = unit.directives[0] as ImportDirective;
|
| + expect(import.uriSource.shortName, 'foo.dart');
|
| + expect(import.selectedSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[0].uriSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[1].uriSource.shortName, 'foo_html.dart');
|
| +
|
| + var exported = outputs[EXPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(exported, 'bar_io.dart');
|
| +
|
| + var export = unit.directives[1] as ExportDirective;
|
| + expect(export.uriSource.shortName, 'bar.dart');
|
| + expect(export.selectedSource.shortName, 'bar_io.dart');
|
| + expect(export.configurations[0].uriSource.shortName, 'bar_io.dart');
|
| + expect(export.configurations[1].uriSource.shortName, 'bar_html.dart');
|
| + }
|
| +
|
| + test_perform_library_configurations_bool2() {
|
| + context.declaredVariables.define('dart.library.html', 'true');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_html.dart');
|
| + }
|
| +
|
| + test_perform_library_configurations_default() {
|
| + context.declaredVariables.define('dart.library.io', 'false');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo.dart');
|
| + }
|
| +
|
| + test_perform_library_configurations_preferFirst() {
|
| + context.declaredVariables.define('dart.library.io', 'true');
|
| + context.declaredVariables.define('dart.library.html', 'true');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_io.dart', '');
|
| + newSource('/foo_html.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.library.io) 'foo_io.dart'
|
| + if (dart.library.html) 'foo_html.dart';
|
| +''');
|
| +
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_io.dart');
|
| +
|
| + var unit = outputs[PARSED_UNIT] as CompilationUnit;
|
| + var import = unit.directives[0] as ImportDirective;
|
| + expect(import.uriSource.shortName, 'foo.dart');
|
| + expect(import.selectedSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[0].uriSource.shortName, 'foo_io.dart');
|
| + expect(import.configurations[1].uriSource.shortName, 'foo_html.dart');
|
| + }
|
| +
|
| + test_perform_library_configurations_value() {
|
| + context.declaredVariables.define('dart.platform', 'Windows');
|
| + newSource('/foo.dart', '');
|
| + newSource('/foo_posix.dart', '');
|
| + newSource('/foo_windows.dart', '');
|
| + _performParseTask(r'''
|
| +import 'foo.dart'
|
| + if (dart.platform == 'Posix') 'foo_posix.dart'
|
| + if (dart.platform == 'Windows') 'foo_windows.dart';
|
| +''');
|
| + var imported = outputs[IMPORTED_LIBRARIES] as List<Source>;
|
| + _assertContainsOnlyShortName(imported, 'foo_windows.dart');
|
| + }
|
| +
|
| test_perform_library_selfReferenceAsPart() {
|
| _performParseTask(r'''
|
| library lib;
|
| @@ -3264,6 +3366,20 @@ class B {}''');
|
| expect(outputs[UNITS], hasLength(1));
|
| }
|
|
|
| + /**
|
| + * Assert that [sources] contains either just a source with the given
|
| + * [expectedShortName], or it and the `dart:core` source.
|
| + */
|
| + void _assertContainsOnlyShortName(
|
| + List<Source> sources, String expectedShortName) {
|
| + Iterable<String> shortNames = sources.map((s) => s.shortName);
|
| + if (shortNames.length == 2) {
|
| + expect(shortNames, unorderedEquals(['core.dart', expectedShortName]));
|
| + } else {
|
| + expect(shortNames, unorderedEquals([expectedShortName]));
|
| + }
|
| + }
|
| +
|
| void _performParseTask(String content) {
|
| if (content == null) {
|
| source = resourceProvider.getFile('/test.dart').createSource();
|
|
|