Skip to content

Commit bd691da

Browse files
nshahanCommit Queue
authored andcommitted
[ddc] Add expression eval tests for dot shorthands
Ensures dot shorthands are usable from expression evaluation on the web. Change-Id: Ia5e5c54f0de0c2237d6d01b4658723f5188bd460 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446500 Reviewed-by: Kallen Tu <kallentu@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
1 parent 0af32bf commit bd691da

File tree

1 file changed

+116
-2
lines changed

1 file changed

+116
-2
lines changed

pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_dart_3_10_test.dart

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void runSharedTests(
4141
ExpressionEvaluationTestDriver driver,
4242
) {
4343
group('local consts', () {
44-
const recordsSource = '''
44+
const localConstsSource = '''
4545
void main() {
4646
topLevelMethod();
4747
@@ -66,7 +66,7 @@ void runSharedTests(
6666
''';
6767

6868
setUpAll(() async {
69-
await driver.initSource(setup, recordsSource);
69+
await driver.initSource(setup, localConstsSource);
7070
});
7171

7272
tearDownAll(() async {
@@ -89,4 +89,118 @@ void runSharedTests(
8989
);
9090
});
9191
});
92+
group('dot shorthands', () {
93+
const dotShorthandsSource = '''
94+
enum Color {
95+
red,
96+
green,
97+
blue;
98+
99+
int get lengthOfName => name.length;
100+
}
101+
102+
class C {
103+
final int i;
104+
C(this.i);
105+
C.namedConstructor() : i = 2;
106+
const C.constConstructor() : i = 1;
107+
factory C.factoryConstructor() => C(42);
108+
static C staticMethod() => C(99);
109+
}
110+
111+
String enumContext(Color c) => c.name;
112+
113+
int classContext(C c) => c.i;
114+
115+
T genericContext<T>(T val) => val;
116+
117+
void main() {
118+
// Breakpoint: bp
119+
print('hello world');
120+
}
121+
''';
122+
123+
setUpAll(() async {
124+
await driver.initSource(setup, dotShorthandsSource);
125+
});
126+
127+
tearDownAll(() async {
128+
await driver.cleanupTest();
129+
});
130+
group('enum context', () {
131+
test('name', () async {
132+
await driver.checkInFrame(
133+
breakpointId: 'bp',
134+
expression: 'enumContext(.red)',
135+
expectedResult: 'red',
136+
);
137+
});
138+
test('equals method', () async {
139+
await driver.checkInFrame(
140+
breakpointId: 'bp',
141+
expression: 'genericContext<bool>(Color.green == .green)',
142+
expectedResult: 'true',
143+
);
144+
});
145+
test('generic context', () async {
146+
await driver.checkInFrame(
147+
breakpointId: 'bp',
148+
expression: 'genericContext<Color>(.blue)',
149+
expectedResult: 'blue',
150+
);
151+
});
152+
});
153+
154+
group('class context', () {
155+
test('new', () async {
156+
await driver.checkInFrame(
157+
breakpointId: 'bp',
158+
expression: 'classContext(.new(123))',
159+
expectedResult: '123',
160+
);
161+
});
162+
test('named constructor', () async {
163+
await driver.checkInFrame(
164+
breakpointId: 'bp',
165+
expression: 'classContext(.namedConstructor())',
166+
expectedResult: '2',
167+
);
168+
});
169+
test('const constructor', () async {
170+
await driver.checkInFrame(
171+
breakpointId: 'bp',
172+
expression: 'const <C>[.constConstructor()].single.i',
173+
expectedResult: '1',
174+
);
175+
});
176+
test('factory constructor', () async {
177+
await driver.checkInFrame(
178+
breakpointId: 'bp',
179+
expression: 'classContext(.factoryConstructor())',
180+
expectedResult: '42',
181+
);
182+
});
183+
test('static method', () async {
184+
await driver.checkInFrame(
185+
breakpointId: 'bp',
186+
expression: 'classContext(.staticMethod())',
187+
expectedResult: '99',
188+
);
189+
});
190+
});
191+
test('equals method', () async {
192+
await driver.checkInFrame(
193+
breakpointId: 'bp',
194+
expression: 'genericContext<bool>(C(99) == .namedConstructor())',
195+
expectedResult: 'false',
196+
);
197+
});
198+
test('generic context', () async {
199+
await driver.checkInFrame(
200+
breakpointId: 'bp',
201+
expression: 'genericContext<C>(.namedConstructor()).i',
202+
expectedResult: '2',
203+
);
204+
});
205+
});
92206
}

0 commit comments

Comments
 (0)