-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move unnecessary_getters_setters tests (dart-lang/linter#4549)
- Loading branch information
Showing
4 changed files
with
134 additions
and
95 deletions.
There are no files selected for viewing
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
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
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,126 @@ | ||
// Copyright (c) 2023, 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(UnnecessaryGettersSettersTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class UnnecessaryGettersSettersTest extends LintRuleTest { | ||
@override | ||
String get lintRule => 'unnecessary_getters_setters'; | ||
|
||
test_necessary_differentType() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? _x; | ||
dynamic get x { | ||
return _x; | ||
} | ||
set x(dynamic value) { | ||
_x = value; | ||
} | ||
} | ||
'''); | ||
} | ||
|
||
test_necessary_hasAnnotation() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? _x; | ||
@Annotation() | ||
String? get x => _x; | ||
set x(String? value) { | ||
_x = value; | ||
} | ||
} | ||
class Annotation { | ||
const Annotation(); | ||
} | ||
'''); | ||
} | ||
|
||
test_necessary_nonTrivialSetter() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? _x; | ||
String? get x => _x; | ||
set x(String? value) { | ||
_x = value?.toLowerCase(); | ||
} | ||
} | ||
'''); | ||
} | ||
|
||
test_necessary_nullAwareAssignment() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? _x; | ||
String? get x => _x; | ||
set x(String? value) { | ||
_x ??= value; | ||
} | ||
} | ||
'''); | ||
} | ||
|
||
test_unnecessary_getterAndSetterHaveBlockBody() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? _x; | ||
String? get x { | ||
return _x; | ||
} | ||
set x(String? value) { | ||
_x = value; | ||
} | ||
} | ||
''', [ | ||
lint(39, 1), | ||
]); | ||
} | ||
|
||
test_unnecessary_getterHasExpressionBody() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? _x; | ||
String? get x => _x; | ||
set x(String? value) | ||
{ | ||
_x = value; | ||
} | ||
} | ||
''', [ | ||
lint(39, 1), | ||
]); | ||
} | ||
|
||
test_unnecessary_setterHasExpressionBody() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? _x; | ||
String? get x { | ||
return _x; | ||
} | ||
set x(String? value) => _x = value; | ||
} | ||
''', [ | ||
lint(39, 1), | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.