Skip to content

Commit

Permalink
Move avoid_types_on_closure_parameters tests (#4694)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Aug 14, 2023
1 parent 28ff65e commit 6b03b69
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 27 deletions.
3 changes: 3 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import 'avoid_single_cascade_in_expression_statements_test.dart'
as avoid_single_cascade_in_expression_statements;
import 'avoid_types_as_parameter_names_test.dart'
as avoid_types_as_parameter_names;
import 'avoid_types_on_closure_parameters_test.dart'
as avoid_types_on_closure_parameters;
import 'avoid_unused_constructor_parameters_test.dart'
as avoid_unused_constructor_parameters;
import 'avoid_void_async_test.dart' as avoid_void_async;
Expand Down Expand Up @@ -243,6 +245,7 @@ void main() {
avoid_shadowing_type_parameters.main();
avoid_single_cascade_in_expression_statements.main();
avoid_types_as_parameter_names.main();
avoid_types_on_closure_parameters.main();
avoid_unused_constructor_parameters.main();
avoid_void_async.main();
await_only_futures.main();
Expand Down
125 changes: 125 additions & 0 deletions test/rules/avoid_types_on_closure_parameters_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// 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(AvoidTypesOnClosureParametersTest);
});
}

@reflectiveTest
class AvoidTypesOnClosureParametersTest extends LintRuleTest {
@override
String get lintRule => 'avoid_types_on_closure_parameters';

test_argument() async {
await assertNoDiagnostics(r'''
void f(List<int> list) {
list.map((e) => e.isEven);
}
''');
}

test_argument_typedParameter() async {
await assertDiagnostics(r'''
void f(List<int> list) {
list.map((int e) => e.isEven);
}
''', [
lint(37, 3),
]);
}

test_initializerInDeclaration_namedOptional() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertNoDiagnostics(r'''
var f = ({e}) => e.isEven;
''');
}

test_initializerInDeclaration_optionalNullable() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertNoDiagnostics(r'''
var f = ([e]) => e.name;
''');
}

test_initializerInDeclaration_optionalWithDefault() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertNoDiagnostics(r'''
var f = ({e = ''}) => e;
''');
}

test_initializerInDeclaration_parameterIsTyped_dynamic() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertNoDiagnostics(r'''
var goodName5 = (dynamic person) => person.name;
''');
}

test_initializerInDeclaration_parameterIsTyped_functionType() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertDiagnostics(r'''
var functionWithFunction = (int f(int x)) => f(0);
''', [
lint(28, 12),
]);
}

test_initializerInDeclaration_parameterIsTyped_namedRequired() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertDiagnostics(r'''
var f = ({required int e}) => e.isEven;
''', [
lint(19, 3),
]);
}

test_initializerInDeclaration_parameterIsTyped_optionalNullable() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertDiagnostics(r'''
var f = ([int? e]) => e?.isEven;
''', [
lint(10, 4),
]);
}

test_initializerInDeclaration_parameterIsTyped_optionalWithDefault() async {
// TODO(srawlins): Any test which just assigns a function literal to a
// variable should be converted to something like an argument, or let
// downwards inference work in some other way.
// See https://github.com/dart-lang/linter/issues/1099.
await assertDiagnostics(r'''
var f = ([String e = '']) => e;
''', [
lint(10, 6),
]);
}
}
27 changes: 0 additions & 27 deletions test_data/rules/avoid_types_on_closure_parameters.dart

This file was deleted.

0 comments on commit 6b03b69

Please sign in to comment.