linter: Migrate the curly_braces_in_flow_control_structures tests

Work towards https://github.com/dart-lang/linter/issues/4870

Change-Id: I0e52227496d3ea26e498501c59e3b2af0e9c67fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352982
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/linter/test/rules/all.dart b/pkg/linter/test/rules/all.dart
index 9f0f5cd..88349ef 100644
--- a/pkg/linter/test/rules/all.dart
+++ b/pkg/linter/test/rules/all.dart
@@ -70,6 +70,8 @@
     as conditional_uri_does_not_exist;
 import 'constant_identifier_names_test.dart' as constant_identifier_names;
 import 'control_flow_in_finally_test.dart' as control_flow_in_finally;
+import 'curly_braces_in_flow_control_structures_test.dart'
+    as curly_braces_in_flow_control_structures;
 import 'dangling_library_doc_comments_test.dart'
     as dangling_library_doc_comments;
 import 'depend_on_referenced_packages_test.dart'
@@ -303,6 +305,7 @@
   conditional_uri_does_not_exist.main();
   constant_identifier_names.main();
   control_flow_in_finally.main();
+  curly_braces_in_flow_control_structures.main();
   dangling_library_doc_comments.main();
   depend_on_referenced_packages.main();
   deprecated_consistency.main();
diff --git a/pkg/linter/test/rules/curly_braces_in_flow_control_structures_test.dart b/pkg/linter/test/rules/curly_braces_in_flow_control_structures_test.dart
new file mode 100644
index 0000000..afafd35
--- /dev/null
+++ b/pkg/linter/test/rules/curly_braces_in_flow_control_structures_test.dart
@@ -0,0 +1,260 @@
+// 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(CurlyBracesInFlowControlStructuresTest);
+  });
+}
+
+@reflectiveTest
+class CurlyBracesInFlowControlStructuresTest extends LintRuleTest {
+  @override
+  String get lintRule => 'curly_braces_in_flow_control_structures';
+
+  test_doWhile_block_sameLineAsDo() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  do { print(''); }
+  while (true);
+}
+''');
+  }
+
+  test_doWhile_singeStatement_sameLineAsDo() async {
+    await assertDiagnostics(r'''
+void f() {
+  do print('');
+  while (true);
+}
+''', [
+      lint(16, 10),
+    ]);
+  }
+
+  test_doWhile_singleStatement_lineAfterDo() async {
+    await assertDiagnostics(r'''
+void f() {
+  do
+    print('');
+  while (true);
+}
+''', [
+      lint(20, 10),
+    ]);
+  }
+
+  test_doWhile_singleStatement_sameLineAsDoAndWhile() async {
+    await assertDiagnostics(r'''
+void f() {
+  do print(''); while (true);
+}
+''', [
+      lint(16, 10),
+    ]);
+  }
+
+  test_forEachLoop_block_sameLine() async {
+    await assertNoDiagnostics(r'''
+void f(List<int> l) {
+  for (var i in l) {}
+}
+''');
+  }
+
+  test_forEachLoop_singleStatement_lineAfter() async {
+    await assertDiagnostics(r'''
+void f(List<int> l) {
+  for (var i in l)
+    return;
+}
+''', [
+      lint(45, 7),
+    ]);
+  }
+
+  test_forEachLoop_singleStatement_sameLine() async {
+    await assertDiagnostics(r'''
+void f(List<int> l) {
+  for (var i in l) return;
+}
+''', [
+      lint(41, 7),
+    ]);
+  }
+
+  test_forLoop_emptyBlock_sameLine() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  for (;;) {}
+}
+''');
+  }
+
+  test_forLoop_singleStatement_lineAfter() async {
+    await assertDiagnostics(r'''
+void f() {
+  for (;;)
+    return;
+}
+''', [
+      lint(26, 7),
+    ]);
+  }
+
+  test_forLoop_singleStatement_sameLine() async {
+    await assertDiagnostics(r'''
+void f() {
+  for (;;) return;
+}
+''', [
+      lint(22, 7),
+    ]);
+  }
+
+  test_ifStatement_block_sameLine() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  if (1 == 2) {}
+}
+''');
+  }
+
+  test_ifStatement_block_sameLine_multiLine() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  if (1 == 2) {
+  }
+}
+''');
+  }
+
+  test_ifStatement_singleStatement_lineAfter() async {
+    await assertDiagnostics(r'''
+void f() {
+  if (1 == 2)
+    return;
+}
+''', [
+      lint(29, 7),
+    ]);
+  }
+
+  test_ifStatement_singleStatement_multiLine() async {
+    await assertDiagnostics(r'''
+void f() {
+  if (1 == 2) print(
+    'First argument'
+    'Second argument');
+}
+''', [
+      lint(25, 51),
+    ]);
+  }
+
+  test_ifStatement_singleStatement_sameLine() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  if (1 == 2) return;
+}
+''');
+  }
+
+  test_ifStatementElse_block_sameLine() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  if (1 == 2) {}
+  else {}
+}
+''');
+  }
+
+  test_ifStatementElse_singleStatement_lineAfter() async {
+    await assertDiagnostics(r'''
+void f() {
+  if (1 == 2) {}
+  else
+    return;
+}
+''', [
+      lint(39, 7),
+    ]);
+  }
+
+  test_ifStatementElse_singleStatement_sameLine() async {
+    await assertDiagnostics(r'''
+void f() {
+  if (1 == 2) {}
+  else return;
+}
+''', [
+      lint(35, 7),
+    ]);
+  }
+
+  test_ifStatementElseIf_block_sameLine_multiLine() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  if (1 == 2) {} else if (2 == 3) {
+  }
+}
+''');
+  }
+
+  test_ifStatementElseIf_singleStatement_lineAfter() async {
+    await assertDiagnostics(r'''
+void f() {
+  if (1 == 2) {}
+  else if (1 == 2)
+    return;
+}
+''', [
+      lint(51, 7),
+    ]);
+  }
+
+  test_ifStatementElseIf_singleStatement_sameLine_lineAfterIfCondition() async {
+    await assertDiagnostics(r'''
+void f() {
+  if (1 == 2) {
+  } else if (1 == 3) return;
+}
+''', [
+      lint(48, 7),
+    ]);
+  }
+
+  test_whileLoop_block_sameLine() async {
+    await assertNoDiagnostics(r'''
+void f() {
+  while (true) {}
+}
+''');
+  }
+
+  test_whileLoop_singleStatement_nextLine() async {
+    await assertDiagnostics(r'''
+void f() {
+  while (true)
+    return;
+}
+''', [
+      lint(30, 7),
+    ]);
+  }
+
+  test_whileLoop_singleStatement_sameLine() async {
+    await assertDiagnostics(r'''
+void f() {
+  while (true) return;
+}
+''', [
+      lint(26, 7),
+    ]);
+  }
+}
diff --git a/pkg/linter/test_data/rules/curly_braces_in_flow_control_structures.dart b/pkg/linter/test_data/rules/curly_braces_in_flow_control_structures.dart
deleted file mode 100644
index dc290b8..0000000
--- a/pkg/linter/test_data/rules/curly_braces_in_flow_control_structures.dart
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) 2018, 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.
-
-testIfElse() {
-  if (false) return; // OK
-
-  if (false) {} // OK
-
-  if (false)
-    return; // LINT
-
-  if (false) { // OK
-  }
-
-  if (false)
-    return; // LINT
-  else return; // LINT
-
-  if (false) {
-  }
-  else if (false) { // OK
-  }
-  else {
-  }
-
-  if (false)
-    return; // LINT
-  else if (false)
-    return; // LINT
-  else
-    return; // LINT
-
-  if (false) { // OK
-  } else if (false) { // OK
-  } else { // OK
-  }
-
-  if (false) { } // OK
-  else return; // LINT
-
-  if (false)
-    return; // LINT
-  else
-    return; // LINT
-
-  if (false){ }// OK
-  else {} // OK
-
-  if (false) print( // LINT
-    'First argument'
-    'Second argument');
-
-  if (false) { print('should be on next line'); // OK
-  }
-
-  if (true) {
-  } else if (true) return; //LINT
-
-  if (true) {
-  } else if (true)
-    return; //LINT
-}
-
-testWhile() {
-  while (true) return; // LINT
-
-  while (true) {} // OK
-
-  while (true)
-    return; // LINT
-}
-
-testForEach(List l) {
-  for (var i in l) return; // LINT
-
-  for (var i in l) {} // OK
-
-  for (var i in l)
-    return; // LINT
-}
-
-testFor() {
-  for (;;) return; // LINT
-
-  for (;;) {} // OK
-
-  for (;;)
-    return; // LINT
-}
-
-testDo() {
-  do print(''); while (true); // LINT
-  do print(''); // LINT
-  while (true);
-
-  do
-    print(''); // LINT
-  while (true);
-
-  do {print('');} // OK
-  while (true);
-}
diff --git a/pkg/linter/tool/legacy_test_move.dart b/pkg/linter/tool/legacy_test_move.dart
index 680bd21..6b88d4d 100644
--- a/pkg/linter/tool/legacy_test_move.dart
+++ b/pkg/linter/tool/legacy_test_move.dart
@@ -27,7 +27,7 @@
     var ruleNameCamelCase = ruleName.splitMapJoin(RegExp('(?:^|_)([a-z])'),
         onMatch: (m) => m[1]!.toUpperCase());
     return '''
-// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS 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.