Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: pkg/analyzer/test/generated/compile_time_error_code_test.dart

Issue 842503003: Enable async support (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library engine.compile_time_error_code_test; 5 library engine.compile_time_error_code_test;
6 6
7 import 'package:analyzer/src/generated/error.dart'; 7 import 'package:analyzer/src/generated/error.dart';
8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
9 import 'package:analyzer/src/generated/source_io.dart'; 9 import 'package:analyzer/src/generated/source_io.dart';
10 import 'package:unittest/unittest.dart' as _ut; 10 import 'package:unittest/unittest.dart' as _ut;
(...skipping 27 matching lines...) Expand all
38 f() { return const C(); }'''); 38 f() { return const C(); }''');
39 resolve(source); 39 resolve(source);
40 assertErrors( 40 assertErrors(
41 source, 41 source,
42 [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]); 42 [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]);
43 verify([source]); 43 verify([source]);
44 } 44 }
45 45
46 void fail_invalidIdentifierInAsync_async() { 46 void fail_invalidIdentifierInAsync_async() {
47 // TODO(brianwilkerson) Report this error. 47 // TODO(brianwilkerson) Report this error.
48 resetWithAsync();
49 Source source = addSource(r''' 48 Source source = addSource(r'''
50 class A { 49 class A {
51 m() async { 50 m() async {
52 int async; 51 int async;
53 } 52 }
54 }'''); 53 }''');
55 resolve(source); 54 resolve(source);
56 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 55 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
57 verify([source]); 56 verify([source]);
58 } 57 }
59 58
60 void fail_invalidIdentifierInAsync_await() { 59 void fail_invalidIdentifierInAsync_await() {
61 // TODO(brianwilkerson) Report this error. 60 // TODO(brianwilkerson) Report this error.
62 resetWithAsync();
63 Source source = addSource(r''' 61 Source source = addSource(r'''
64 class A { 62 class A {
65 m() async { 63 m() async {
66 int await; 64 int await;
67 } 65 }
68 }'''); 66 }''');
69 resolve(source); 67 resolve(source);
70 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 68 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
71 verify([source]); 69 verify([source]);
72 } 70 }
73 71
74 void fail_invalidIdentifierInAsync_yield() { 72 void fail_invalidIdentifierInAsync_yield() {
75 // TODO(brianwilkerson) Report this error. 73 // TODO(brianwilkerson) Report this error.
76 resetWithAsync();
77 Source source = addSource(r''' 74 Source source = addSource(r'''
78 class A { 75 class A {
79 m() async { 76 m() async {
80 int yield; 77 int yield;
81 } 78 }
82 }'''); 79 }''');
83 resolve(source); 80 resolve(source);
84 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]); 81 assertErrors(source, [CompileTimeErrorCode.INVALID_IDENTIFIER_IN_ASYNC]);
85 verify([source]); 82 verify([source]);
86 } 83 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 Source source = addSource(r''' 141 Source source = addSource(r'''
145 '''); 142 ''');
146 resolve(source); 143 resolve(source);
147 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); 144 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]);
148 verify([source]); 145 verify([source]);
149 } 146 }
150 147
151 void fail_yieldEachInNonGenerator_async() { 148 void fail_yieldEachInNonGenerator_async() {
152 // TODO(brianwilkerson) We are currently parsing the yield statement as a 149 // TODO(brianwilkerson) We are currently parsing the yield statement as a
153 // binary expression. 150 // binary expression.
154 resetWithAsync();
155 Source source = addSource(r''' 151 Source source = addSource(r'''
156 f() async { 152 f() async {
157 yield* 0; 153 yield* 0;
158 }'''); 154 }''');
159 resolve(source); 155 resolve(source);
160 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); 156 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]);
161 verify([source]); 157 verify([source]);
162 } 158 }
163 159
164 void fail_yieldEachInNonGenerator_sync() { 160 void fail_yieldEachInNonGenerator_sync() {
165 // TODO(brianwilkerson) We are currently parsing the yield statement as a 161 // TODO(brianwilkerson) We are currently parsing the yield statement as a
166 // binary expression. 162 // binary expression.
167 resetWithAsync();
168 Source source = addSource(r''' 163 Source source = addSource(r'''
169 f() { 164 f() {
170 yield* 0; 165 yield* 0;
171 }'''); 166 }''');
172 resolve(source); 167 resolve(source);
173 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); 168 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]);
174 verify([source]); 169 verify([source]);
175 } 170 }
176 171
177 void fail_yieldInNonGenerator_async() { 172 void fail_yieldInNonGenerator_async() {
178 // TODO(brianwilkerson) We are currently trying to parse the yield statement 173 // TODO(brianwilkerson) We are currently trying to parse the yield statement
179 // as a binary expression. 174 // as a binary expression.
180 resetWithAsync();
181 Source source = addSource(r''' 175 Source source = addSource(r'''
182 f() async { 176 f() async {
183 yield 0; 177 yield 0;
184 }'''); 178 }''');
185 resolve(source); 179 resolve(source);
186 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]); 180 assertErrors(source, [CompileTimeErrorCode.YIELD_IN_NON_GENERATOR]);
187 verify([source]); 181 verify([source]);
188 } 182 }
189 183
190 void fail_yieldInNonGenerator_sync() { 184 void fail_yieldInNonGenerator_sync() {
191 // TODO(brianwilkerson) We are currently trying to parse the yield statement 185 // TODO(brianwilkerson) We are currently trying to parse the yield statement
192 // as a binary expression. 186 // as a binary expression.
193 resetWithAsync();
194 Source source = addSource(r''' 187 Source source = addSource(r'''
195 f() { 188 f() {
196 yield 0; 189 yield 0;
197 }'''); 190 }''');
198 resolve(source); 191 resolve(source);
199 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); 192 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]);
200 verify([source]); 193 verify([source]);
201 } 194 }
202 195
203 void test_accessPrivateEnumField() { 196 void test_accessPrivateEnumField() {
(...skipping 29 matching lines...) Expand all
233 f(list) { 226 f(list) {
234 await for (var e in list) { 227 await for (var e in list) {
235 } 228 }
236 }'''); 229 }''');
237 resolve(source); 230 resolve(source);
238 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]); 231 assertErrors(source, [CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT]);
239 verify([source]); 232 verify([source]);
240 } 233 }
241 234
242 void test_awaitInWrongContext_sync() { 235 void test_awaitInWrongContext_sync() {
243 resetWithAsync();
244 Source source = addSource(r''' 236 Source source = addSource(r'''
245 f(x) { 237 f(x) {
246 return await x; 238 return await x;
247 }'''); 239 }''');
248 resolve(source); 240 resolve(source);
249 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); 241 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]);
250 verify([source]); 242 verify([source]);
251 } 243 }
252 244
253 void test_awaitInWrongContext_syncStar() { 245 void test_awaitInWrongContext_syncStar() {
254 resetWithAsync();
255 Source source = addSource(r''' 246 Source source = addSource(r'''
256 f(x) sync* { 247 f(x) sync* {
257 yield await x; 248 yield await x;
258 }'''); 249 }''');
259 resolve(source); 250 resolve(source);
260 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); 251 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]);
261 verify([source]); 252 verify([source]);
262 } 253 }
263 254
264 void test_builtInIdentifierAsMixinName_classTypeAlias() { 255 void test_builtInIdentifierAsMixinName_classTypeAlias() {
(...skipping 2452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2717 factory B() {} 2708 factory B() {}
2718 }'''); 2709 }''');
2719 resolve(source); 2710 resolve(source);
2720 assertErrors( 2711 assertErrors(
2721 source, 2712 source,
2722 [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); 2713 [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]);
2723 // no verify() call, "B" is not resolved 2714 // no verify() call, "B" is not resolved
2724 } 2715 }
2725 2716
2726 void test_invalidModifierOnConstructor_async() { 2717 void test_invalidModifierOnConstructor_async() {
2727 resetWithAsync();
2728 Source source = addSource(r''' 2718 Source source = addSource(r'''
2729 class A { 2719 class A {
2730 A() async {} 2720 A() async {}
2731 }'''); 2721 }''');
2732 resolve(source); 2722 resolve(source);
2733 assertErrors( 2723 assertErrors(
2734 source, 2724 source,
2735 [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); 2725 [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]);
2736 verify([source]); 2726 verify([source]);
2737 } 2727 }
2738 2728
2739 void test_invalidModifierOnConstructor_asyncStar() { 2729 void test_invalidModifierOnConstructor_asyncStar() {
2740 resetWithAsync();
2741 Source source = addSource(r''' 2730 Source source = addSource(r'''
2742 class A { 2731 class A {
2743 A() async* {} 2732 A() async* {}
2744 }'''); 2733 }''');
2745 resolve(source); 2734 resolve(source);
2746 assertErrors( 2735 assertErrors(
2747 source, 2736 source,
2748 [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); 2737 [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]);
2749 verify([source]); 2738 verify([source]);
2750 } 2739 }
2751 2740
2752 void test_invalidModifierOnConstructor_syncStar() { 2741 void test_invalidModifierOnConstructor_syncStar() {
2753 resetWithAsync();
2754 Source source = addSource(r''' 2742 Source source = addSource(r'''
2755 class A { 2743 class A {
2756 A() sync* {} 2744 A() sync* {}
2757 }'''); 2745 }''');
2758 resolve(source); 2746 resolve(source);
2759 assertErrors( 2747 assertErrors(
2760 source, 2748 source,
2761 [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]); 2749 [CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR]);
2762 verify([source]); 2750 verify([source]);
2763 } 2751 }
2764 2752
2765 void test_invalidModifierOnSetter_member_async() { 2753 void test_invalidModifierOnSetter_member_async() {
2766 resetWithAsync();
2767 Source source = addSource(r''' 2754 Source source = addSource(r'''
2768 class A { 2755 class A {
2769 set x(v) async {} 2756 set x(v) async {}
2770 }'''); 2757 }''');
2771 resolve(source); 2758 resolve(source);
2772 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2759 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2773 verify([source]); 2760 verify([source]);
2774 } 2761 }
2775 2762
2776 void test_invalidModifierOnSetter_member_asyncStar() { 2763 void test_invalidModifierOnSetter_member_asyncStar() {
2777 resetWithAsync();
2778 Source source = addSource(r''' 2764 Source source = addSource(r'''
2779 class A { 2765 class A {
2780 set x(v) async* {} 2766 set x(v) async* {}
2781 }'''); 2767 }''');
2782 resolve(source); 2768 resolve(source);
2783 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2769 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2784 verify([source]); 2770 verify([source]);
2785 } 2771 }
2786 2772
2787 void test_invalidModifierOnSetter_member_syncStar() { 2773 void test_invalidModifierOnSetter_member_syncStar() {
2788 resetWithAsync();
2789 Source source = addSource(r''' 2774 Source source = addSource(r'''
2790 class A { 2775 class A {
2791 set x(v) sync* {} 2776 set x(v) sync* {}
2792 }'''); 2777 }''');
2793 resolve(source); 2778 resolve(source);
2794 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2779 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2795 verify([source]); 2780 verify([source]);
2796 } 2781 }
2797 2782
2798 void test_invalidModifierOnSetter_topLevel_async() { 2783 void test_invalidModifierOnSetter_topLevel_async() {
2799 resetWithAsync();
2800 Source source = addSource("set x(v) async {}"); 2784 Source source = addSource("set x(v) async {}");
2801 resolve(source); 2785 resolve(source);
2802 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2786 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2803 verify([source]); 2787 verify([source]);
2804 } 2788 }
2805 2789
2806 void test_invalidModifierOnSetter_topLevel_asyncStar() { 2790 void test_invalidModifierOnSetter_topLevel_asyncStar() {
2807 resetWithAsync();
2808 Source source = addSource("set x(v) async* {}"); 2791 Source source = addSource("set x(v) async* {}");
2809 resolve(source); 2792 resolve(source);
2810 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2793 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2811 verify([source]); 2794 verify([source]);
2812 } 2795 }
2813 2796
2814 void test_invalidModifierOnSetter_topLevel_syncStar() { 2797 void test_invalidModifierOnSetter_topLevel_syncStar() {
2815 resetWithAsync();
2816 Source source = addSource("set x(v) sync* {}"); 2798 Source source = addSource("set x(v) sync* {}");
2817 resolve(source); 2799 resolve(source);
2818 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]); 2800 assertErrors(source, [CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER]);
2819 verify([source]); 2801 verify([source]);
2820 } 2802 }
2821 2803
2822 void test_invalidReferenceToThis_factoryConstructor() { 2804 void test_invalidReferenceToThis_factoryConstructor() {
2823 Source source = addSource(r''' 2805 Source source = addSource(r'''
2824 class A { 2806 class A {
2825 factory A() { return this; } 2807 factory A() { return this; }
(...skipping 2035 matching lines...) Expand 10 before | Expand all | Expand 10 after
4861 A() => null; 4843 A() => null;
4862 }'''); 4844 }''');
4863 resolve(source); 4845 resolve(source);
4864 assertErrors( 4846 assertErrors(
4865 source, 4847 source,
4866 [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]); 4848 [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]);
4867 verify([source]); 4849 verify([source]);
4868 } 4850 }
4869 4851
4870 void test_returnInGenerator_asyncStar() { 4852 void test_returnInGenerator_asyncStar() {
4871 resetWithAsync();
4872 Source source = addSource(r''' 4853 Source source = addSource(r'''
4873 f() async* { 4854 f() async* {
4874 return 0; 4855 return 0;
4875 }'''); 4856 }''');
4876 resolve(source); 4857 resolve(source);
4877 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); 4858 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]);
4878 verify([source]); 4859 verify([source]);
4879 } 4860 }
4880 4861
4881 void test_returnInGenerator_syncStar() { 4862 void test_returnInGenerator_syncStar() {
4882 resetWithAsync();
4883 Source source = addSource(r''' 4863 Source source = addSource(r'''
4884 f() sync* { 4864 f() sync* {
4885 return 0; 4865 return 0;
4886 }'''); 4866 }''');
4887 resolve(source); 4867 resolve(source);
4888 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]); 4868 assertErrors(source, [CompileTimeErrorCode.RETURN_IN_GENERATOR]);
4889 verify([source]); 4869 verify([source]);
4890 } 4870 }
4891 4871
4892 void test_sharedDeferredPrefix() { 4872 void test_sharedDeferredPrefix() {
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
5469 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); 5449 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]);
5470 verify([source]); 5450 verify([source]);
5471 reset(); 5451 reset();
5472 } 5452 }
5473 5453
5474 void _check_wrongNumberOfParametersForOperator1(String name) { 5454 void _check_wrongNumberOfParametersForOperator1(String name) {
5475 _check_wrongNumberOfParametersForOperator(name, ""); 5455 _check_wrongNumberOfParametersForOperator(name, "");
5476 _check_wrongNumberOfParametersForOperator(name, "a, b"); 5456 _check_wrongNumberOfParametersForOperator(name, "a, b");
5477 } 5457 }
5478 } 5458 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698