Files
sdk/pkg/linter/test/rules/empty_statements_test.dart
Brian Wilkerson a16de199d7 Convert many lint tests to use markdown
This is a rediculously large CL, and if you want me to split it up I'm
willing to do so.

However, the changes were all made by running a script I wrote and then
running the formatter over the code, so hopefully a spot-check will be
sufficient.

Change-Id: Ifc59b2cc3bf9e4edf0229a130cd587dc73f95615
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505042
Reviewed-by: Samuel Rawlins <srawlins@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-20 11:27:11 -07:00

147 lines
2.6 KiB
Dart

// 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';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(EmptyStatementsTest);
});
}
@reflectiveTest
class EmptyStatementsTest extends LintRuleTest {
@override
String get lintRule => LintNames.empty_statements;
test_emptyFor() async {
await assertDiagnosticsFromMarkdown(r'''
void f(bool b) {
for ( ; b; )[!;!]
}
''');
}
test_emptyIf_followedByBlock() async {
await assertDiagnosticsFromMarkdown(r'''
void f(bool b) {
if (b)[!;!]
{
print(b);
}
}
''');
}
test_emptyIf_followedByStatement() async {
await assertDiagnosticsFromMarkdown(r'''
void f(bool b) {
if (b)[!;!]
print(b);
}
''');
}
test_emptyWhile() async {
await assertDiagnosticsFromMarkdown(r'''
void f(bool b) {
while (b)[!;!]
}
''');
}
test_nonEmptyIf_emptyBlock() async {
await assertNoDiagnostics(r'''
void f(bool b) {
if (b) {}
}
''');
}
test_nonEmptyWhile_emptyBlock() async {
await assertNoDiagnostics(r'''
void f(bool b) {
while (b) {}
}
''');
}
/// https://github.com/dart-lang/linter/issues/4410
test_switchPatternCase_justEmpties() async {
await assertDiagnosticsFromMarkdown(r'''
f() {
switch(true) {
case true :
/*[0*/;/*0]*/
/*[1*/;/*1]*/
;
case false :
print('');
}
}
''');
}
/// https://github.com/dart-lang/linter/issues/4410
test_switchPatternCase_leading() async {
await assertDiagnosticsFromMarkdown(r'''
f() {
switch(true) {
case true :
[!;!]
print('');
case false :
print('');
}
}
''');
}
/// https://github.com/dart-lang/linter/issues/4410
test_switchPatternCase_leading_trailing() async {
await assertDiagnosticsFromMarkdown(r'''
f() {
switch(true) {
case true :
[!;!]
;
case false :
print('');
}
}
''');
}
/// https://github.com/dart-lang/linter/issues/4410
test_switchPatternCase_only() async {
await assertNoDiagnostics(r'''
f() {
switch(true) {
case true :
;
case false :
print('');
}
}
''');
}
/// https://github.com/dart-lang/linter/issues/4410
test_switchPatternCase_trailing() async {
await assertDiagnosticsFromMarkdown(r'''
f() {
switch(true) {
case true :
print('');
[!;!]
case false :
print('');
}
}
''');
}
}