| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:analyzer/src/generated/error.dart'; | 5 import 'package:analyzer/src/generated/error.dart'; |
| 6 import 'package:analyzer/src/generated/source.dart'; | 6 import 'package:analyzer/src/generated/source.dart'; |
| 7 import 'package:analyzer/src/generated/source_io.dart'; | 7 import 'package:analyzer/src/generated/source_io.dart'; |
| 8 | 8 |
| 9 import '../reflective_tests.dart'; | 9 import '../reflective_tests.dart'; |
| 10 import '../utils.dart'; | 10 import '../utils.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // ignore: invalid_assignment | 35 // ignore: invalid_assignment |
| 36 int x = ''; | 36 int x = ''; |
| 37 // ... but no ignore here ... | 37 // ... but no ignore here ... |
| 38 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 38 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 39 '''); | 39 '''); |
| 40 computeLibrarySourceErrors(source); | 40 computeLibrarySourceErrors(source); |
| 41 assertErrors(source, | 41 assertErrors(source, |
| 42 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); | 42 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void test_ignore_first_trailing() { |
| 46 Source source = addSource(''' |
| 47 int x = ''; // ignore: invalid_assignment |
| 48 // ... but no ignore here ... |
| 49 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 50 '''); |
| 51 computeLibrarySourceErrors(source); |
| 52 assertErrors(source, |
| 53 [CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE]); |
| 54 } |
| 55 |
| 56 void test_ignore_only_trailing() { |
| 57 Source source = addSource(''' |
| 58 int x = ''; // ignore: invalid_assignment |
| 59 '''); |
| 60 computeLibrarySourceErrors(source); |
| 61 assertErrors(source, []); |
| 62 } |
| 63 |
| 45 void test_ignore_second() { | 64 void test_ignore_second() { |
| 46 Source source = addSource(''' | 65 Source source = addSource(''' |
| 47 //INVALID_ASSIGNMENT | 66 //INVALID_ASSIGNMENT |
| 48 int x = ''; | 67 int x = ''; |
| 49 // ignore: const_initialized_with_non_constant_value | 68 // ignore: const_initialized_with_non_constant_value |
| 50 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 69 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 51 '''); | 70 '''); |
| 52 computeLibrarySourceErrors(source); | 71 computeLibrarySourceErrors(source); |
| 53 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 72 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 54 } | 73 } |
| 55 | 74 |
| 75 void test_ignore_second_trailing() { |
| 76 Source source = addSource(''' |
| 77 //INVALID_ASSIGNMENT |
| 78 int x = ''; |
| 79 const y = x; // ignore: const_initialized_with_non_constant_value |
| 80 '''); |
| 81 computeLibrarySourceErrors(source); |
| 82 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 83 } |
| 84 |
| 56 void test_invalid_error_code() { | 85 void test_invalid_error_code() { |
| 57 Source source = addSource(''' | 86 Source source = addSource(''' |
| 58 // ignore: right_format_wrong_code | 87 // ignore: right_format_wrong_code |
| 59 int x = ''; | 88 int x = ''; |
| 60 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 89 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 61 '''); | 90 '''); |
| 62 computeLibrarySourceErrors(source); | 91 computeLibrarySourceErrors(source); |
| 63 assertErrors(source, [ | 92 assertErrors(source, [ |
| 64 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 93 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 65 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 94 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void test_multiple_ignores() { | 130 void test_multiple_ignores() { |
| 102 Source source = addSource(''' | 131 Source source = addSource(''' |
| 103 int x = 3; | 132 int x = 3; |
| 104 // ignore: invalid_assignment, const_initialized_with_non_constant_value | 133 // ignore: invalid_assignment, const_initialized_with_non_constant_value |
| 105 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 134 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 106 '''); | 135 '''); |
| 107 computeLibrarySourceErrors(source); | 136 computeLibrarySourceErrors(source); |
| 108 assertErrors(source, []); | 137 assertErrors(source, []); |
| 109 } | 138 } |
| 110 | 139 |
| 140 void test_multiple_ignores_traling() { |
| 141 Source source = addSource(''' |
| 142 int x = 3; |
| 143 const String y = x; // ignore: invalid_assignment, const_initialized_with_non_co
nstant_value |
| 144 '''); |
| 145 computeLibrarySourceErrors(source); |
| 146 assertErrors(source, []); |
| 147 } |
| 148 |
| 111 void test_multiple_ignores_whitespace_variant_1() { | 149 void test_multiple_ignores_whitespace_variant_1() { |
| 112 Source source = addSource(''' | 150 Source source = addSource(''' |
| 113 int x = 3; | 151 int x = 3; |
| 114 //ignore:invalid_assignment,const_initialized_with_non_constant_value | 152 //ignore:invalid_assignment,const_initialized_with_non_constant_value |
| 115 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE | 153 const String y = x; //INVALID_ASSIGNMENT, CONST_INITIALIZED_WITH_NON_CONSTANT_VA
LUE |
| 116 '''); | 154 '''); |
| 117 computeLibrarySourceErrors(source); | 155 computeLibrarySourceErrors(source); |
| 118 assertErrors(source, []); | 156 assertErrors(source, []); |
| 119 } | 157 } |
| 120 | 158 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 int x = ''; //INVALID_ASSIGNMENT | 181 int x = ''; //INVALID_ASSIGNMENT |
| 144 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 182 const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 145 '''); | 183 '''); |
| 146 computeLibrarySourceErrors(source); | 184 computeLibrarySourceErrors(source); |
| 147 assertErrors(source, [ | 185 assertErrors(source, [ |
| 148 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 186 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 149 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 187 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 150 ]); | 188 ]); |
| 151 } | 189 } |
| 152 } | 190 } |
| OLD | NEW |