Skip to content

Commit

Permalink
Move sized_box_for_whitespace tests (#4684)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Aug 14, 2023
1 parent 76f414e commit a9e90d5
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 68 deletions.
3 changes: 3 additions & 0 deletions test/rule_test_support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,14 @@ class Container extends StatelessWidget {
super.key,
Color? color,
double? width,
double? height,
Widget? child,
});
}
class SizedBox implements Widget {}
class Row implements Widget {}
''');

libFolder
Expand Down
2 changes: 2 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import 'provide_deprecation_message_test.dart' as provide_deprecation_message;
import 'public_member_api_docs_test.dart' as public_member_api_docs;
import 'recursive_getters_test.dart' as recursive_getters;
import 'secure_pubspec_urls_test.dart' as secure_pubspec_urls;
import 'sized_box_for_whitespace_test.dart' as sized_box_for_whitespace;
import 'slash_for_doc_comments_test.dart' as slash_for_doc_comments;
import 'sort_constructors_first_test.dart' as sort_constructors_first;
import 'sort_pub_dependencies_test.dart' as sort_pub_dependencies;
Expand Down Expand Up @@ -322,6 +323,7 @@ void main() {
public_member_api_docs.main();
recursive_getters.main();
secure_pubspec_urls.main();
sized_box_for_whitespace.main();
slash_for_doc_comments.main();
sort_constructors_first.main();
sort_pub_dependencies.main();
Expand Down
145 changes: 145 additions & 0 deletions test/rules/sized_box_for_whitespace_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// 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(SizedBoxForWhitespaceTest);
});
}

@reflectiveTest
class SizedBoxForWhitespaceTest extends LintRuleTest {
@override
bool get addFlutterPackageDep => true;

@override
String get lintRule => 'sized_box_for_whitespace';

test_hasChild() async {
await assertNoDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
child: Row(),
);
}
''');
}

test_hasHeight_andChild() async {
await assertDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
height: 10,
child: Row(),
);
}
''', [
lint(62, 9),
]);
}

test_hasHeight_noChild() async {
await assertNoDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
height:10,
);
}
''');
}

test_hasWidth_andChild() async {
await assertDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
width: 10,
child: Row(),
);
}
''', [
lint(62, 9),
]);
}

test_hasWidth_noChild() async {
await assertNoDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
width: 10,
);
}
''');
}

test_hasWidthAndHeight_andChild() async {
await assertDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
width: 10,
height: 10,
child: Row(),
);
}
''', [
lint(62, 9),
]);
}

test_hasWidthAndHeight_andKey_noChild() async {
await assertDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
key: Key(''),
width: 10,
height: 10,
);
}
''', [
lint(62, 9),
]);
}

test_hasWidthAndHeight_noChild() async {
await assertDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget f() {
return Container(
width: 10,
height: 10,
);
}
''', [
lint(62, 9),
]);
}

test_noArguments() async {
await assertNoDiagnostics(r'''
import 'package:flutter/widgets.dart';
Widget emptyContainer() {
return Container();
}
''');
}
}
68 changes: 0 additions & 68 deletions test_data/rules/sized_box_for_whitespace.dart

This file was deleted.

0 comments on commit a9e90d5

Please sign in to comment.