From 575cf4fc4ae53584868efff408b8aa47f5e8c8af Mon Sep 17 00:00:00 2001 From: "Sergey G. Grekhov" Date: Thu, 4 Jan 2024 17:21:37 +0200 Subject: [PATCH] #2420. Add relational pattern exhaustiveness tests (#2463) --- .../exhaustiveness_relational_A01_t01.dart | 70 +++++++++++++++++++ .../exhaustiveness_relational_A01_t02.dart | 64 +++++++++++++++++ .../exhaustiveness_relational_A01_t03.dart | 70 +++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t01.dart create mode 100644 LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t02.dart create mode 100644 LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t03.dart diff --git a/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t01.dart b/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t01.dart new file mode 100644 index 0000000000..f64ed8c025 --- /dev/null +++ b/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t01.dart @@ -0,0 +1,70 @@ +// 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 Relational pattern doesn't take part in the calculating of the +/// exhaustiveness +/// +/// @description Check that relational pattern doesn't take part in the +/// calculating of the exhaustiveness. Test the case when constants in +/// relational patterns are extension types +/// @author sgrekhov22@gmail.com +/// @issue 54506 + +// SharedOptions=--enable-experiment=inline-class + +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 b) { + switch (b) { +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + case == True1: + return "true"; + case == False1: + return "false"; + } + +} + +String testStatement2(bool b) { + switch (b) { +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + case == True2: + return "true"; + case == False2: + return "false"; + } +} + +String testExpression1(bool b) => switch (b) { +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + == True1 => "true", + == False1 => "false" + }; + +String testExpression2(bool b) => switch (b) { +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + == True2 => "true", + == False2 => "false" + }; + +main() { + testStatement1(true); + testStatement2(false); + testExpression1(true); + testExpression2(false); +} diff --git a/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t02.dart b/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t02.dart new file mode 100644 index 0000000000..62d8f5d725 --- /dev/null +++ b/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t02.dart @@ -0,0 +1,64 @@ +// 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 Relational pattern doesn't take part in the calculating of the +/// exhaustiveness +/// +/// @description Check that relational pattern doesn't take part in the +/// calculating of the exhaustiveness. Test the case when expression in +/// a `switch` are extension types +/// @author sgrekhov22@gmail.com + +// SharedOptions=--enable-experiment=inline-class + +extension type const BoolET1(bool _) {} +extension type const BoolET2(bool _) implements bool {} + +String testStatement1(BoolET1 b) { + switch (b) { +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + case == true: + return "true"; + case == false: + return "false"; + } + +} + +String testStatement2(BoolET2 b) { + switch (b) { +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + case == true: + return "true"; + case == false: + return "false"; + } +} + +String testExpression1(BoolET1 b) => switch (b) { +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + == true => "true", + == false => "false" + }; + +String testExpression2(BoolET2 b) => switch (b) { +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + == true => "true", + == false => "false" + }; + +main() { + testStatement1(BoolET1(true)); + testStatement2(BoolET2(false)); + testExpression1(BoolET1(false)); + testExpression2(BoolET2(true)); +} diff --git a/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t03.dart b/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t03.dart new file mode 100644 index 0000000000..0f21234a34 --- /dev/null +++ b/LanguageFeatures/Extension-types/exhaustiveness_relational_A01_t03.dart @@ -0,0 +1,70 @@ +// 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 Relational pattern doesn't take part in the calculating of the +/// exhaustiveness +/// +/// @description Check that relational pattern doesn't take part in the +/// calculating of the exhaustiveness. Test the case when both expression in +/// a `switch` and constants in relational patterns are extension types +/// @author sgrekhov22@gmail.com +/// @issue 54506 + +// SharedOptions=--enable-experiment=inline-class + +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 b) { + switch (b) { +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + case == True1: + return "true"; + case == False1: + return "false"; + } + +} + +String testStatement2(BoolET2 b) { + switch (b) { +//^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + case == True2: + return "true"; + case == False2: + return "false"; + } +} + +String testExpression1(BoolET1 b) => switch (b) { +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + == True1 => "true", + == False1 => "false" + }; + +String testExpression2(BoolET2 b) => switch (b) { +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified + == True2 => "true", + == False2 => "false" + }; + +main() { + testStatement1(True1); + testStatement2(False2); + testExpression1(False1); + testExpression2(True2); +}