Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: pkg/analysis_server/test/services/dependencies/reachable_source_collector_test.dart

Issue 1491013002: Analysis request `getReachableSources` (#24893). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: spec_bump Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.services.dependencies.import_collector;
6
7 import 'package:analysis_server/src/services/dependencies/reachable_source_colle ctor.dart';
8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart';
11 import 'package:unittest/unittest.dart';
12
13 import '../../abstract_context.dart';
14 import '../../utils.dart';
15
16 main() {
17 initializeTestEnvironment();
18 defineReflectiveTests(ReachableSourceCollectorTest);
19 }
20
21 @reflectiveTest
22 class ReachableSourceCollectorTest extends AbstractContextTest {
23 CompilationUnit addLibrary(String path, String contents) =>
24 resolveLibraryUnit(addSource(path, contents));
25
26 Map<String, List<String>> importsFor(Source source) =>
27 new ReachableSourceCollector(source, context).collectSources();
28
29 test_null_context() {
30 Source lib = addSource('/lib.dart', '');
31 expect(() => new ReachableSourceCollector(lib, null),
32 throwsA(new isInstanceOf<ArgumentError>()));
33 }
34
35 test_null_source() {
36 expect(() => new ReachableSourceCollector(null, context),
37 throwsA(new isInstanceOf<ArgumentError>()));
38 }
39
40 test_sources() {
41 Source lib1 = addSource(
42 '/lib1.dart',
43 '''
44 import "lib2.dart";
45 import "dart:html";''');
46 Source lib2 = addSource('/lib2.dart', 'import "lib1.dart";');
47
48 Source lib3 = addSource('/lib3.dart', 'import "lib4.dart";');
49 addSource('/lib4.dart', 'import "lib3.dart";');
50
51 Map<String, List<String>> imports = importsFor(lib1);
52
53 // Verify keys.
54 expect(
55 imports.keys,
56 unorderedEquals([
57 'dart:_internal',
58 'dart:async',
59 'dart:core',
60 'dart:html',
61 'dart:math',
62 'file:///lib1.dart',
63 'file:///lib2.dart',
64 ]));
65 // Values.
66 expect(imports['file:///lib1.dart'],
67 unorderedEquals(['dart:core', 'dart:html', 'file:///lib2.dart']));
68
69 // Check transitivity.
70 expect(importsFor(lib2).keys, contains('dart:html'));
71
72 // Cycles should be OK.
73 expect(
74 importsFor(lib3).keys,
75 unorderedEquals([
76 'dart:_internal',
77 'dart:async',
78 'dart:core',
79 'dart:math',
80 'file:///lib3.dart',
81 'file:///lib4.dart'
82 ]));
83 }
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698