Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Aug 26, 2024
1 parent 569aaa6 commit 8bf7571
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/classes_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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(ClassesTest);
});
}

@reflectiveTest
class ClassesTest extends DartdocTestBase {
@override
String get libraryName => 'classes';

void test_publicInterfaces_direct() async {
var library = await bootPackageWithLibrary('''
class A {}
class B implements A {}
''');

var b = library.classes.named('B');
expect(b.publicInterfaces, hasLength(1));
expect(b.publicInterfaces.first.modelElement, library.classes.named('A'));
}

void test_publicInterfaces_indirect() async {
var library = await bootPackageWithLibrary('''
class A {}
class B implements A {}
class C implements B {}
''');

var c = library.classes.named('C');
// Only `B` is shown, not indirect-through-public like `A`.
expect(c.publicInterfaces, hasLength(1));
expect(c.publicInterfaces.first.modelElement, library.classes.named('B'));
}

void test_publicInterfaces_indirectViaPrivate() async {
var library = await bootPackageWithLibrary('''
class A {}
class _B implements A {}
class C implements _B {}
''');

var c = library.classes.named('C');
expect(c.publicInterfaces, hasLength(1));
expect(c.publicInterfaces.first.modelElement, library.classes.named('A'));
}

void test_publicInterfaces_indirectViaPrivate_multiply() async {
var library = await bootPackageWithLibrary('''
class A<T> {}
class _B<U> implements A<U> {}
class C<T> implements A<T>, _B<T> {}
''');

var c = library.classes.named('C');
expect(c.publicInterfaces, hasLength(1));
expect(c.publicInterfaces.first.modelElement, library.classes.named('A'));
}

// TODO(srawlins): Test everything else about classes.
}

0 comments on commit 8bf7571

Please sign in to comment.