| Index: pkg/analysis_server/test/pub_summary_test.dart
|
| diff --git a/pkg/analysis_server/test/pub_summary_test.dart b/pkg/analysis_server/test/pub_summary_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e2f2f766558922419536dd0db90937f02d64f200
|
| --- /dev/null
|
| +++ b/pkg/analysis_server/test/pub_summary_test.dart
|
| @@ -0,0 +1,103 @@
|
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'package:analysis_server/src/pub_summary.dart';
|
| +import 'package:analyzer/file_system/file_system.dart';
|
| +import 'package:analyzer/src/util/fast_uri.dart';
|
| +import 'package:path/path.dart' as pathos;
|
| +import 'package:test_reflective_loader/test_reflective_loader.dart';
|
| +import 'package:unittest/unittest.dart' hide ERROR;
|
| +
|
| +import 'analysis_abstract.dart';
|
| +import 'mocks.dart';
|
| +import 'utils.dart';
|
| +
|
| +main() {
|
| + initializeTestEnvironment();
|
| + defineReflectiveTests(PubSummaryManagerTest);
|
| +}
|
| +
|
| +@reflectiveTest
|
| +class PubSummaryManagerTest extends AbstractAnalysisTest {
|
| + test_getPackageName() {
|
| + String getPackageName(String uriStr) {
|
| + return PubSummaryManager.getPackageName(FastUri.parse(uriStr));
|
| + }
|
| + expect(getPackageName('package:foo/bar.dart'), 'foo');
|
| + expect(getPackageName('package:foo/bar/baz.dart'), 'foo');
|
| + expect(getPackageName('wrong:foo/bar.dart'), isNull);
|
| + expect(getPackageName('package:foo'), isNull);
|
| + }
|
| +
|
| + test_isPathInPubCache_posix() {
|
| + expect(
|
| + PubSummaryManager.isPathInPubCache(pathos.posix,
|
| + '/home/.pub-cache/hosted/pub.dartlang.org/foo/lib/bar.dart'),
|
| + isTrue);
|
| + expect(
|
| + PubSummaryManager.isPathInPubCache(
|
| + pathos.posix, '/home/.pub-cache/foo/lib/bar.dart'),
|
| + isTrue);
|
| + expect(
|
| + PubSummaryManager.isPathInPubCache(
|
| + pathos.posix, '/home/sources/dart/foo/lib/bar.dart'),
|
| + isFalse);
|
| + }
|
| +
|
| + test_isPathInPubCache_windows() {
|
| + expect(
|
| + PubSummaryManager.isPathInPubCache(pathos.windows,
|
| + r'C:\Users\user\Setters\Pub\Cache\hosted\foo\lib\bar.dart'),
|
| + isTrue);
|
| + expect(
|
| + PubSummaryManager.isPathInPubCache(
|
| + pathos.windows, r'C:\Users\user\Sources\Dart\foo\lib\bar.dart'),
|
| + isFalse);
|
| + }
|
| +
|
| + test_onComplete() async {
|
| + String cachePath = '/home/.pub-cache/hosted/pub.dartlang.org';
|
| + // Create package files.
|
| + resourceProvider.newFile(
|
| + '$cachePath/aaa/lib/a.dart',
|
| + '''
|
| +class A {}
|
| +''');
|
| + resourceProvider.newFile(
|
| + '$cachePath/aaa/lib/src/a2.dart',
|
| + '''
|
| +class A2 {}
|
| +''');
|
| + resourceProvider.newFile(
|
| + '$cachePath/bbb/lib/b.dart',
|
| + '''
|
| +class B {}
|
| +''');
|
| + // Configure package map.
|
| + Folder libFolderA = resourceProvider.newFolder('$cachePath/aaa/lib');
|
| + Folder libFolderB = resourceProvider.newFolder('$cachePath/bbb/lib');
|
| + packageMapProvider.packageMap = {
|
| + 'aaa': [libFolderA],
|
| + 'bbb': [libFolderB],
|
| + };
|
| +
|
| + // Analyze a file that uses these two packages.
|
| + addTestFile('''
|
| +import 'package:aaa/a.dart';
|
| +import 'package:bbb/b.dart';
|
| +main() {
|
| + new A();
|
| + new B();
|
| +}
|
| +''');
|
| + createProject();
|
| + await pumpEventQueue();
|
| + await server.pubSummaryManager.onComplete;
|
| + // The summary files must be ready.
|
| + File fileA = libFolderA.parent.getChildAssumingFile('summary_spec.full.ds');
|
| + File fileB = libFolderB.parent.getChildAssumingFile('summary_spec.full.ds');
|
| + expect(fileA.exists, isTrue);
|
| + expect(fileB.exists, isTrue);
|
| + }
|
| +}
|
|
|