Skip to content

Commit 2d39914

Browse files
committed
Move a test case from e2e tests to unit tests.
This test case is tickled in a refactoring I am attempting. I'm moving it to be a unit test here, for better debuggability, and understandability, before I make the refactoring.
1 parent 96f18b4 commit 2d39914

File tree

3 files changed

+33
-44
lines changed

3 files changed

+33
-44
lines changed

test/classes_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,37 @@ class D implements Object {}
197197
expect(toString.canonicalEnclosingContainer!.isDartCoreObject, isTrue);
198198
}
199199

200+
void test_multiplyInheritedOperator_oneIsPrivate() async {
201+
// Test an edge case where inherited ExecutableElements can come both from
202+
// private classes and public interfaces. The test makes sure the class
203+
// still takes precedence.
204+
// See https://github.com/dart-lang/dartdoc/issues/1561.
205+
var library = await bootPackageWithLibrary('''
206+
abstract class A<K, V> {
207+
void operator []=(K key, V value);
208+
}
209+
210+
abstract class B<K, V> implements A<K, V> {
211+
@override
212+
operator []=(K key, V value);
213+
}
214+
215+
abstract class C<K, V> extends B<K, V> {}
216+
217+
abstract class _D<K, V> implements A<K, V> {
218+
@override
219+
void operator []=(K key, V value);
220+
}
221+
222+
abstract class E<K, V> = C<K, V> with _D<K, V>;
223+
''');
224+
225+
var indexAssign =
226+
library.classes.named('E').inheritedOperators.named('operator []=');
227+
expect(indexAssign.element2.enclosingElement2!.name3, '_D');
228+
expect(indexAssign.canonicalEnclosingContainer!.name, 'E');
229+
expect(indexAssign.canonicalModelElement!.enclosingElement!.name, 'E');
230+
}
231+
200232
// TODO(srawlins): Test everything else about classes.
201233
}

test/end2end/model_test.dart

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
// ignore_for_file: non_constant_identifier_names
66

7-
// ignore_for_file: analyzer_use_new_elements
8-
97
import 'package:analyzer/dart/element/element2.dart';
108
import 'package:analyzer/dart/element/type.dart';
119
import 'package:analyzer/source/line_info.dart';
@@ -909,7 +907,7 @@ void main() async {
909907
});
910908

911909
test('can import other libraries with unusual URIs', () {
912-
final importLists = fakeLibrary.element2.fragments
910+
final importLists = fakeLibrary.element2.fragments
913911
.map((fragment) => fragment.libraryImports2);
914912
final exportLists = fakeLibrary.element2.fragments
915913
.map((fragment) => fragment.libraryExports2);
@@ -1680,19 +1678,6 @@ void main() async {
16801678
var gadgetGetter = GadgetExtender.instanceFields.named('gadgetGetter');
16811679
expect(gadgetGetter.isCanonical, isTrue);
16821680
});
1683-
1684-
test(
1685-
'ExecutableElements from private classes and from public interfaces (#1561)',
1686-
() {
1687-
var MIEEMixinWithOverride =
1688-
fakeLibrary.classes.wherePublic.named('MIEEMixinWithOverride');
1689-
var problematicOperator =
1690-
MIEEMixinWithOverride.inheritedOperators.named('operator []=');
1691-
expect(problematicOperator.element2.enclosingElement2?.name3,
1692-
equals('_MIEEPrivateOverride'));
1693-
expect(problematicOperator.canonicalModelElement!.enclosingElement!.name,
1694-
equals('MIEEMixinWithOverride'));
1695-
});
16961681
});
16971682

16981683
group('Mixin', () {

testing/test_package/lib/fake.dart

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,34 +1117,6 @@ extension OnOldSchool on OldSchoolMixin {
11171117

11181118
class School with OldSchoolMixin, NewSchoolMixin {}
11191119

1120-
//
1121-
//
1122-
//
1123-
1124-
/// Test an edge case for cases where inherited ExecutableElements can come
1125-
/// both from private classes and public interfaces. The test makes sure the
1126-
/// class still takes precedence (#1561).
1127-
abstract class MIEEMixinWithOverride<K, V> = MIEEBase<K, V>
1128-
with _MIEEPrivateOverride<K, V>;
1129-
1130-
abstract class _MIEEPrivateOverride<K, V> implements MIEEThing<K, V> {
1131-
// ignore: annotate_overrides
1132-
void operator []=(K key, V value) {
1133-
throw UnsupportedError("Never use this");
1134-
}
1135-
}
1136-
1137-
abstract class MIEEBase<K, V> extends MIEEMixin<K, V> {}
1138-
1139-
abstract class MIEEMixin<K, V> implements MIEEThing<K, V> {
1140-
// ignore: annotate_overrides
1141-
operator []=(K key, V value);
1142-
}
1143-
1144-
abstract class MIEEThing<K, V> {
1145-
void operator []=(K key, V value);
1146-
}
1147-
11481120
abstract class ImplementingClassForTool {
11491121
/// Invokes a tool from inherited documentation via `implemented`
11501122
///

0 commit comments

Comments
 (0)