Skip to content

Commit 601e854

Browse files
kallentuCommit Queue
authored andcommitted
[tests] Cascade tests for static member and constructor enum shorthands.
Similar cascade-related tests for testing static member and constructor shorthands. Bug: #57038 Change-Id: I0c0f5121bbfc60473a1c757ee07462a2047e1fa0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401240 Reviewed-by: Erik Ernst <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent 4093bda commit 601e854

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
// Context type is propagated down in cascades for constructor enum shorthands.
6+
7+
// SharedOptions=--enable-experiment=enum-shorthands
8+
9+
import '../enum_shorthand_helper.dart';
10+
11+
class Cascade {
12+
late ConstructorClass ctor;
13+
late ConstructorExt ctorExt;
14+
}
15+
16+
class CascadeCollection {
17+
late List<ConstructorClass> ctorList;
18+
late Set<ConstructorClass> ctorSet;
19+
late Map<ConstructorClass, ConstructorClass> ctorMap;
20+
late Map<ConstructorClass, (ConstructorClass, ConstructorClass)> ctorMap2;
21+
22+
late List<ConstructorExt> ctorExtList;
23+
late Set<ConstructorExt> ctorExtSet;
24+
late Map<ConstructorExt, ConstructorExt> ctorExtMap;
25+
late Map<ConstructorExt, (ConstructorExt, ConstructorExt)> ctorExtMap2;
26+
}
27+
28+
class CascadeMethod {
29+
void ctor(ConstructorClass ctor) => print(ctor);
30+
void ctorExt(ConstructorExt ctor) => print(ctor);
31+
}
32+
33+
void main() {
34+
Cascade()
35+
..ctor = .new(1)
36+
..ctor = .regular(1)
37+
..ctor = .named(x: 1)
38+
..ctor = .optional(1)
39+
..ctorExt = .new(1)
40+
..ctorExt = .regular(1)
41+
..ctorExt = .named(x: 1)
42+
..ctorExt = .optional(1);
43+
44+
dynamic mayBeNull = null;
45+
Cascade()
46+
..ctor = mayBeNull ?? .new(1)
47+
..ctor = mayBeNull ?? .regular(1)
48+
..ctor = mayBeNull ?? .named(x: 1)
49+
..ctor = mayBeNull ?? .optional(1)
50+
..ctorExt = mayBeNull ?? .new(1)
51+
..ctorExt = mayBeNull ?? .regular(1)
52+
..ctorExt = mayBeNull ?? .named(x: 1)
53+
..ctorExt = mayBeNull ?? .optional(1);
54+
55+
CascadeCollection()
56+
..ctorList = [.new(1), .regular(1), .named(x: 1), .optional(1)]
57+
..ctorSet = {.new(1), .regular(1), .named(x: 1), .optional(1)}
58+
..ctorMap = {
59+
.new(1): .new(1),
60+
.regular(1): .regular(1),
61+
.named(x: 1): .named(x: 1),
62+
.optional(1): .optional(1),
63+
}
64+
..ctorMap2 = {
65+
.new(1): (.new(1), .new(1)),
66+
.regular(1): (.regular(1), .regular(1)),
67+
.named(x: 1): (.named(x: 1), .named(x: 1)),
68+
.optional(1): (.optional(1), .optional(1)),
69+
}
70+
..ctorExtList = [.new(1), .regular(1), .named(x: 1), .optional(1)]
71+
..ctorExtSet = {.new(1), .regular(1), .named(x: 1), .optional(1)}
72+
..ctorExtMap = {
73+
.new(1): .new(1),
74+
.regular(1): .regular(1),
75+
.named(x: 1): .named(x: 1),
76+
.optional(1): .optional(1),
77+
}
78+
..ctorExtMap2 = {
79+
.new(1): (.new(1), .new(1)),
80+
.regular(1): (.regular(1), .regular(1)),
81+
.named(x: 1): (.named(x: 1), .named(x: 1)),
82+
.optional(1): (.optional(1), .optional(1)),
83+
};
84+
85+
CascadeMethod()
86+
..ctor(.new(1))
87+
..ctor(.regular(1))
88+
..ctor(.named(x: 1))
89+
..ctor(.optional(1))
90+
..ctorExt(.new(1))
91+
..ctorExt(.regular(1))
92+
..ctorExt(.named(x: 1))
93+
..ctorExt(.optional(1));
94+
95+
ConstructorClass ctor = .new(1)..toString();
96+
ConstructorClass ctorRegular = .regular(1)..toString();
97+
ConstructorClass ctorNamed = .named(x: 1)..toString();
98+
ConstructorClass ctorOptional = .optional(1)..toString();
99+
ConstructorExt ctorExt = .new(1)..toString();
100+
ConstructorExt ctorExtRegular = .regular(1)..toString();
101+
ConstructorExt ctorExtNamed = .named(x: 1)..toString();
102+
ConstructorExt ctorExtOptional = .optional(1)..toString();
103+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
// Context type is propagated down in cascades for static member enum
6+
// shorthands.
7+
8+
// SharedOptions=--enable-experiment=enum-shorthands
9+
10+
import '../enum_shorthand_helper.dart';
11+
12+
class Cascade {
13+
late StaticMember member;
14+
late StaticMemberExt memberExt;
15+
}
16+
17+
class CascadeCollection {
18+
late List<StaticMember> memberList;
19+
late Set<StaticMember> memberSet;
20+
late Map<StaticMember, StaticMember> memberMap;
21+
late Map<StaticMember, (StaticMember, StaticMember)> memberMap2;
22+
23+
late List<StaticMemberExt> memberExtList;
24+
late Set<StaticMemberExt> memberExtSet;
25+
late Map<StaticMemberExt, StaticMemberExt> memberExtMap;
26+
late Map<StaticMemberExt, (StaticMemberExt, StaticMemberExt)> memberExtMap2;
27+
}
28+
29+
class CascadeMethod {
30+
void member(StaticMember member) => print(member);
31+
void memberExt(StaticMemberExt member) => print(member);
32+
}
33+
34+
void main() {
35+
Cascade()
36+
..member = .member()
37+
..member = .memberType<String, int>('s')
38+
..memberExt = .member()
39+
..memberExt = .memberType<String, int>('s');
40+
41+
dynamic mayBeNull = null;
42+
Cascade()
43+
..member = mayBeNull ?? .member()
44+
..member = mayBeNull ?? .memberType<String, int>('s')
45+
..memberExt = mayBeNull ?? .member()
46+
..memberExt = mayBeNull ?? .memberType<String, int>('s');
47+
48+
CascadeCollection()
49+
..memberList = [.member(), .memberType<String, int>('s')]
50+
..memberSet = {.member(), .memberType<String, int>('s')}
51+
..memberMap = {
52+
.member(): .member(),
53+
.memberType<String, int>(
54+
's',
55+
): .memberType<String, int>('s'),
56+
}
57+
..memberMap2 = {
58+
.member(): (.member(), .member()),
59+
.memberType<String, int>('s'): (
60+
.memberType<String, int>('s'),
61+
.memberType<String, int>('s'),
62+
),
63+
}
64+
..memberExtList = [.member(), .memberType<String, int>('s')]
65+
..memberExtSet = {.member(), .memberType<String, int>('s')}
66+
..memberExtMap = {
67+
.member(): .member(),
68+
.memberType<String, int>(
69+
's',
70+
): .memberType<String, int>('s'),
71+
}
72+
..memberExtMap2 = {
73+
.member(): (.member(), .member()),
74+
.memberType<String, int>('s'): (
75+
.memberType<String, int>('s'),
76+
.memberType<String, int>('s'),
77+
),
78+
};
79+
80+
CascadeMethod()
81+
..member(.member())
82+
..member(.memberType<String, int>('s'))
83+
..memberExt(.member())
84+
..memberExt(.memberType<String, int>('s'));
85+
86+
StaticMember member = .member()..toString();
87+
StaticMember memberType = .memberType<String, int>('s')
88+
..toString();
89+
StaticMemberExt memberExt = .member()..toString();
90+
StaticMemberExt memberTypeExt = .memberType<String, int>('s')
91+
..toString();
92+
}

0 commit comments

Comments
 (0)