Skip to content

Commit 3b8e8df

Browse files
kallentuCommit Queue
authored andcommitted
[test] Enum shorthand tests for mixins with the existing eq and simple identifier tests.
Follow up to the comments here: https://dart-review.googlesource.com/c/sdk/+/393606/comment/138e0340_c13d55f6/ Add the same tests, but testing mixins and enum shorthands. Bug: #57038 Change-Id: Ia8f1176570253590d5b0757a603ea27f74e5a6fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396302 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent e5b70a7 commit 3b8e8df

File tree

4 files changed

+154
-10
lines changed

4 files changed

+154
-10
lines changed

tests/language/enum_shorthands/enum_shorthand_helper.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ extension type IntegerExt(int integer) {
2323
static const IntegerExt constTwo = const IntegerExt._(2);
2424
const IntegerExt._(this.integer);
2525
}
26+
27+
mixin IntegerMixin on Integer {
28+
static IntegerMixin get mixinOne => IntegerWithMixin(1);
29+
static const IntegerMixin mixinConstOne = const IntegerWithMixin._(1);
30+
static const IntegerMixin mixinConstTwo = const IntegerWithMixin._(2);
31+
}
32+
33+
class IntegerWithMixin extends Integer with IntegerMixin {
34+
const IntegerWithMixin(int integer) : this._(integer);
35+
const IntegerWithMixin._(super.integer) : super._();
36+
}

tests/language/enum_shorthands/equality/equality_error_test.dart

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,22 @@ class ConstConstructorAssert {
4444
// ^
4545
// [analyzer] unspecified
4646
// [cfe] unspecified
47+
48+
const ConstConstructorAssert.oneMixin(IntegerMixin integer)
49+
: assert(.mixinConstOne == integer);
50+
// ^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
54+
const ConstConstructorAssert.notOneMixin(IntegerMixin integer)
55+
: assert(.mixinConstOne != integer);
56+
// ^
57+
// [analyzer] unspecified
58+
// [cfe] unspecified
4759
}
4860

