mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:16:51 +00:00
3b74c305fd
New language features made `futureOr(null) = 1` a syntactically correct pattern assignment, so it should not be expected to cause a syntax error. This CL changes that test case such that it is still an assignment to a syntactically correct function invocation, but not a correct pattern assignment (so it's again a syntax error). Added more tests with similar properties: The 3.0 grammar causes some test cases to be wrong, and this CL makes changes such that they will continue to test "the same thing" as far as possible in the new language. Change-Id: Ie0166f1a599ffeebfd352f4fadc01abc0950bd0b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279169 Reviewed-by: Lasse Nielsen <lrn@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
44 lines
1 KiB
Dart
44 lines
1 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// @dart = 2.19
|
|
|
|
// Test legacy forms of switch statement.
|
|
|
|
// VMOptions=
|
|
// VMOptions=--force-switch-dispatch-type=0
|
|
// VMOptions=--force-switch-dispatch-type=1
|
|
// VMOptions=--force-switch-dispatch-type=2
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
const int ic1 = 1;
|
|
const int ic2 = 2;
|
|
void testSwitchIntExpression(int input, int? expect) {
|
|
int? result = null;
|
|
switch (input) {
|
|
case 1 + 1: // 2
|
|
case ic1 + 2: // 3
|
|
result = 11;
|
|
break;
|
|
case ic2 * 2: // 4
|
|
case 1 * 5: // 5
|
|
result = 21;
|
|
break;
|
|
case ic1 % ic2 + 5: // 6
|
|
result = 31;
|
|
break;
|
|
}
|
|
Expect.equals(expect, result);
|
|
}
|
|
|
|
main() {
|
|
testSwitchIntExpression(2, 11);
|
|
testSwitchIntExpression(3, 11);
|
|
testSwitchIntExpression(4, 21);
|
|
testSwitchIntExpression(5, 21);
|
|
testSwitchIntExpression(6, 31);
|
|
testSwitchIntExpression(7, null);
|
|
}
|