Skip to content

Commit 9680d36

Browse files
authored
Move a test case from e2e tests to unit tests. (#3998)
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 9680d36

File tree

3 files changed

+35
-44
lines changed

3 files changed

+35
-44
lines changed

test/classes_test.dart

+32
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

+3-16
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: non_constant_identifier_names
6-
75
// ignore_for_file: analyzer_use_new_elements
86

7+
// ignore_for_file: non_constant_identifier_names
8+
99
import 'package:analyzer/dart/element/element2.dart';
1010
import 'package:analyzer/dart/element/type.dart';
1111
import 'package:analyzer/source/line_info.dart';
@@ -909,7 +909,7 @@ void main() async {
909909
});
910910

911911
test('can import other libraries with unusual URIs', () {
912-
final importLists = fakeLibrary.element2.fragments
912+
final importLists = fakeLibrary.element2.fragments
913913
.map((fragment) => fragment.libraryImports2);
914914
final exportLists = fakeLibrary.element2.fragments
915915
.map((fragment) => fragment.libraryExports2);
@@ -1680,19 +1680,6 @@ void main() async {
16801680
var gadgetGetter = GadgetExtender.instanceFields.named('gadgetGetter');
16811681
expect(gadgetGetter.isCanonical, isTrue);
16821682
});
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-
});
16961683
});
16971684

16981685
group('Mixin', () {

testing/test_package/lib/fake.dart

-28
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)