Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests supporting the wildcard feature #3835

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
srawlins marked this conversation as resolved.
Show resolved Hide resolved
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>');
}
}