Skip to content

Commit

Permalink
Add tests supporting the wildcard feature (#3835)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Aug 13, 2024
1 parent ce09815 commit 31e110d
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/dartdoc_test_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class DartdocTestBase {

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

List<String> get experiments => [];
List<String> get experiments => ['wildcard-variables'];

bool get skipUnreachableSdkLibraries => true;

Expand Down
91 changes: 86 additions & 5 deletions test/parameter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<p>Text <code>p</code>.</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, '<p>Text <code>p</code>.</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, '<p>Text <code>p</code>.</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, '<p>Text <code>_</code>.</p>');
}

void test_formalParameter_generic_method() async {
var library = await bootPackageWithLibrary('''
Expand Down Expand Up @@ -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, '<p>Text <code>p</code>.</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, '<p>Text <code>_</code>.</p>');
}

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, '<p>Text <code>_</code>.</p>');
}

void test_superParameter_fieldFormal() async {
var library = await bootPackageWithLibrary('''
class C {
int f;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
54 changes: 54 additions & 0 deletions test/type_parameter_test.dart
Original file line number Diff line number Diff line change
@@ -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<T>(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, '<p>Text <code>T</code>.</p>');
}

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, '<p>Text <code>_</code>.</p>');
}

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, '<p>Text <code>_</code>.</p>');
}
}

0 comments on commit 31e110d

Please sign in to comment.