diff --git a/test/dartdoc_test_base.dart b/test/dartdoc_test_base.dart index 4bc7e764eb..da629b2cd8 100644 --- a/test/dartdoc_test_base.dart +++ b/test/dartdoc_test_base.dart @@ -40,7 +40,7 @@ abstract class DartdocTestBase { String get sdkConstraint => '>=3.3.0 <4.0.0'; - List get experiments => []; + List get experiments => ['wildcard-variables']; bool get skipUnreachableSdkLibraries => true; diff --git a/test/parameter_test.dart b/test/parameter_test.dart index f98df5d2d7..f43a6361e9 100644 --- a/test/parameter_test.dart +++ b/test/parameter_test.dart @@ -20,8 +20,48 @@ void main() { class ParameterTest extends DartdocTestBase { @override String get libraryName => 'parameters'; - @override - String get sdkConstraint => '>=2.17.0 <3.0.0'; + + void test_formalParameter_referenced() async { + var library = await bootPackageWithLibrary(''' +/// Text [p]. +void f(int p) {} +'''); + var f = library.functions.named('f'); + // There is no link, but also no wrong link or crash. + expect(f.documentationAsHtml, '

Text p.

'); + } + + void test_formalParameter_referenced_notShadowedElement() async { + var library = await bootPackageWithLibrary(''' +/// Text [p]. +void f(int p) {} +var p = 0; +'''); + var f = library.functions.named('f'); + // There is no link, but also no wrong link or crash. + expect(f.documentationAsHtml, '

Text p.

'); + } + + void test_formalParameter_referenced_notShadowedPrefix() async { + var library = await bootPackageWithLibrary(''' +import 'dart:async' as p; +/// Text [p]. +void f(int p) {} +'''); + var f = library.functions.named('f'); + // There is no link, but also no wrong link or crash. + expect(f.documentationAsHtml, '

Text p.

'); + } + + void test_formalParameter_referenced_wildcard() async { + var library = await bootPackageWithLibrary(''' +/// Text [_]. +void f(int _) {} +'''); + var f = library.functions.named('f'); + // There is no link, but also no wrong link or crash. + expect(f.documentationAsHtml, '

Text _.

'); + } void test_formalParameter_generic_method() async { var library = await bootPackageWithLibrary(''' @@ -203,7 +243,48 @@ class A { ''')); } - void test_superConstructorParameter_fieldFormal() async { + void test_fieldFormalParameter_referenced() async { + var library = await bootPackageWithLibrary(''' +class C { + int p; + /// Text [p]. + C(this.p); +} +'''); + var cConstructor = library.classes.named('C').constructors.named('C'); + // There is no link, but also no wrong link or crash. + expect(cConstructor.documentationAsHtml, '

Text p.

'); + } + + void test_fieldFormalParameter_referenced_wildcard() async { + var library = await bootPackageWithLibrary(''' +class C { + int _; + /// Text [_]. + C(this._); +} +'''); + var cConstructor = library.classes.named('C').constructors.named('C'); + // There is no link, but also no wrong link or crash. + expect(cConstructor.documentationAsHtml, '

Text _.

'); + } + + void test_superParameter_referenced_wildcard() async { + var library = await bootPackageWithLibrary(''' +class C { + C(int _); +} +class D extends C { + /// Text [_]. + D(super._) {} +} +'''); + var dConstructor = library.classes.named('D').constructors.named('D'); + // There is no link, but also no wrong link or crash. + expect(dConstructor.documentationAsHtml, '

Text _.

'); + } + + void test_superParameter_fieldFormal() async { var library = await bootPackageWithLibrary(''' class C { int f; @@ -225,7 +306,7 @@ class D extends C { ''')); } - void test_superConstructorParameter_isSubtype() async { + void test_superParameter_isSubtype() async { var library = await bootPackageWithLibrary(''' class C { C.positionalNum(num g); @@ -246,7 +327,7 @@ class D extends C { ''')); } - void test_superConstructorParameter_superParameter() async { + void test_superParameter_superParameter() async { var library = await bootPackageWithLibrary(''' class C { C.requiredPositional(int a); diff --git a/test/type_parameter_test.dart b/test/type_parameter_test.dart new file mode 100644 index 0000000000..d5d02ee320 --- /dev/null +++ b/test/type_parameter_test.dart @@ -0,0 +1,54 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:test/test.dart'; +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import 'dartdoc_test_base.dart'; +import 'src/utils.dart'; + +void main() { + defineReflectiveSuite(() { + defineReflectiveTests(TypeParameterTest); + }); +} + +@reflectiveTest +class TypeParameterTest extends DartdocTestBase { + @override + String get libraryName => 'type_parameters'; + + void test_referenced() async { + var library = await bootPackageWithLibrary(''' +/// Text [T]. +void f(int p) {} +typedef T = int; +'''); + var f = library.functions.named('f'); + // There is no link, but also no wrong link or crash. + expect(f.documentationAsHtml, '

Text T.

'); + } + + void test_referenced_wildcard() async { + var library = await bootPackageWithLibrary(''' +/// Text [_]. +void f<_>() {} +'''); + var f = library.functions.named('f'); + // There is no link, but also no wrong link or crash. + expect(f.documentationAsHtml, '

Text _.

'); + } + + void test_referenced_wildcardInParent() async { + var library = await bootPackageWithLibrary(''' +class C<_> { + /// Text [_]. + void m() {} +} +'''); + var m = library.classes.named('C').instanceMethods.named('m'); + // There is no link, but also no wrong link or crash. + expect(m.documentationAsHtml, '

Text _.

'); + } +}