Skip to content

Commit 64920c6

Browse files
committed
Add tests supporting the wildcard feature
1 parent ce09815 commit 64920c6

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

test/dartdoc_test_base.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class DartdocTestBase {
4040

4141
String get sdkConstraint => '>=3.3.0 <4.0.0';
4242

43-
List<String> get experiments => [];
43+
List<String> get experiments => ['wildcards'];
4444

4545
bool get skipUnreachableSdkLibraries => true;
4646

test/parameter_test.dart

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,48 @@ void main() {
2020
class ParameterTest extends DartdocTestBase {
2121
@override
2222
String get libraryName => 'parameters';
23-
@override
24-
String get sdkConstraint => '>=2.17.0 <3.0.0';
23+
24+
void test_formalParameter_referenced() async {
25+
var library = await bootPackageWithLibrary('''
26+
/// Text [p].
27+
void f(int p) {}
28+
''');
29+
var f = library.functions.named('f');
30+
// There is no link, but also no wrong link or crash.
31+
expect(f.documentationAsHtml, '<p>Text <code>p</code>.</p>');
32+
}
33+
34+
void test_formalParameter_referenced_notShadowedElement() async {
35+
var library = await bootPackageWithLibrary('''
36+
/// Text [p].
37+
void f(int p) {}
38+
var p = 0;
39+
''');
40+
var f = library.functions.named('f');
41+
// There is no link, but also no wrong link or crash.
42+
expect(f.documentationAsHtml, '<p>Text <code>p</code>.</p>');
43+
}
44+
45+
void test_formalParameter_referenced_notShadowedPrefix() async {
46+
var library = await bootPackageWithLibrary('''
47+
import 'dart:async' as p;
48+
/// Text [p].
49+
void f(int p) {}
50+
''');
51+
var f = library.functions.named('f');
52+
// There is no link, but also no wrong link or crash.
53+
expect(f.documentationAsHtml, '<p>Text <code>p</code>.</p>');
54+
}
55+
56+
void test_formalParameter_referenced_wildcard() async {
57+
var library = await bootPackageWithLibrary('''
58+
/// Text [_].
59+
void f(int _) {}
60+
''');
61+
var f = library.functions.named('f');
62+
// There is no link, but also no wrong link or crash.
63+
expect(f.documentationAsHtml, '<p>Text <code>_</code>.</p>');
64+
}
2565

2666
void test_formalParameter_generic_method() async {
2767
var library = await bootPackageWithLibrary('''

test/type_parameter_test.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2022, 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+
import 'package:test/test.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import 'dartdoc_test_base.dart';
9+
import 'src/utils.dart';
10+
11+
void main() {
12+
defineReflectiveSuite(() {
13+
defineReflectiveTests(TypeParameterTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class TypeParameterTest extends DartdocTestBase {
19+
@override
20+
String get libraryName => 'type_parameters';
21+
22+
void test_referenced() async {
23+
var library = await bootPackageWithLibrary('''
24+
/// Text [T].
25+
void f<T>(int p) {}
26+
typedef T = int;
27+
''');
28+
var f = library.functions.named('f');
29+
// There is no link, but also no wrong link or crash.
30+
expect(f.documentationAsHtml, '<p>Text <code>T</code>.</p>');
31+
}
32+
33+
void test_referenced_wildcard() async {
34+
var library = await bootPackageWithLibrary('''
35+
/// Text [_].
36+
void f<_>() {}
37+
''');
38+
var f = library.functions.named('f');
39+
// There is no link, but also no wrong link or crash.
40+
expect(f.documentationAsHtml, '<p>Text <code>_</code>.</p>');
41+
}
42+
43+
void test_referenced_wildcardInParent() async {
44+
var library = await bootPackageWithLibrary('''
45+
class C<_> {
46+
/// Text [_].
47+
void m() {}
48+
}
49+
''');
50+
var m = library.classes.named('C').instanceMethods.named('m');
51+
// There is no link, but also no wrong link or crash.
52+
expect(m.documentationAsHtml, '<p>Text <code>_</code>.</p>');
53+
}
54+
}

0 commit comments

Comments
 (0)