| // Copyright (c) 2022, 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. |
| |
| /// @assertion |
| /// logicalAndPattern ::= ( logicalAndPattern '&&' )? relationalPattern |
| /// |
| /// A pair of patterns separated by & matches only if both subpatterns match. |
| /// Unlike logical-or patterns, the variables defined in each branch must not |
| /// overlap, since the logical-and pattern only matches if both branches do and |
| /// the variables in both branches will be bound. |
| /// |
| /// If the left branch does not match, the right branch is not evaluated. This |
| /// only matters because patterns may invoke user-defined methods with visible |
| /// side effects. |
| /// |
| /// @description Checks a logical-and pattern in an if-case statement |
| /// @author sgrekhov22@gmail.com |
| |
| import "../../Utils/expect.dart"; |
| |
| bool test(int value) { |
| if (value case > -1 && <= 3) { |
| return true; |
| } |
| return false; |
| } |
| |
| main() { |
| Expect.isTrue(test(0)); |
| Expect.isTrue(test(1)); |
| Expect.isTrue(test(2)); |
| Expect.isTrue(test(3)); |
| Expect.isFalse(test(-1)); |
| Expect.isFalse(test(4)); |
| } |