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

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: 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_sources() {
30 Source lib1 = addSource(
31 '/lib1.dart',
32 '''
33 import "lib2.dart";
34 import "dart:html";''');
35 Source lib2 = addSource('/lib2.dart', 'import "lib1.dart";');
36
37 Source lib3 = addSource('/lib3.dart', 'import "lib4.dart";');
38 addSource('/lib4.dart', 'import "lib3.dart";');
39
40 Map<String, List<String>> imports = importsFor(lib1);
41
42 // Verify keys.
43 expect(
44 imports.keys,
45 unorderedEquals([
46 'dart:_internal',
47 'dart:async',
48 'dart:core',
49 'dart:html',
50 'dart:math',
51 'file:///lib1.dart',
52 'file:///lib2.dart',
53 ]));
54 // Values.
55 expect(imports['file:///lib1.dart'],
56 unorderedEquals(['dart:core', 'dart:html', 'file:///lib2.dart']));
57
58 // Check transitivity.
59 expect(importsFor(lib2).keys, contains('dart:html'));
60
61 // Cycles should be OK.
62 expect(
63 importsFor(lib3).keys,
64 unorderedEquals([
65 'dart:_internal',
66 'dart:async',
67 'dart:core',
68 'dart:math',
69 'file:///lib3.dart',
70 'file:///lib4.dart'
71 ]));
72 }
73
74 test_null_context() {
75 Source lib = addSource('/lib.dart', '');
76 // Shouldn't throw an exception.
77 expect(new ReachableSourceCollector(lib, null).collectSources(), isEmpty);
78 }
79
80 test_null_source() {
81 // Shouldn't throw an exception.
82 expect(
83 new ReachableSourceCollector(null, context).collectSources(), isEmpty);
84 }
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698