49-
void notSymmetrical(Color color, Integer integer, IntegerExt integerExt) {
61+
void notSymmetrical(Color color, Integer integer, IntegerExt integerExt,
62+
IntegerMixin integerMixin) {
5063
const bool symBlueEq = .blue == color;
5164
// ^
5265
// [analyzer] unspecified
@@ -106,9 +119,20 @@ void notSymmetrical(Color color, Integer integer, IntegerExt integerExt) {
106119
// ^
107120
// [analyzer] unspecified
108121
// [cfe] unspecified
122+
123+
if (.mixinOne == integerMixin) print('not ok');
124+
// ^
125+
// [analyzer] unspecified
126+
// [cfe] unspecified
127+
128+
if (.mixinOne != integerMixin) print('not ok');
129+
// ^
130+
// [analyzer] unspecified
131+
// [cfe] unspecified
109132
}
110133

111-
void rhsNeedsToBeShorthand(Color color, Integer integer, IntegerExt integerExt, bool condition) {
134+
void rhsNeedsToBeShorthand(Color color, Integer integer, IntegerExt integerExt,
135+
IntegerMixin integerMixin, bool condition) {
112136
const Color constColor = Color.red;
113137
const Object obj = true;
114138
const bool constCondition = obj as bool;
@@ -224,9 +248,49 @@ void rhsNeedsToBeShorthand(Color color, Integer integer, IntegerExt integerExt,
224248
// [cfe] unspecified
225249
print('not ok');
226250
}
251+
252+
const IntegerMixin constIntegerMixin = IntegerMixin.mixinConstOne;
253+
const bool rhsIntegerMixinEq = constIntegerMixin == (constCondition ? .mixinConstOne : .mixinConstTwo);
254+
// ^
255+
// [analyzer] unspecified
256+
// [cfe] unspecified
257+
258+
const bool rhsIntegerMixinNeq = constIntegerMixin != (constCondition ? .mixinConstOne : .mixinConstTwo);
259+
// ^
260+
// [analyzer] unspecified
261+
// [cfe] unspecified
262+
263+
if (integerMixin == (condition ? .mixinConstOne : .mixinConstTwo)) {
264+
// ^
265+
// [analyzer] unspecified
266+
// [cfe] unspecified
267+
print('not ok');
268+
}
269+
270+
if (integerMixin != (condition ? .mixinConstOne : .mixinConstTwo)) {
271+
// ^
272+
// [analyzer] unspecified
273+
// [cfe] unspecified
274+
print('not ok');
275+
}
276+
277+
if (integerMixin case == (constCondition ? .mixinConstOne : .mixinConstTwo)) {
278+
// ^
279+
// [analyzer] unspecified
280+
// [cfe] unspecified
281+
print('not ok');
282+
}
283+
284+
if (integerMixin case != (constCondition ? .mixinConstOne : .mixinConstTwo)) {
285+
// ^
286+
// [analyzer] unspecified
287+
// [cfe] unspecified
288+
print('not ok');
289+
}
227290
}
228291

229-
void objectContextType(Color color, Integer integer, IntegerExt integerExt) {
292+
void objectContextType(Color color, Integer integer, IntegerExt integerExt,
293+
IntegerMixin integerMixin) {
230294
const Color constColor = Color.red;
231295
const bool contextTypeColorEq = (constColor as Object) == .blue;
232296
// ^
@@ -319,6 +383,37 @@ void objectContextType(Color color, Integer integer, IntegerExt integerExt) {
319383
// ^
320384
// [analyzer] unspecified
321385
// [cfe] unspecified
386+
387+
const IntegerMixin constIntegerMixin = IntegerMixin.mixinConstOne;
388+
const bool contextTypeIntegerMixinEq = (constIntegerMixin as Object) == .mixinConstTwo;
389+
// ^
390+
// [analyzer] unspecified
391+
// [cfe] unspecified
392+
393+
const bool contextTypeIntegerMixinNeq = (constIntegerMixin as Object) != .mixinConstTwo;
394+
// ^
395+
// [analyzer] unspecified
396+
// [cfe] unspecified
397+
398+
if ((integerMixin as Object) == .mixinOne) print('not ok');
399+
// ^
400+
// [analyzer] unspecified
401+
// [cfe] unspecified
402+
403+
if ((integerMixin as Object) case == .mixinConstOne) print('not ok');
404+
// ^
405+
// [analyzer] unspecified
406+
// [cfe] unspecified
407+
408+
if ((integerMixin as Object) != .mixinOne) print('not ok');
409+
// ^
410+
// [analyzer] unspecified
411+
// [cfe] unspecified
412+
413+
if ((integerMixin as Object) case != .mixinConstOne) print('not ok');
414+
// ^
415+
// [analyzer] unspecified
416+
// [cfe] unspecified
322417
}
323418

324419
void typeParameterContext<C extends Color, T extends Object>(C color, T value) {
@@ -338,11 +433,12 @@ void main() {
338433
Color color = .blue;
339434
Integer integer = .one;
340435
IntegerExt integerExt = .one;
436+
IntegerMixin integerMixin = .mixinOne;
341437

342-
notSymmetrical(color, integer, integerExt);
343-
rhsNeedsToBeShorthand(color, integer, integerExt, true);
344-
rhsNeedsToBeShorthand(color, integer, integerExt, false);
345-
objectContextType(color, integer, integerExt);
438+
notSymmetrical(color, integer, integerExt, integerMixin);
439+
rhsNeedsToBeShorthand(color, integer, integerExt, integerMixin, true);
440+
rhsNeedsToBeShorthand(color, integer, integerExt, integerMixin, false);
441+
objectContextType(color, integer, integerExt, integerMixin);
346442

347443
typeParameterContext(color, integer);
348444
typeParameterContext(color, Color.red);
@@ -355,4 +451,6 @@ void main() {
355451
const ConstConstructorAssert.notOne(Integer.constTwo);
356452
const ConstConstructorAssert.oneExt(IntegerExt.constOne);
357453
const ConstConstructorAssert.notOneExt(IntegerExt.constTwo);
454+
const ConstConstructorAssert.oneMixin(IntegerMixin.mixinConstOne);
455+
const ConstConstructorAssert.notOneMixin(IntegerMixin.mixinConstTwo);
358456
}

tests/language/enum_shorthands/equality/equality_test.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,25 @@ class ConstConstructorAssert {
1313
: assert(color == .blue);
1414

1515
const ConstConstructorAssert.notBlue(Color color)
16-
: assert(color == .blue);
16+
: assert(color != .blue);
1717

1818
const ConstConstructorAssert.one(Integer integer)
1919
: assert(integer == .constOne);
2020

2121
const ConstConstructorAssert.notOne(Integer integer)
22-
: assert(integer == .constOne);
22+
: assert(integer != .constOne);
2323

2424
const ConstConstructorAssert.oneExt(IntegerExt integer)
2525
: assert(integer == .constOne);
2626

2727
const ConstConstructorAssert.notOneExt(IntegerExt integer)
28-
: assert(integer == .constOne);
28+
: assert(integer != .constOne);
29+
30+
const ConstConstructorAssert.oneMixin(IntegerMixin integer)
31+
: assert(integer == .mixinConstOne);
32+
33+
const ConstConstructorAssert.notOneMixin(IntegerExt integer)
34+
: assert(integer != .mixinConstOne);
2935
}
3036

3137
void main() {
@@ -68,6 +74,19 @@ void main() {
6874
if (integerExt != .one) print('ok');
6975
if (integerExt case != .constOne) print('ok');
7076

77+
// Mixin
78+
IntegerMixin integerMixin = .mixinOne;
79+
const IntegerMixin constIntegerMixin = .mixinConstOne;
80+
81+
const bool constIntegerMixinEq = constIntegerMixin == .mixinConstOne;
82+
const bool constIntegerMixinNeq = constIntegerMixin != .mixinConstOne;
83+
84+
if (integerMixin == .mixinOne) print('ok');
85+
if (integerMixin case == .mixinConstOne) print('ok');
86+
87+
if (integerMixin != .mixinOne) print('ok');
88+
if (integerMixin case != .mixinConstOne) print('ok');
89+
7190
// Test the constant evaluation for enum shorthands in const constructor
7291
// asserts.
7392
const ConstConstructorAssert.blue(Color.blue);
@@ -76,4 +95,6 @@ void main() {
7695
const ConstConstructorAssert.notOne(Integer.constTwo);
7796
const ConstConstructorAssert.oneExt(IntegerExt.constOne);
7897
const ConstConstructorAssert.notOneExt(IntegerExt.constTwo);
98+
const ConstConstructorAssert.oneMixin(IntegerMixin.constOne);
99+
const ConstConstructorAssert.notOneMixin(IntegerMixin.constTwo);
79100
}

tests/language/enum_shorthands/simple/simple_identifier_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class IntegerExtContext {
2929
IntegerExtContext.optional([this.integer]);
3030
}
3131

32+
class IntegerMixinContext {
33+
final IntegerMixin? integer;
34+
IntegerMixinContext(this.integer);
35+
IntegerMixinContext.named({this.integer});
36+
IntegerMixinContext.optional([this.integer]);
37+
}
38+
3239
void main() {
3340
// Enum
3441
Color color = .blue;
@@ -58,4 +65,11 @@ void main() {
5865
var integerExtContextPositional = IntegerExtContext(.one);
5966
var integerExtContextNamed = IntegerExtContext.named(integer: .one);
6067
var integerExtContextOptional = IntegerExtContext.optional(.one);
68+
69+
// Mixin
70+
IntegerMixin integerMixin = .mixinOne;
71+
const IntegerMixin constIntegerMixin = .mixinConstOne;
72+
var integerMixinContextPositional = IntegerMixinContext(.mixinOne);
73+
var integerMixinContextNamed = IntegerMixinContext.named(integer: .mixinOne);
74+
var integerMixinContextOptional = IntegerMixinContext.optional(.mixinOne);
6175
}

0 commit comments

Comments
 (0)