From b1f0731cbf9ba9619bd7b04a0a6703a8512f288c Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Fri, 27 Dec 2024 10:53:11 -0800 Subject: [PATCH] [tests] Enum shorthands == tests for constructors and static methods. Add tests similar to what we already have for ==, but with constructors and static methods. Fix some prior == const tests. Bug: https://github.com/dart-lang/sdk/issues/57038 Change-Id: Ia6afde353fd16d7dcd767d0514484cae5ac1730b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401980 Reviewed-by: Erik Ernst Commit-Queue: Kallen Tu --- .../equality/equality_ctor_error_test.dart | 503 ++++++++++++++++++ .../equality/equality_ctor_test.dart | 98 ++++ .../equality/equality_error_test.dart | 16 +- .../equality/equality_member_error_test.dart | 178 +++++++ .../equality/equality_member_test.dart | 28 + 5 files changed, 817 insertions(+), 6 deletions(-) create mode 100644 tests/language/enum_shorthands/equality/equality_ctor_error_test.dart create mode 100644 tests/language/enum_shorthands/equality/equality_ctor_test.dart create mode 100644 tests/language/enum_shorthands/equality/equality_member_error_test.dart create mode 100644 tests/language/enum_shorthands/equality/equality_member_test.dart diff --git a/tests/language/enum_shorthands/equality/equality_ctor_error_test.dart b/tests/language/enum_shorthands/equality/equality_ctor_error_test.dart new file mode 100644 index 000000000000..1f777e502d3c --- /dev/null +++ b/tests/language/enum_shorthands/equality/equality_ctor_error_test.dart @@ -0,0 +1,503 @@ +// 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. + +// Testing erroneous ways of using shorthands with the `==` and `!=` operators. + +// SharedOptions=--enable-experiment=enum-shorthands + +import '../enum_shorthand_helper.dart'; + +class ConstConstructorAssert { + const ConstConstructorAssert.regular(ConstructorClass ctor) + : assert(const .constRegular(1) == ctor); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const ConstConstructorAssert.named(ConstructorClass ctor) + : assert(const .constNamed(x: 1) == ctor); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const ConstConstructorAssert.optional(ConstructorClass ctor) + : assert(const .constOptional(1) == ctor); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const ConstConstructorAssert.regularExt(ConstructorExt ctor) + : assert(const .constRegular(1) == ctor); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const ConstConstructorAssert.namedExt(ConstructorExt ctor) + : assert(const .constNamed(x: 1) == ctor); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const ConstConstructorAssert.optionalExt(ConstructorExt ctor) + : assert(const .constOptional(1) == ctor); + // ^ + // [analyzer] unspecified + // [cfe] unspecified +} + +void notSymmetrical(ConstructorClass ctor, ConstructorExt ctorExt) { + const ConstructorClass constCtor = .constRegular(1); + const bool symEqRegular = .constRegular(1) == constCtor; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symEqNamed = .constNamed(x: 1) == constCtor; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symEqOptional = .constOptional(1) == constCtor; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symNeqRegular = .constRegular(1) != constCtor; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symNeqNamed = .constNamed(x: 1) != constCtor; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symNeqOptional = .constOptional(1) != constCtor; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const ConstructorExt constCtorExt = .constRegular(1); + const bool symExtEqRegular = .constRegular(1) == constCtorExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symExtEqNamed = .constNamed(x: 1) == constCtorExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symExtEqOptional = .constOptional(1) == constCtorExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symExtNeqRegular = .constRegular(1) != constCtorExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symExtNeqNamed = .constNamed(x: 1) != constCtorExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool symExtNeqOptional = .constOptional(1) != constCtorExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.new(1) == ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.regular(1) == ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.named(x: 1) == ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.optional(1) == ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.new(1) != ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.regular(1) != ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.named(x: 1) != ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.optional(1) != ctor) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.new(1) == ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.regular(1) == ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.named(x: 1) == ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.optional(1) == ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.new(1) != ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.regular(1) != ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.named(x: 1) != ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.optional(1) != ctorExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified +} + +void rhsNeedsToBeShorthand( + ConstructorClass ctor, + ConstructorExt ctorExt, + bool condition, +) { + const Object obj = true; + const bool constCondition = obj as bool; + + const constCtor = .constRegular(1); + const bool rhsCtorEq = constCtor == (constCondition ? .constRegular(1) : ConstructorClass.constNamed(x: 1)); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool rhsCtorNeq = constCtor != (constCondition ? ConstructorClass.constOptional(1) : .constRegular(1)); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (ctor == (condition ? .new(1) : .regular(1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (ctor != (condition ? .optional(1) : .named(x: 1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (ctor case == (constCondition ? const .constRegular(1) : const .constNamed(x: 1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (ctor case != (constCondition ? const .constOptional(1) : const .constRegular(1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + const constCtorExt = .constRegular(1); + const bool rhsCtorExtEq = constCtorExt == (constCondition ? .constRegular(1) : ConstructorExt.constNamed(x: 1)); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool rhsCtorExtNeq = constCtorExt != (constCondition ? ConstructorExt.constOptional(1) : .constRegular(1)); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (ctorExt == (condition ? .new(1) : .regular(1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (ctorExt != (condition ? .named(x: 1) : .optional(1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (ctorExt case == (constCondition ? const .constRegular(1) : const .constNamed(x: 1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (ctorExt case != (constCondition ? const .constOptional(1) : const .constRegular(1))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } +} + +void objectContextType(ConstructorClass ctor, ConstructorExt ctorExt) { + const ConstructorClass constCtor = .constRegular(1); + const bool contextTypeCtorEqRegular = (constCtor as Object) == .constRegular(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorEqNamed = (constCtor as Object) == .constNamed(x: 1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorEqOptional = (constCtor as Object) == .constOptional(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorNeqRegular = (constCtor as Object) != .constRegular(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorNeqNamed = (constCtor as Object) != .constNamed(x: 1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorNeqOptional = (constCtor as Object) != .constOptional(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) == .new(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) == .regular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) == .named(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) == .optional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) != .new(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) != .regular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) != .named(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) != .optional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) case == const .constRegular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) case == const .constNamed(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) case == const .constOptional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) case != const .constRegular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) case != const .constNamed(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctor as Object) case != const .constOptional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const ConstructorExt constCtorExt = .constRegular(1); + const bool contextTypeCtorExtEqRegular = (constCtorExt as Object) == .constRegular(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorExtEqNamed = (constCtorExt as Object) == .constNamed(x: 1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorExtEqOptional = (constCtorExt as Object) == .constOptional(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorExtNeqRegular = (constCtorExt as Object) != .constRegular(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorExtNeqNamed = (constCtorExt as Object) != .constNamed(x: 1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + const bool contextTypeCtorExtNeqOptional = (constCtorExt as Object) != .constOptional(1); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) == .new(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) == .regular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) == .named(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) == .optional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) != .new(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) != .regular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) != .named(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) != .optional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) case == const .constRegular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) case == const .constNamed(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) case == const .constOptional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) case != const .constRegular(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) case != const .constNamed(x: 1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((ctorExt as Object) case != const .constOptional(1)) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified +} + +void main() { + ConstructorClass ctor = .new(1); + const ConstructorClass constCtor = .constRegular(1); + ConstructorExt ctorExt = .new(1); + const ConstructorExt constCtorExt = .constRegular(1); + + notSymmetrical(ctor, ctorExt); + rhsNeedsToBeShorthand(ctor, ctorExt, true); + rhsNeedsToBeShorthand(ctor, ctorExt, false); + objectContextType(ctor, ctorExt); + + // Test the constant evaluation for enum shorthands in const constructor + // asserts. + const ConstConstructorAssert.regular(constCtor); + const ConstConstructorAssert.named(constCtor); + const ConstConstructorAssert.optional(constCtor); + const ConstConstructorAssert.regularExt(constCtorExt); + const ConstConstructorAssert.namedExt(constCtorExt); + const ConstConstructorAssert.optionalExt(constCtorExt); +} diff --git a/tests/language/enum_shorthands/equality/equality_ctor_test.dart b/tests/language/enum_shorthands/equality/equality_ctor_test.dart new file mode 100644 index 000000000000..7a9cc7880c92 --- /dev/null +++ b/tests/language/enum_shorthands/equality/equality_ctor_test.dart @@ -0,0 +1,98 @@ +// 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. + +// Testing the == and != behaviour for enum shorthands with constructors. + +// SharedOptions=--enable-experiment=enum-shorthands + +import '../enum_shorthand_helper.dart'; + +class ConstConstructorAssert { + const ConstConstructorAssert.regular(ConstructorClass ctor) + : assert(ctor == const .constRegular(1)); + + const ConstConstructorAssert.named(ConstructorClass ctor) + : assert(ctor == const .constNamed(x: 1)); + + const ConstConstructorAssert.optional(ConstructorClass ctor) + : assert(ctor == const .constOptional(1)); + + const ConstConstructorAssert.regularExt(ConstructorExt ctor) + : assert(ctor == const .constRegular(1)); + + const ConstConstructorAssert.namedExt(ConstructorExt ctor) + : assert(ctor == const .constNamed(x: 1)); + + const ConstConstructorAssert.optionalExt(ConstructorExt ctor) + : assert(ctor == const .constOptional(1)); +} + +void main() { + ConstructorClass ctor = ConstructorClass(1); + const ConstructorClass constCtor = .constRegular(1); + + const bool constEqRegular = constCtor == .constRegular(1); + const bool constEqNamed = constCtor == .constNamed(x: 1); + const bool constEqOptional = constCtor == .constOptional(1); + + const bool constNeqRegular = constCtor != .constRegular(1); + const bool constNeqNamed = constCtor != .constNamed(x: 1); + const bool constNeqOptional = constCtor != .constOptional(1); + + if (ctor == .new(1)) print('ok'); + if (ctor == .regular(1)) print('ok'); + if (ctor == .named(x: 1)) print('ok'); + if (ctor == .optional(1)) print('ok'); + + if (ctor case == const .constRegular(1)) print('ok'); + if (ctor case == const .constNamed(x: 1)) print('ok'); + if (ctor case == const .constOptional(1)) print('ok'); + + if (ctor != .new(1)) print('ok'); + if (ctor != .regular(1)) print('ok'); + if (ctor != .named(x: 1)) print('ok'); + if (ctor != .optional(1)) print('ok'); + + if (ctor case != const .constRegular(1)) print('ok'); + if (ctor case != const .constNamed(x: 1)) print('ok'); + if (ctor case != const .constOptional(1)) print('ok'); + + ConstructorExt ctorExt = ConstructorExt(1); + const ConstructorExt constCtorExt = .constRegular(1); + + const bool constEqRegularExt = constCtorExt == .constRegular(1); + const bool constEqNamedExt = constCtorExt == .constNamed(x: 1); + const bool constEqOptionalExt = constCtorExt == .constOptional(1); + + const bool constNeqRegularExt = constCtorExt != .constRegular(1); + const bool constNeqNamedExt = constCtorExt != .constNamed(x: 1); + const bool constNeqOptionalExt = constCtorExt != .constOptional(1); + + if (ctorExt == .new(1)) print('ok'); + if (ctorExt == .regular(1)) print('ok'); + if (ctorExt == .named(x: 1)) print('ok'); + if (ctorExt == .optional(1)) print('ok'); + + if (ctorExt case == const .constRegular(1)) print('ok'); + if (ctorExt case == const .constNamed(x: 1)) print('ok'); + if (ctorExt case == const .constOptional(1)) print('ok'); + + if (ctorExt != .new(1)) print('ok'); + if (ctorExt != .regular(1)) print('ok'); + if (ctorExt != .named(x: 1)) print('ok'); + if (ctorExt != .optional(1)) print('ok'); + + if (ctorExt case != const .constRegular(1)) print('ok'); + if (ctorExt case != const .constNamed(x: 1)) print('ok'); + if (ctorExt case != const .constOptional(1)) print('ok'); + + // Test the constant evaluation for enum shorthands in const constructor + // asserts. + const ConstConstructorAssert.regular(constCtor); + const ConstConstructorAssert.named(constCtor); + const ConstConstructorAssert.optional(constCtor); + const ConstConstructorAssert.regularExt(constCtorExt); + const ConstConstructorAssert.namedExt(constCtorExt); + const ConstConstructorAssert.optionalExt(constCtorExt); +} diff --git a/tests/language/enum_shorthands/equality/equality_error_test.dart b/tests/language/enum_shorthands/equality/equality_error_test.dart index 992786b40178..c60fb77e7888 100644 --- a/tests/language/enum_shorthands/equality/equality_error_test.dart +++ b/tests/language/enum_shorthands/equality/equality_error_test.dart @@ -60,32 +60,36 @@ class ConstConstructorAssert { void notSymmetrical(Color color, Integer integer, IntegerExt integerExt, IntegerMixin integerMixin) { - const bool symBlueEq = .blue == color; + const constColor = Color.blue; + + const bool symBlueEq = .blue == constColor; // ^ // [analyzer] unspecified // [cfe] unspecified - const bool symBlueNeq = .blue != color; + const bool symBlueNeq = .blue != constColor; // ^ // [analyzer] unspecified // [cfe] unspecified - const bool symOneEq = .one == integer; + const constInteger = Integer.constOne; + const bool symOneEq = .one == constInteger; // ^ // [analyzer] unspecified // [cfe] unspecified - const bool symOneNeq = .one != integer; + const bool symOneNeq = .one != constInteger; // ^ // [analyzer] unspecified // [cfe] unspecified - const bool symOneExtEq = .one == integerExt; + const constIntegerExt = IntegerExt.constOne; + const bool symOneExtEq = .one == constIntegerExt; // ^ // [analyzer] unspecified // [cfe] unspecified - const bool symOneExtNeq = .one != integerExt; + const bool symOneExtNeq = .one != constIntegerExt; // ^ // [analyzer] unspecified // [cfe] unspecified diff --git a/tests/language/enum_shorthands/equality/equality_member_error_test.dart b/tests/language/enum_shorthands/equality/equality_member_error_test.dart new file mode 100644 index 000000000000..828c179b1808 --- /dev/null +++ b/tests/language/enum_shorthands/equality/equality_member_error_test.dart @@ -0,0 +1,178 @@ +// 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. + +// Testing erroneous ways of using shorthands with the `==` and `!=` operators +// for static members. + +// SharedOptions=--enable-experiment=enum-shorthands + +import '../enum_shorthand_helper.dart'; + +void notSymmetrical(StaticMember member, StaticMemberExt memberExt) { + bool eq = .member() == member; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + bool eqType = .memberType('s') == member; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + bool neq = .member() != member; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + bool neqType = .memberType('s') != member; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + bool eqExt = .member() == memberExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + bool eqTypeExt = .memberType('s') == memberExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + bool neqExt = .member() != memberExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + bool neqTypeExt = .memberType('s') != memberExt; + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.member() == member) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.memberType('s') == member) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.member() != member) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.memberType('s') != member) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.member() == memberExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.memberType('s') == memberExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.member() != memberExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if (.memberType('s') != memberExt) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified +} + +void rhsNeedsToBeShorthand( + StaticMember member, + StaticMemberExt memberExt, + bool condition, +) { + if (member == (condition ? .member() : .memberType('s'))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (member != (condition ? .member() : .memberType('s'))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (memberExt == (condition ? .member() : .memberType('s'))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } + + if (memberExt != (condition ? .member() : .memberType('s'))) { + // ^ + // [analyzer] unspecified + // [cfe] unspecified + print('not ok'); + } +} + +void objectContextType(StaticMember member, StaticMemberExt memberExt) { + if ((member as Object) == .member()) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((member as Object) == .memberType('s')) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((member as Object) != .member()) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((member as Object) != .memberType('s')) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((memberExt as Object) == .member()) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((memberExt as Object) == .memberType('s')) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((memberExt as Object) != .member()) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified + + if ((memberExt as Object) != .memberType('s')) print('not ok'); + // ^ + // [analyzer] unspecified + // [cfe] unspecified +} + +void main() { + StaticMember member = .member(); + StaticMemberExt memberExt = .member(); + + notSymmetrical(member, memberExt); + rhsNeedsToBeShorthand(member, memberExt, true); + rhsNeedsToBeShorthand(member, memberExt, false); + objectContextType(member, memberExt); +} diff --git a/tests/language/enum_shorthands/equality/equality_member_test.dart b/tests/language/enum_shorthands/equality/equality_member_test.dart new file mode 100644 index 000000000000..6a7b2b28b392 --- /dev/null +++ b/tests/language/enum_shorthands/equality/equality_member_test.dart @@ -0,0 +1,28 @@ +// 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. + +// Testing the == and != behaviour for enum shorthands with static members. + +// SharedOptions=--enable-experiment=enum-shorthands + +import '../enum_shorthand_helper.dart'; + +void main() { + // Enum + StaticMember member = .member(); + + bool eq = member == .member(); + bool neq = member != .member(); + + if (member == .member()) print('ok'); + if (member != .member()) print('ok'); + + StaticMember memberType = .memberType('s'); + + bool eqType = memberType == .memberType('s'); + bool neqType = memberType != .memberType('s'); + + if (memberType == .memberType('s')) print('ok'); + if (memberType != .memberType('s')) print('ok'); +}