From c3d457087a938d98e2e3b358a884832ed40be4fd Mon Sep 17 00:00:00 2001 From: pq Date: Thu, 27 Jan 2022 10:40:46 -0800 Subject: [PATCH] enhanced enum tests for `annotate_overrides` --- test/rules/all.dart | 2 + test/rules/annotate_overrides.dart | 59 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/rules/annotate_overrides.dart diff --git a/test/rules/all.dart b/test/rules/all.dart index b7e776e99..cf03bfc1a 100644 --- a/test/rules/all.dart +++ b/test/rules/all.dart @@ -2,6 +2,7 @@ // 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. +import 'annotate_overrides.dart' as annotate_overrides; import 'avoid_annotating_with_dynamic.dart' as avoid_annotating_with_dynamic; import 'avoid_function_literals_in_foreach_calls.dart' as avoid_function_literals_in_foreach_calls; @@ -48,6 +49,7 @@ import 'use_is_even_rather_than_modulo.dart' as use_is_even_rather_than_modulo; import 'void_checks.dart' as void_checks; void main() { + annotate_overrides.main(); avoid_annotating_with_dynamic.main(); avoid_function_literals_in_foreach_calls.main(); avoid_init_to_null.main(); diff --git a/test/rules/annotate_overrides.dart b/test/rules/annotate_overrides.dart new file mode 100644 index 000000000..3e0d52e5b --- /dev/null +++ b/test/rules/annotate_overrides.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2022, 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. + +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import '../rule_test_support.dart'; + +main() { + defineReflectiveSuite(() { + defineReflectiveTests(AnnotateOverridesTest); + }); +} + +@reflectiveTest +class AnnotateOverridesTest extends LintRuleTest { + @override + List get experiments => [ + EnableString.enhanced_enums, + ]; + + @override + String get lintRule => 'annotate_overrides'; + + test_field() async { + await assertDiagnostics(r''' +enum A { + a,b,c; + int get hashCode => 0; +} +''', [ + lint('annotate_overrides', 28, 8), + ]); + } + + test_method() async { + await assertDiagnostics(r''' +enum A { + a,b,c; + String toString() => ''; +} +''', [ + lint('annotate_overrides', 27, 8), + ]); + } + + @FailingTest(issue: 'https://github.com/dart-lang/linter/issues/3093') + test_ok() async { + await assertNoDiagnostics(r''' +enum A { + a,b,c; + @override + int get hashCode => 0; + @override + String toString() => ''; +} +'''); + } +}