Skip to content

Commit 31e110d

Browse files
authored
Add tests supporting the wildcard feature (#3835)
1 parent ce09815 commit 31e110d

File tree

3 files changed

+141
-6
lines changed

3 files changed

+141
-6
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 => ['wildcard-variables'];
4444

4545
bool get skipUnreachableSdkLibraries => true;
4646

test/parameter_test.dart

Lines changed: 86 additions & 5 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('''
@@ -203,7 +243,48 @@ class A {
203243
'''));
204244
}
205245

206-
void test_superConstructorParameter_fieldFormal() async {
246+
void test_fieldFormalParameter_referenced() async {
247+
var library = await bootPackageWithLibrary('''
248+
class C {
249+
int p;
250+
/// Text [p].
251+
C(this.p);
252+
}
253+
''');
254+
var cConstructor = library.classes.named('C').constructors.named('C');
255+
// There is no link, but also no wrong link or crash.
256+
expect(cConstructor.documentationAsHtml, '<p>Text <code>p</code>.</p>');
257+
}
258+
259+
void test_fieldFormalParameter_referenced_wildcard() async {
260+
var library = await bootPackageWithLibrary('''
261+
class C {
262+
int _;
263+
/// Text [_].
264+
C(this._);
265+
}
266+
''');
267+
var cConstructor = library.classes.named('C').constructors.named('C');
268+
// There is no link, but also no wrong link or crash.
269+
expect(cConstructor.documentationAsHtml, '<p>Text <code>_</code>.</p>');
270+
}
271+
272+
void test_superParameter_referenced_wildcard() async {
273+
var library = await bootPackageWithLibrary('''
274+
class C {
275+
C(int _);
276+
}
277+
class D extends C {
278+
/// Text [_].
279+
D(super._) {}
280+
}
281+
''');
282+
var dConstructor = library.classes.named('D').constructors.named('D');
283+
// There is no link, but also no wrong link or crash.
284+
expect(dConstructor.documentationAsHtml, '<p>Text <code>_</code>.</p>');
285+
}
286+
287+
void test_superParameter_fieldFormal() async {
207288
var library = await bootPackageWithLibrary('''
208289
class C {
209290
int f;
@@ -225,7 +306,7 @@ class D extends C {
225306
'''));
226307
}
227308

228-
void test_superConstructorParameter_isSubtype() async {
309+
void test_superParameter_isSubtype() async {
229310
var library = await bootPackageWithLibrary('''
230311
class C {
231312
C.positionalNum(num g);
@@ -246,7 +327,7 @@ class D extends C {
246327
'''));
247328
}
248329

249-
void test_superConstructorParameter_superParameter() async {
330+
void test_superParameter_superParameter() async {
250331
var library = await bootPackageWithLibrary('''
251332
class C {
252333
C.requiredPositional(int a);

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) 2024, 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)