-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide constructors that cannot be called or referenced by user code (#…
- Loading branch information
Showing
4 changed files
with
174 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// 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(ConstructorsTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class ConstructorsTest extends DartdocTestBase { | ||
@override | ||
final libraryName = 'constructors'; | ||
|
||
void test_classIsAbstractFinal_factory() async { | ||
var library = await bootPackageWithLibrary(''' | ||
abstract final class C { | ||
/// Constructor. | ||
factory C() => throw 'Nope'; | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C')); | ||
expect(c.isPublic, isTrue); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsAbstractFinal_unnamed() async { | ||
var library = await bootPackageWithLibrary(''' | ||
abstract final class C { | ||
/// Constructor. | ||
C(); | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C')); | ||
expect(c.isPublic, isFalse); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsAbstractInterface_unnamed() async { | ||
var library = await bootPackageWithLibrary(''' | ||
abstract interface class C { | ||
/// Constructor. | ||
C(); | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C')); | ||
expect(c.isPublic, isFalse); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsPrivate_named() async { | ||
var library = await bootPackageWithLibrary(''' | ||
class C { | ||
/// Constructor. | ||
C._(); | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C._')); | ||
expect(c.isPublic, isFalse); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsPrivate_unnamed() async { | ||
var library = await bootPackageWithLibrary(''' | ||
class _C { | ||
/// Constructor. | ||
_C(); | ||
} | ||
'''); | ||
var c = library.classes.named('_C').constructors.first; | ||
expect(c.name, equals('_C')); | ||
expect(c.isPublic, isFalse); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsPublic_default() async { | ||
var library = await bootPackageWithLibrary(''' | ||
class C {} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C')); | ||
expect(c.isPublic, isTrue); | ||
expect(c.documentationAsHtml, ''); | ||
} | ||
|
||
void test_classIsPublic_named() async { | ||
var library = await bootPackageWithLibrary(''' | ||
class C { | ||
/// Constructor. | ||
C.named(); | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C.named')); | ||
expect(c.isPublic, isTrue); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsPublic_unnamed() async { | ||
var library = await bootPackageWithLibrary(''' | ||
class C { | ||
/// Constructor. | ||
C(); | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C')); | ||
expect(c.isPublic, isTrue); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsPublic_unnamed_explicitNew() async { | ||
var library = await bootPackageWithLibrary(''' | ||
class C { | ||
/// Constructor. | ||
C.new(); | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C')); | ||
expect(c.isPublic, isTrue); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
|
||
void test_classIsSealed_unnamed() async { | ||
var library = await bootPackageWithLibrary(''' | ||
sealed class C { | ||
/// Constructor. | ||
C(); | ||
} | ||
'''); | ||
var c = library.classes.named('C').constructors.first; | ||
expect(c.name, equals('C')); | ||
expect(c.isPublic, isFalse); | ||
expect(c.documentationAsHtml, '<p>Constructor.</p>'); | ||
} | ||
} |