-
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.
linter: Migrate prefer_conditional_assignment tests
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try Change-Id: I0e09a9b51df81bad301cb7451534856afa7aea58 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377727 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
- Loading branch information
Showing
3 changed files
with
156 additions
and
132 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
153 changes: 153 additions & 0 deletions
153
pkg/linter/test/rules/prefer_conditional_assignment_test.dart
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,153 @@ | ||
// 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. | ||
|
||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../rule_test_support.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(PreferConditionalAssignmentTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class PreferConditionalAssignmentTest extends LintRuleTest { | ||
@override | ||
String get lintRule => 'prefer_conditional_assignment'; | ||
|
||
test_field_ifEqNull() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? x; | ||
void f(String s) { | ||
if (x == null) { | ||
x = s; | ||
} | ||
} | ||
} | ||
''', [ | ||
lint(49, 35), | ||
]); | ||
} | ||
|
||
test_field_ifEqNull_conditionWrappedInParens() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? x; | ||
void f(String s) { | ||
if ((x == null)) { | ||
x = s; | ||
} | ||
} | ||
} | ||
''', [ | ||
lint(48, 37), | ||
]); | ||
} | ||
|
||
test_field_ifEqNull_eachWrappedInParens() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? x; | ||
void f(String s) { | ||
if ((x) == (null)) { | ||
x = s; | ||
} | ||
} | ||
} | ||
''', [ | ||
lint(48, 39), | ||
]); | ||
} | ||
|
||
test_field_ifEqNull_statementBody() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? x; | ||
String? f(String s) { | ||
if (x == null) | ||
x = s; | ||
return x; | ||
} | ||
} | ||
''', [ | ||
lint(51, 27), | ||
]); | ||
} | ||
|
||
test_field_ifHasElse() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? x; | ||
void f() { | ||
if (x == null) { | ||
x = foo(this); | ||
} else {} | ||
} | ||
} | ||
String foo(C c) => ''; | ||
'''); | ||
} | ||
|
||
test_field_onOtherTarget() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? x; | ||
void f(C a, C b) { | ||
if (a.x == null) { | ||
b.x = ''; | ||
} | ||
} | ||
} | ||
'''); | ||
} | ||
|
||
test_field_onSameTarget() async { | ||
await assertDiagnostics(r''' | ||
class C { | ||
String? x; | ||
void f(C a) { | ||
if (a.x == null) { | ||
a.x = ''; | ||
} | ||
} | ||
} | ||
''', [ | ||
lint(43, 40), | ||
]); | ||
} | ||
|
||
test_field_unrelatedAssignment() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? x; | ||
var y = 1; | ||
void f() { | ||
if (x == null) { | ||
y = 0; | ||
} | ||
} | ||
} | ||
'''); | ||
} | ||
|
||
test_field_unrelatedAssignment_thenAssignment() async { | ||
await assertNoDiagnostics(r''' | ||
class C { | ||
String? x; | ||
var y = 1; | ||
void f() { | ||
if (x == null) { | ||
y = 0; | ||
x = ''; | ||
} | ||
} | ||
} | ||
'''); | ||
} | ||
} |
132 changes: 0 additions & 132 deletions
132
pkg/linter/test_data/rules/prefer_conditional_assignment.dart
This file was deleted.
Oops, something went wrong.