Skip to content

Commit

Permalink
dart-lang#2420. Add parenthesized pattern exhaustiveness tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Jan 5, 2024
1 parent 86b168a commit feda56b
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2024, 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 Exhaustiveness of a parenthesized pattern is defined by the
/// exhaustiveness of the appropriate subpattern
///
/// @description Check that an exhaustiveness of a parenthesized pattern is
/// defined by the exhaustiveness of the appropriate subpattern. Test the case
/// when extension types are used in `case` parts of a `switch`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type const BoolET1(bool _) {}
extension type const BoolET2(bool _) implements bool {}

const True1 = BoolET1(true);
const False1 = BoolET1(false);
const True2 = BoolET2(true);
const False2 = BoolET2(false);

String testStatement1(bool o) {
switch (o) {
case (True1):
return "true";
case (False1):
return "false";
}
}

String testStatement2(bool o) {
switch (o) {
case (True2):
return "true";
case (False2):
return "false";
}
}

String testExpression1(bool o) => switch (o) {
(True1) => "true",
(False1) => "false"
};

String testExpression2(bool o) => switch (o) {
(True2) => "true",
(False2) => "false"
};

main() {
Expect.equals("true", testStatement1(true));
Expect.equals("false", testStatement1(false));
Expect.equals("true", testStatement2(true));
Expect.equals("false", testStatement2(false));

Expect.equals("true", testExpression1(true));
Expect.equals("false", testExpression1(false));
Expect.equals("true", testExpression2(true));
Expect.equals("false", testExpression2(false));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2024, 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 Exhaustiveness of a parenthesized pattern is defined by the
/// exhaustiveness of the appropriate subpattern
///
/// @description Check that an exhaustiveness of a parenthesized pattern is
/// defined by the exhaustiveness of the appropriate subpattern. Test the case
/// when extension types are used in the expression parts of a `switch`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type const BoolET1(bool _) {}
extension type const BoolET2(bool _) implements bool {}

String testStatement1(BoolET1 o) {
switch (o) {
case (true):
return "true";
case (false):
return "false";
}
}

String testStatement2(BoolET2 o) {
switch (o) {
case (true):
return "true";
case (false):
return "false";
}
}

String testExpression1(BoolET1 o) => switch (o) {
(true) => "true",
(false) => "false"
};

String testExpression2(BoolET2 o) => switch (o) {
(true) => "true",
(false) => "false"
};

main() {
Expect.equals("true", testStatement1(BoolET1(true)));
Expect.equals("false", testStatement1(BoolET1(false)));
Expect.equals("true", testStatement2(BoolET2(true)));
Expect.equals("false", testStatement2(BoolET2(false)));

Expect.equals("true", testExpression1(BoolET1(true)));
Expect.equals("false", testExpression1(BoolET1(false)));
Expect.equals("true", testExpression2(BoolET2(true)));
Expect.equals("false", testExpression2(BoolET2(false)));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2024, 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 Exhaustiveness of a parenthesized pattern is defined by the
/// exhaustiveness of the appropriate subpattern
///
/// @description Check that an exhaustiveness of a parenthesized pattern is
/// defined by the exhaustiveness of the appropriate subpattern. Test the case
/// when extension types are used in `case` and expression parts of a `switch`
/// @author sgrekhov22@gmail.com
// SharedOptions=--enable-experiment=inline-class

import "../../Utils/expect.dart";

extension type const BoolET1(bool _) {}
extension type const BoolET2(bool _) implements bool {}

const True1 = BoolET1(true);
const False1 = BoolET1(false);
const True2 = BoolET2(true);
const False2 = BoolET2(false);

String testStatement1(BoolET1 o) {
switch (o) {
case (True1):
return "true";
case (False1):
return "false";
}
}

String testStatement2(BoolET2 o) {
switch (o) {
case (True2):
return "true";
case (False2):
return "false";
}
}

String testExpression1(BoolET1 o) => switch (o) {
(True1) => "true",
(False1) => "false"
};

String testExpression2(BoolET2 o) => switch (o) {
(True2) => "true",
(False2) => "false"
};

main() {
Expect.equals("true", testStatement1(BoolET1(true)));
Expect.equals("false", testStatement1(BoolET1(false)));
Expect.equals("true", testStatement2(BoolET2(true)));
Expect.equals("false", testStatement2(BoolET2(false)));

Expect.equals("true", testExpression1(BoolET1(true)));
Expect.equals("false", testExpression1(BoolET1(false)));
Expect.equals("true", testExpression2(BoolET2(true)));
Expect.equals("false", testExpression2(BoolET2(false)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ String testStatement1(bool b) {
case == False1:
return "false";
}

}

String testStatement2(bool b) {
Expand Down

0 comments on commit feda56b

Please sign in to comment.