blob: 8bb30fbf7465d0298e660936d45bc976ab9bd3a3 [file] [log] [blame]
// Copyright (c) 2019, 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:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ExtraPositionalArgumentsCouldBeNamedTest);
defineReflectiveTests(ExtraPositionalArgumentsTest);
});
}
@reflectiveTest
class ExtraPositionalArgumentsCouldBeNamedTest
extends PubPackageResolutionTest {
test_constConstructor() async {
await assertErrorsInCode(r'''
class A {
const A({int x});
}
main() {
const A(0);
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 50,
3),
]);
}
test_constConstructor_super() async {
await assertErrorsInCode(r'''
class A {
const A({int x});
}
class B extends A {
const B() : super(0);
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 71,
3),
]);
}
test_functionExpressionInvocation() async {
await assertErrorsInCode('''
main() {
(int x, {int y}) {} (0, 1);
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 31,
6),
]);
}
test_methodInvocation_topLevelFunction() async {
await assertErrorsInCode('''
f({x, y}) {}
main() {
f(0, 1, '2');
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS_COULD_BE_NAMED, 25,
11),
]);
}
}
@reflectiveTest
class ExtraPositionalArgumentsTest extends PubPackageResolutionTest {
test_constConstructor() async {
await assertErrorsInCode(r'''
class A {
const A();
}
main() {
const A(0);
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 43, 3),
]);
}
test_constConstructor_super() async {
await assertErrorsInCode(r'''
class A {
const A();
}
class B extends A {
const B() : super(0);
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 64, 3),
]);
}
test_functionExpressionInvocation() async {
await assertErrorsInCode('''
main() {
(int x) {} (0, 1);
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 22, 6),
]);
}
test_methodInvocation_topLevelFunction() async {
await assertErrorsInCode('''
f() {}
main() {
f(0, 1, '2');
}
''', [
error(CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS, 19, 11),
]);
}
}