forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dart-lang#2420. Add parenthesized pattern exhaustiveness tests
- Loading branch information
Showing
4 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
LanguageFeatures/Extension-types/exhaustiveness_parenthesized_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
58 changes: 58 additions & 0 deletions
58
LanguageFeatures/Extension-types/exhaustiveness_parenthesized_A01_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} |
63 changes: 63 additions & 0 deletions
63
LanguageFeatures/Extension-types/exhaustiveness_parenthesized_A01_t03.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ String testStatement1(bool b) { | |
case == False1: | ||
return "false"; | ||
} | ||
|
||
} | ||
|
||
String testStatement2(bool b) { | ||
|