blob: 381e06ec748e31a83350d7d9deb5f5748901b927 [file]
// 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';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(PreferIfNullOperatorsTest);
});
}
@reflectiveTest
class PreferIfNullOperatorsTest extends LintRuleTest {
@override
String get lintRule => LintNames.prefer_if_null_operators;
test_null_eqEq_nullable() async {
await assertDiagnosticsFromMarkup(r'''
void f(int? p) {
[!null == p ? 1 : p!];
}
''');
}
test_null_notEq_nullable() async {
await assertDiagnosticsFromMarkup(r'''
void f(int? p) {
[!null != p ? p : 2!];
}
''');
}
test_nullable_eqEq_null() async {
await assertDiagnosticsFromMarkup(r'''
void f(int? p) {
[!p == null ? 1 : p!];
}
''');
}
test_nullable_notEq_null() async {
await assertDiagnosticsFromMarkup(r'''
void f(int? p) {
[!p != null ? p : 2!];
}
''');
}
test_nullablePrefixedIdentifier_notEq_null() async {
await assertDiagnosticsFromMarkup(r'''
void f(C c) {
[!c.d != null ? c.d : 7!];
}
class C {
int? get d => 7;
}
''');
}
}