-
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 use_setters_to_change_properties tests (dart-lang/linter#4544)
- Loading branch information
Showing
3 changed files
with
113 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// 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(() { | ||
// TODO(srawlins): Add test with setter-like with multiple statements; add | ||
// test with non-trivial right side (`this.x = x + 1`). | ||
defineReflectiveTests(UseSettersToChangePropertiesTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class UseSettersToChangePropertiesTest extends LintRuleTest { | ||
@override | ||
String get lintRule => 'use_setters_to_change_properties'; | ||
|
||
test_setterLike_expressionBody() async { | ||
await assertDiagnostics(r''' | ||
abstract class A { | ||
int x = 0; | ||
void setX(int x) => this.x = x; | ||
} | ||
''', [ | ||
lint(39, 4), | ||
]); | ||
} | ||
|
||
test_setterLike_blockBody() async { | ||
await assertDiagnostics(r''' | ||
abstract class A { | ||
int x = 0; | ||
void setX(int x) { | ||
this.x = x; | ||
} | ||
} | ||
''', [ | ||
lint(39, 4), | ||
]); | ||
} | ||
|
||
test_combo() async { | ||
await assertNoDiagnostics(r''' | ||
abstract class A { | ||
int x = 0; | ||
void setX(int x) => this.x += x; | ||
} | ||
'''); | ||
} | ||
|
||
test_inheritedFromSuperclass() async { | ||
await assertNoDiagnostics(r''' | ||
abstract class A { | ||
void setX(int x); | ||
} | ||
class B extends A { | ||
int x = 0; | ||
void setX(int x) { | ||
this.x = x; | ||
} | ||
} | ||
'''); | ||
} | ||
|
||
test_abstract() async { | ||
await assertNoDiagnostics(r''' | ||
abstract class A { | ||
void setX(int x); | ||
} | ||
'''); | ||
} | ||
|
||
test_inheritedFromSuperInterface() async { | ||
await assertNoDiagnostics(r''' | ||
abstract class A { | ||
void setX(int x); | ||
} | ||
class B implements A { | ||
int x = 0; | ||
void setX(int x) { | ||
this.x = x; | ||
} | ||
} | ||
'''); | ||
} | ||
|
||
test_extension() async { | ||
await assertDiagnostics(r''' | ||
class A { | ||
int x = 0; | ||
} | ||
extension E on A { | ||
void setX(int x) { | ||
this.x = x; | ||
} | ||
} | ||
''', [ | ||
lint(52, 4), | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.