Skip to content

Commit 8d80d97

Browse files
srawlinsCommit Queue
authored andcommitted
linter: Move avoid_multiple_declarations_per_line tests
Change-Id: I92271ad7999c521ea343c3199dc09f32a897b0c7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329140 Auto-Submit: Samuel Rawlins <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 5f89d7f commit 8d80d97

File tree

3 files changed

+99
-59
lines changed

3 files changed

+99
-59
lines changed

pkg/linter/test/rules/all.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import 'avoid_final_parameters_test.dart' as avoid_final_parameters;
1616
import 'avoid_function_literals_in_foreach_calls_test.dart'
1717
as avoid_function_literals_in_foreach_calls;
1818
import 'avoid_init_to_null_test.dart' as avoid_init_to_null;
19+
import 'avoid_multiple_declarations_per_line_test.dart'
20+
as avoid_multiple_declarations_per_line;
1921
import 'avoid_positional_boolean_parameters_test.dart'
2022
as avoid_positional_boolean_parameters;
2123
import 'avoid_print_test.dart' as avoid_print;
@@ -260,6 +262,7 @@ void main() {
260262
avoid_final_parameters.main();
261263
avoid_function_literals_in_foreach_calls.main();
262264
avoid_init_to_null.main();
265+
avoid_multiple_declarations_per_line.main();
263266
avoid_positional_boolean_parameters.main();
264267
avoid_print.main();
265268
avoid_private_typedef_functions.main();
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test_reflective_loader/test_reflective_loader.dart';
6+
7+
import '../rule_test_support.dart';
8+
9+
main() {
10+
defineReflectiveSuite(() {
11+
defineReflectiveTests(AvoidMultipleDeclarationsPerLineTest);
12+
});
13+
}
14+
15+
@reflectiveTest
16+
class AvoidMultipleDeclarationsPerLineTest extends LintRuleTest {
17+
@override
18+
String get lintRule => 'avoid_multiple_declarations_per_line';
19+
20+
test_extensionField_multiple() async {
21+
await assertDiagnostics(r'''
22+
extension E on Object {
23+
static String? a, b, c;
24+
}
25+
''', [
26+
lint(44, 1),
27+
]);
28+
}
29+
30+
test_extensionField_single() async {
31+
await assertNoDiagnostics(r'''
32+
extension E on Object {
33+
static String? a;
34+
}
35+
''');
36+
}
37+
38+
test_field_multiple() async {
39+
await assertDiagnostics(r'''
40+
class C {
41+
String? a, b, c;
42+
}
43+
''', [
44+
lint(23, 1),
45+
]);
46+
}
47+
48+
test_field_single() async {
49+
await assertNoDiagnostics(r'''
50+
class C {
51+
String? a;
52+
}
53+
''');
54+
}
55+
56+
test_forLoop_multiple() async {
57+
await assertNoDiagnostics(r'''
58+
// See https://github.com/dart-lang/linter/issues/2543.
59+
void f() {
60+
for (var i = 0, j = 0; i < 2 && j < 2; ++i, ++j) {}
61+
}
62+
''');
63+
}
64+
65+
test_functionVariable_multiple() async {
66+
await assertDiagnostics(r'''
67+
void f() {
68+
String? a, b, c;
69+
}
70+
''', [
71+
lint(24, 1),
72+
]);
73+
}
74+
75+
test_functionVariable_single() async {
76+
await assertNoDiagnostics(r'''
77+
void f() {
78+
String? a;
79+
}
80+
''');
81+
}
82+
83+
test_topLevel_multiple() async {
84+
await assertDiagnostics(r'''
85+
String? a, b, c;
86+
''', [
87+
lint(11, 1),
88+
]);
89+
}
90+
91+
test_topLevel_single() async {
92+
await assertNoDiagnostics(r'''
93+
String? a;
94+
''');
95+
}
96+
}

pkg/linter/test_data/rules/avoid_multiple_declarations_per_line.dart

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)