Skip to content

Commit 96a511b

Browse files
authored
Migrate comment_referable tests (#2877)
1 parent 0a9c124 commit 96a511b

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

test/comment_referable/comment_referable_test.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
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

5-
// @dart=2.9
6-
75
library dartdoc.comment_reference_test;
86

7+
import 'package:collection/collection.dart';
98
import 'package:dartdoc/src/model/comment_referable.dart';
109
import 'package:dartdoc/src/model/model_object_builder.dart';
1110
import 'package:dartdoc/src/model/nameable.dart';
@@ -20,21 +19,22 @@ abstract class Base extends Nameable with CommentReferable {
2019

2120
List<Base> get children;
2221

23-
Base parent;
22+
Base? parent;
2423

2524
/// Utility function to quickly build structures similar to [ModelElement]
2625
/// hierarchies in dartdoc in tests.
2726
/// Returns the added (or already existing) [Base].
2827
Base add(String newName);
2928

30-
T lookup<T extends CommentReferable>(String value,
31-
{bool Function(CommentReferable) allowTree,
32-
bool Function(CommentReferable) filter}) =>
33-
referenceBy(value.split(_separator),
34-
allowTree: allowTree ?? (_) => true, filter: filter ?? (_) => true);
29+
CommentReferable? lookup<T extends CommentReferable?>(String value,
30+
{bool Function(CommentReferable?)? allowTree,
31+
bool Function(CommentReferable?)? filter}) {
32+
return referenceBy(value.split(_separator),
33+
allowTree: allowTree ?? (_) => true, filter: filter ?? (_) => true);
34+
}
3535

3636
@override
37-
Iterable<CommentReferable> get referenceGrandparentOverrides => null;
37+
Iterable<CommentReferable>? get referenceGrandparentOverrides => null;
3838
}
3939

4040
class Top extends Base {
@@ -49,13 +49,13 @@ class Top extends Base {
4949
Base add(String newName) {
5050
Base retval;
5151
var newNameSplit = newName.split(_separator).toList();
52-
var parent = children.firstWhere((c) => c.name == newNameSplit.first,
53-
orElse: () => null);
52+
var parent = children.firstWhereOrNull((c) => c.name == newNameSplit.first);
5453
if (parent == null) {
5554
parent = TopChild(newNameSplit.last, [], this);
5655
children.add(parent);
5756
retval = parent;
5857
}
58+
retval = parent;
5959
if (newNameSplit.length > 1) {
6060
retval = parent.add(newNameSplit.sublist(1).join(_separator));
6161
}
@@ -78,13 +78,13 @@ abstract class Child extends Base {
7878
Base add(String newName) {
7979
Base retval;
8080
var newNameSplit = newName.split(_separator).toList();
81-
var child = children.firstWhere((c) => c.name == newNameSplit.first,
82-
orElse: () => null);
81+
var child = children.firstWhereOrNull((c) => c.name == newNameSplit.first);
8382
if (child == null) {
8483
child = GenericChild(newNameSplit.last, [], this);
8584
children.add(child);
86-
retval = child;
8785
}
86+
87+
retval = child;
8888
if (newNameSplit.length > 1) {
8989
retval = child.add(newNameSplit.sublist(1).join(_separator));
9090
}
@@ -141,7 +141,7 @@ class GrandparentOverrider extends GenericChild {
141141

142142
void main() {
143143
group('Basic comment reference lookups', () {
144-
Top referable;
144+
late Top referable;
145145

146146
setUp(() {
147147
referable = Top('top', []);
@@ -157,10 +157,10 @@ void main() {
157157
});
158158

159159
test('Check that basic lookups work', () {
160-
expect(referable.lookup('lib1').name, equals('lib1'));
161-
expect(referable.lookup('lib2').name, equals('lib2'));
162-
expect(referable.lookup('lib1.class2.member1').name, equals('member1'));
163-
expect(referable.lookup('lib2.class3').name, equals('class3'));
160+
expect(referable.lookup('lib1')?.name, equals('lib1'));
161+
expect(referable.lookup('lib2')?.name, equals('lib2'));
162+
expect(referable.lookup('lib1.class2.member1')?.name, equals('member1'));
163+
expect(referable.lookup('lib2.class3')?.name, equals('class3'));
164164
});
165165

166166
test('Check that filters work', () {

test/comment_referable/parser_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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

5-
// @dart=2.9
6-
75
import 'package:dartdoc/src/comment_references/parser.dart';
86
import 'package:test/test.dart';
97

0 commit comments

Comments
 (0)