dart-sdk/tests/language/switch/switch_legacy_test.dart
Erik Ernst 3b74c305fd Update syntax_test to avoid expecting new syntax to be a syntax error
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>
2023-01-19 14:44:36 +00:00

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);
}