Skip to content

Commit db8057b

Browse files
committed
dart-lang#2420. Add relational pattern exhaustiveness tests
1 parent f523471 commit db8057b

3 files changed

+204
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Relational pattern doesn't take part in the calculating of the
6+
/// exhaustiveness
7+
///
8+
/// @description Check that relational pattern doesn't take part in the
9+
/// calculating of the exhaustiveness. Test the case when constants in
10+
/// relational patterns are extension types
11+
/// @author [email protected]
12+
/// @issue 54506
13+
14+
// SharedOptions=--enable-experiment=inline-class
15+
16+
extension type const BoolET1(bool _) {}
17+
extension type const BoolET2(bool _) implements bool {}
18+
19+
const True1 = BoolET1(true);
20+
const False1 = BoolET1(false);
21+
const True2 = BoolET2(true);
22+
const False2 = BoolET2(false);
23+
24+
String testStatement1(bool b) {
25+
switch (b) {
26+
//^^^^^^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
case == True1:
30+
return "true";
31+
case == False1:
32+
return "false";
33+
}
34+
35+
}
36+
37+
String testStatement2(bool b) {
38+
switch (b) {
39+
//^^^^^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
case == True2:
43+
return "true";
44+
case == False2:
45+
return "false";
46+
}
47+
}
48+
49+
String testExpression1(bool b) => switch (b) {
50+
// ^^^^^^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
== True1 => "true",
54+
== False1 => "false"
55+
};
56+
57+
String testExpression2(bool b) => switch (b) {
58+
// ^^^^^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
== True2 => "true",
62+
== False2 => "false"
63+
};
64+
65+
main() {
66+
testStatement1(true);
67+
testStatement2(false);
68+
testExpression1(true);
69+
testExpression2(false);
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Relational pattern doesn't take part in the calculating of the
6+
/// exhaustiveness
7+
///
8+
/// @description Check that relational pattern doesn't take part in the
9+
/// calculating of the exhaustiveness. Test the case when expression in
10+
/// a `switch` are extension types
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=inline-class
14+
15+
extension type const BoolET1(bool _) {}
16+
extension type const BoolET2(bool _) implements bool {}
17+
18+
String testStatement1(BoolET1 b) {
19+
switch (b) {
20+
//^^^^^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
case == true:
24+
return "true";
25+
case == false:
26+
return "false";
27+
}
28+
29+
}
30+
31+
String testStatement2(BoolET2 b) {
32+
switch (b) {
33+
//^^^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
case == true:
37+
return "true";
38+
case == false:
39+
return "false";
40+
}
41+
}
42+
43+
String testExpression1(BoolET1 b) => switch (b) {
44+
// ^^^^^^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
== true => "true",
48+
== false => "false"
49+
};
50+
51+
String testExpression2(BoolET2 b) => switch (b) {
52+
// ^^^^^^
53+
// [analyzer] unspecified
54+
// [cfe] unspecified
55+
== true => "true",
56+
== false => "false"
57+
};
58+
59+
main() {
60+
testStatement1(BoolET1(true));
61+
testStatement2(BoolET2(false));
62+
testExpression1(BoolET1(false));
63+
testExpression2(BoolET2(true));
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Relational pattern doesn't take part in the calculating of the
6+
/// exhaustiveness
7+
///
8+
/// @description Check that relational pattern doesn't take part in the
9+
/// calculating of the exhaustiveness. Test the case when both expression in
10+
/// a `switch` and constants in relational patterns are extension types
11+
/// @author [email protected]
12+
/// @issue 54506
13+
14+
// SharedOptions=--enable-experiment=inline-class
15+
16+
extension type const BoolET1(bool _) {}
17+
extension type const BoolET2(bool _) implements bool {}
18+
19+
const True1 = BoolET1(true);
20+
const False1 = BoolET1(false);
21+
const True2 = BoolET2(true);
22+
const False2 = BoolET2(false);
23+
24+
String testStatement1(BoolET1 b) {
25+
switch (b) {
26+
//^^^^^^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
case == True1:
30+
return "true";
31+
case == False1:
32+
return "false";
33+
}
34+
35+
}
36+
37+
String testStatement2(BoolET2 b) {
38+
switch (b) {
39+
//^^^^^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
case == True2:
43+
return "true";
44+
case == False2:
45+
return "false";
46+
}
47+
}
48+
49+
String testExpression1(BoolET1 b) => switch (b) {
50+
// ^^^^^^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
== True1 => "true",
54+
== False1 => "false"
55+
};
56+
57+
String testExpression2(BoolET2 b) => switch (b) {
58+
// ^^^^^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
== True2 => "true",
62+
== False2 => "false"
63+
};
64+
65+
main() {
66+
testStatement1(True1);
67+
testStatement2(False2);
68+
testExpression1(False1);
69+
testExpression2(True2);
70+
}

0 commit comments

Comments
 (0)