| // 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 '../../generated/resolver_test_case.dart'; |
| |
| main() { |
| defineReflectiveSuite(() { |
| defineReflectiveTests(CanBeNullAfterNullAwareTest); |
| defineReflectiveTests(CanBeNullAfterNullAwareTest_Driver); |
| }); |
| } |
| |
| @reflectiveTest |
| class CanBeNullAfterNullAwareTest extends ResolverTestCase { |
| test_afterCascade() async { |
| assertErrorsInCode(r''' |
| m(x) { |
| x..a?.b.c; |
| } |
| ''', [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); |
| } |
| |
| test_beforeCascade() async { |
| assertErrorsInCode(r''' |
| m(x) { |
| x?.a..m(); |
| } |
| ''', [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); |
| } |
| |
| test_cascadeWithParenthesis() async { |
| assertErrorsInCode(r''' |
| m(x) { |
| (x?.a)..m(); |
| } |
| ''', [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); |
| } |
| |
| test_definedForNull() async { |
| assertNoErrorsInCode(r''' |
| m(x) { |
| x?.a.hashCode; |
| x?.a.runtimeType; |
| x?.a.toString(); |
| x?.b().hashCode; |
| x?.b().runtimeType; |
| x?.b().toString(); |
| } |
| '''); |
| } |
| |
| test_guarded_methodInvocation() async { |
| assertNoErrorsInCode(r''' |
| m(x) { |
| x?.a()?.b(); |
| } |
| '''); |
| } |
| |
| test_guarded_propertyAccess() async { |
| assertNoErrorsInCode(r''' |
| m(x) { |
| x?.a?.b; |
| } |
| '''); |
| } |
| |
| test_methodInvocation() async { |
| assertErrorsInCode(r''' |
| m(x) { |
| x?.a.b(); |
| } |
| ''', [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); |
| } |
| |
| test_multipleInvocations() async { |
| assertErrorsInCode(r''' |
| m(x) { |
| x?.a |
| ..m() |
| ..m(); |
| } |
| ''', [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); |
| } |
| |
| test_parenthesized() async { |
| assertErrorsInCode(r''' |
| m(x) { |
| (x?.a).b; |
| } |
| ''', [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); |
| } |
| |
| test_propertyAccess() async { |
| assertErrorsInCode(r''' |
| m(x) { |
| x?.a.b; |
| } |
| ''', [HintCode.CAN_BE_NULL_AFTER_NULL_AWARE]); |
| } |
| } |
| |
| @reflectiveTest |
| class CanBeNullAfterNullAwareTest_Driver extends CanBeNullAfterNullAwareTest { |
| @override |
| bool get enableNewAnalysisDriver => true; |
| } |