|
| 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(ClassesTest); |
| 14 | + }); |
| 15 | +} |
| 16 | + |
| 17 | +@reflectiveTest |
| 18 | +class ClassesTest extends DartdocTestBase { |
| 19 | + @override |
| 20 | + String get libraryName => 'classes'; |
| 21 | + |
| 22 | + void test_publicInterfaces_direct() async { |
| 23 | + var library = await bootPackageWithLibrary(''' |
| 24 | +class A {} |
| 25 | +class B implements A {} |
| 26 | +'''); |
| 27 | + |
| 28 | + var b = library.classes.named('B'); |
| 29 | + expect(b.publicInterfaces, hasLength(1)); |
| 30 | + expect(b.publicInterfaces.first.modelElement, library.classes.named('A')); |
| 31 | + } |
| 32 | + |
| 33 | + void test_publicInterfaces_indirect() async { |
| 34 | + var library = await bootPackageWithLibrary(''' |
| 35 | +class A {} |
| 36 | +class B implements A {} |
| 37 | +class C implements B {} |
| 38 | +'''); |
| 39 | + |
| 40 | + var c = library.classes.named('C'); |
| 41 | + // Only `B` is shown, not indirect-through-public like `A`. |
| 42 | + expect(c.publicInterfaces, hasLength(1)); |
| 43 | + expect(c.publicInterfaces.first.modelElement, library.classes.named('B')); |
| 44 | + } |
| 45 | + |
| 46 | + void test_publicInterfaces_indirectViaPrivate() async { |
| 47 | + var library = await bootPackageWithLibrary(''' |
| 48 | +class A {} |
| 49 | +class _B implements A {} |
| 50 | +class C implements _B {} |
| 51 | +'''); |
| 52 | + |
| 53 | + var c = library.classes.named('C'); |
| 54 | + expect(c.publicInterfaces, hasLength(1)); |
| 55 | + expect(c.publicInterfaces.first.modelElement, library.classes.named('A')); |
| 56 | + } |
| 57 | + |
| 58 | + void test_publicInterfaces_indirectViaPrivate_multiply() async { |
| 59 | + var library = await bootPackageWithLibrary(''' |
| 60 | +class A<T> {} |
| 61 | +class _B<U> implements A<U> {} |
| 62 | +class C<T> implements A<T>, _B<T> {} |
| 63 | +'''); |
| 64 | + |
| 65 | + var c = library.classes.named('C'); |
| 66 | + expect(c.publicInterfaces, hasLength(1)); |
| 67 | + expect(c.publicInterfaces.first.modelElement, library.classes.named('A')); |
| 68 | + } |
| 69 | + |
| 70 | + // TODO(srawlins): Test everything else about classes. |
| 71 | +} |
0 commit comments