Skip to content

Commit 4105724

Browse files
authored
Cleanup tests and remove prefixFor. (#306)
1 parent fffde65 commit 4105724

File tree

7 files changed

+19
-464
lines changed

7 files changed

+19
-464
lines changed

lib/src/library.dart

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -180,48 +180,4 @@ class LibraryReader {
180180
}
181181
return [element];
182182
}
183-
184-
/// Returns the identifier prefix of [element] if it is referenced by one.
185-
///
186-
/// For example in the following file:
187-
/// ```
188-
/// import 'bar.dart' as bar;
189-
///
190-
/// bar.Bar b;
191-
/// ```
192-
///
193-
/// ... we'd assume that `b`'s type has a prefix of `bar`.
194-
///
195-
/// If there is no prefix, one could not be computed, `null` is returned.
196-
///
197-
/// If there is an attempt to read a prefix of a file _other_ than the current
198-
/// library being read this will throw [StateError], as it is not always
199-
/// possible to read details of the source file from other inputs.
200-
String _prefixForType(Element element) {
201-
final astNode = element.computeNode();
202-
if (astNode is VariableDeclaration) {
203-
final parentNode = astNode.parent as VariableDeclarationList;
204-
return _prefixForTypeAnnotation(parentNode.type);
205-
}
206-
return null;
207-
}
208-
209-
static String _prefixForTypeAnnotation(TypeAnnotation astNode) {
210-
if (astNode is NamedType) {
211-
return _prefixForIdentifier(astNode.name);
212-
}
213-
return null;
214-
}
215-
216-
static String _prefixForIdentifier(Identifier id) {
217-
return id is PrefixedIdentifier ? id.prefix.name : null;
218-
}
219183
}
220-
221-
// Testing-only access to LibraryReader._prefixFor.
222-
//
223-
// This is used to iterate on the tests without launching the feature.
224-
// Additionally it looks ike `computeNode()` will be deprecated, so we might
225-
// have to rewrite the entire body of the function in the near future; at least
226-
// the tests can help for correctness.
227-
String testingPrefixForType(LibraryReader r, Element e) => r._prefixForType(e);

test/analysis_utils.dart

Lines changed: 0 additions & 113 deletions
This file was deleted.

test/find_libraries_test.dart

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

@@ -7,39 +7,41 @@ import 'package:build_test/build_test.dart';
77
import 'package:source_gen/source_gen.dart';
88
import 'package:test/test.dart';
99

10+
final _source = r'''
11+
library test_lib;
12+
13+
export 'dart:collection' show LinkedHashMap;
14+
export 'package:source_gen/source_gen.dart' show Generator;
15+
import 'dart:async' show Stream;
16+
17+
class Example {}
18+
''';
19+
1020
void main() {
1121
LibraryReader library;
1222

1323
setUpAll(() async {
1424
library = await resolveSource(
15-
r'''
16-
library test_lib;
17-
18-
export 'dart:collection' show LinkedHashMap;
19-
export 'package:source_gen/source_gen.dart' show Generator;
20-
import 'dart:async' show Stream;
21-
22-
class Example {}
23-
''',
24-
(resolver) async =>
25-
new LibraryReader(await resolver.findLibraryByName('test_lib')));
25+
_source,
26+
(r) async => new LibraryReader(await r.findLibraryByName('test_lib')),
27+
);
2628
});
2729

28-
final isClassElement = const isInstanceOf<ClassElement>();
29-
3030
test('should return a type not exported', () {
31-
expect(library.findType('Example'), isClassElement);
31+
expect(library.findType('Example'), _isClassElement);
3232
});
3333

3434
test('should return a type exported from dart:', () {
35-
expect(library.findType('LinkedHashMap'), isClassElement);
35+
expect(library.findType('LinkedHashMap'), _isClassElement);
3636
});
3737

3838
test('should return a type exported from package:', () {
39-
expect(library.findType('Generator'), isClassElement);
39+
expect(library.findType('Generator'), _isClassElement);
4040
});
4141

4242
test('should not return a type imported', () {
4343
expect(library.findType('Stream'), isNull);
4444
});
4545
}
46+
47+
final _isClassElement = const isInstanceOf<ClassElement>();

test/library/prefix_for_type_test.dart

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)