Skip to content

Commit

Permalink
Move unnecessary_null_in_if_null_operators tests (#4524)
Browse files Browse the repository at this point in the history
* Move unnecessary_null_in_if_null_operators tests

* rename
  • Loading branch information
srawlins authored Jul 5, 2023
1 parent b411303 commit 3a38f78
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
3 changes: 3 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ import 'unnecessary_new_test.dart' as unnecessary_new;
import 'unnecessary_null_aware_assignments_test.dart'
as unnecessary_null_aware_assignments;
import 'unnecessary_null_checks_test.dart' as unnecessary_null_checks;
import 'unnecessary_null_in_if_null_operators_test.dart'
as unnecessary_null_in_if_null_operators;
import 'unnecessary_nullable_for_final_variable_declarations_test.dart'
as unnecessary_nullable_for_final_variable_declarations;
import 'unnecessary_overrides_test.dart' as unnecessary_overrides;
Expand Down Expand Up @@ -285,6 +287,7 @@ void main() {
unnecessary_new.main();
unnecessary_null_aware_assignments.main();
unnecessary_null_checks.main();
unnecessary_null_in_if_null_operators.main();
unnecessary_nullable_for_final_variable_declarations.main();
unnecessary_overrides.main();
unnecessary_parenthesis.main();
Expand Down
72 changes: 72 additions & 0 deletions test/rules/unnecessary_null_in_if_null_operators_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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(UnnecessaryNullInIfNullOperatorsLanguage29Test);
});
}

@reflectiveTest
class UnnecessaryNullInIfNullOperatorsLanguage29Test extends LintRuleTest {
@override
String get lintRule => 'unnecessary_null_in_if_null_operators';

@override
String get testPackageLanguageVersion => '2.9';

test_localVariableDeclaration_noNull() async {
await assertNoDiagnostics(r'''
void f() {
var x = 1 ?? 1;
}
''');
}

test_localVariableDeclaration_nullOnLeft() async {
await assertDiagnostics(r'''
void f() {
var x = null ?? 1;
}
''', [
lint(21, 9),
]);
}

test_localVariableDeclaration_nullOnRight() async {
await assertDiagnostics(r'''
void f() {
var x = 1 ?? null;
}
''', [
lint(21, 9),
]);
}

test_topLevelVariableDeclaration_noNull() async {
await assertNoDiagnostics(r'''
var x = 1 ?? 1;
''');
}

test_topLevelVariableDeclaration_nullOnLeft() async {
await assertDiagnostics(r'''
var x = null ?? 1;
''', [
lint(8, 9),
]);
}

test_topLevelVariableDeclaration_nullOnRight() async {
await assertDiagnostics(r'''
var x = 1 ?? null;
''', [
lint(8, 9),
]);
}
}
17 changes: 0 additions & 17 deletions test_data/rules/unnecessary_null_in_if_null_operators.dart

This file was deleted.

0 comments on commit 3a38f78

Please sign in to comment.