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

Side by Side Diff: pkg/analyzer/test/src/dart/sdk/patch_test.dart

Issue 2405383002: Patch imports and function type aliases. Report more errors. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/sdk/patch.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/file_system/file_system.dart'; 6 import 'package:analyzer/file_system/file_system.dart';
7 import 'package:analyzer/file_system/memory_file_system.dart'; 7 import 'package:analyzer/file_system/memory_file_system.dart';
8 import 'package:analyzer/src/dart/sdk/patch.dart'; 8 import 'package:analyzer/src/dart/sdk/patch.dart';
9 import 'package:analyzer/src/dart/sdk/sdk.dart'; 9 import 'package:analyzer/src/dart/sdk/sdk.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 15 matching lines...) Expand all
26 Folder sdkFolder; 26 Folder sdkFolder;
27 FolderBasedDartSdk sdk; 27 FolderBasedDartSdk sdk;
28 28
29 SdkPatcher patcher = new SdkPatcher(); 29 SdkPatcher patcher = new SdkPatcher();
30 RecordingErrorListener listener = new RecordingErrorListener(); 30 RecordingErrorListener listener = new RecordingErrorListener();
31 31
32 void setUp() { 32 void setUp() {
33 sdkFolder = provider.getFolder(_p('/sdk')); 33 sdkFolder = provider.getFolder(_p('/sdk'));
34 } 34 }
35 35
36 test_directive_fail_export() {
37 expect(() {
38 _doTopLevelPatching(
39 r'''
40 import 'a.dart';
41 ''',
42 r'''
43 export 'c.dart';
44 ''');
45 }, throwsArgumentError);
46 }
47
48 test_directive_import() {
49 CompilationUnit unit = _doTopLevelPatching(
50 r'''
51 import 'a.dart';
52 part 'b.dart';
53 int bar() => 0;
54 ''',
55 r'''
56 import 'c.dart';
57 ''');
58 _assertUnitCode(unit,
59 "import 'a.dart'; part 'b.dart'; import 'c.dart'; int bar() => 0;");
60 }
61
36 test_fail_noSuchLibrary() { 62 test_fail_noSuchLibrary() {
37 expect(() { 63 expect(() {
38 _setSdkLibraries('const LIBRARIES = const {};'); 64 _setSdkLibraries('const LIBRARIES = const {};');
39 _createSdk(); 65 _createSdk();
40 File file = provider.newFile(_p('/sdk/lib/test/test.dart'), ''); 66 File file = provider.newFile(_p('/sdk/lib/test/test.dart'), '');
41 Source source = file.createSource(FastUri.parse('dart:test')); 67 Source source = file.createSource(FastUri.parse('dart:test'));
42 CompilationUnit unit = SdkPatcher.parse(source, true, listener); 68 CompilationUnit unit = SdkPatcher.parse(source, true, listener);
43 patcher.patch(sdk, SdkLibraryImpl.VM_PLATFORM, listener, source, unit); 69 patcher.patch(sdk, SdkLibraryImpl.VM_PLATFORM, listener, source, unit);
44 }, throwsArgumentError); 70 }, throwsArgumentError);
45 } 71 }
(...skipping 23 matching lines...) Expand all
69 int _foo1() => 1; 95 int _foo1() => 1;
70 int get _foo2 => 1; 96 int get _foo2 => 1;
71 void set _foo3(int val) {} 97 void set _foo3(int val) {}
72 '''); 98 ''');
73 _assertUnitCode( 99 _assertUnitCode(
74 unit, 100 unit,
75 'int bar() => 2; int _foo1() => 1; ' 101 'int bar() => 2; int _foo1() => 1; '
76 'int get _foo2 => 1; void set _foo3(int val) {}'); 102 'int get _foo2 => 1; void set _foo3(int val) {}');
77 } 103 }
78 104
79 test_topLevel_fail_append_notPrivate() { 105 test_topLevel_fail_topLevelVariable() {
80 expect(() { 106 expect(() {
81 _doTopLevelPatching( 107 _doTopLevelPatching(
82 r''' 108 r'''
83 int foo() => 1; 109 int foo() => 0;
84 ''', 110 ''',
85 r''' 111 r'''
86 int bar() => 2; 112 int _bar;
87 '''); 113 ''');
88 }, throwsArgumentError); 114 }, throwsArgumentError);
89 } 115 }
90 116
91 test_topLevel_fail_noExternalKeyword() { 117 test_topLevel_function_fail_noExternalKeyword() {
92 expect(() { 118 expect(() {
93 _doTopLevelPatching( 119 _doTopLevelPatching(
94 r''' 120 r'''
95 int foo(); 121 int foo();
96 ''', 122 ''',
97 r''' 123 r'''
98 @patch 124 @patch
99 int foo() => 1; 125 int foo() => 1;
100 '''); 126 ''');
101 }, throwsArgumentError); 127 }, throwsArgumentError);
102 } 128 }
103 129
130 test_topLevel_function_fail_notPrivate() {
131 expect(() {
132 _doTopLevelPatching(
133 r'''
134 int foo() => 1;
135 ''',
136 r'''
137 int bar() => 2;
138 ''');
139 }, throwsArgumentError);
140 }
141
142 test_topLevel_functionTypeAlias_append() {
143 CompilationUnit unit = _doTopLevelPatching(
144 r'''
145 int foo() => 0;
146 ''',
147 r'''
148 typedef int _bar();
149 ''');
150 _assertUnitCode(unit, 'int foo() => 0; typedef int _bar();');
151 }
152
153 test_topLevel_functionTypeAlias_fail_hasAnnotation() {
154 expect(() {
155 _doTopLevelPatching(
156 r'''
157 int foo() => 0;
158 ''',
159 r'''
160 @patch
161 typedef int _bar();
162 ''');
163 }, throwsArgumentError);
164 }
165
166 test_topLevel_functionTypeAlias_fail_notPrivate() {
167 expect(() {
168 _doTopLevelPatching(
169 r'''
170 int foo() => 0;
171 ''',
172 r'''
173 typedef int bar();
174 ''');
175 }, throwsArgumentError);
176 }
177
104 test_topLevel_patch_function() { 178 test_topLevel_patch_function() {
105 CompilationUnit unit = _doTopLevelPatching( 179 CompilationUnit unit = _doTopLevelPatching(
106 r''' 180 r'''
107 external int foo(); 181 external int foo();
108 int bar() => 2; 182 int bar() => 2;
109 ''', 183 ''',
110 r''' 184 r'''
111 @patch 185 @patch
112 int foo() => 1; 186 int foo() => 1;
113 '''); 187 ''');
114 _assertUnitCode(unit, 'int foo() => 1; int bar() => 2;'); 188 _assertUnitCode(unit, 'int foo() => 1; int bar() => 2;');
115 } 189 }
116 190
191 test_topLevel_patch_function_blockBody() {
192 CompilationUnit unit = _doTopLevelPatching(
193 r'''
194 external int foo();
195 ''',
196 r'''
197 @patch
198 int foo() {int v = 1; return v + 2;}
199 ''');
200 _assertUnitCode(unit, 'int foo() {int v = 1; return v + 2;}');
201 }
202
117 test_topLevel_patch_getter() { 203 test_topLevel_patch_getter() {
118 CompilationUnit unit = _doTopLevelPatching( 204 CompilationUnit unit = _doTopLevelPatching(
119 r''' 205 r'''
120 external int get foo; 206 external int get foo;
121 int bar() => 2; 207 int bar() => 2;
122 ''', 208 ''',
123 r''' 209 r'''
124 @patch 210 @patch
125 int get foo => 1; 211 int get foo => 1;
126 '''); 212 ''');
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return unit; 253 return unit;
168 } 254 }
169 255
170 String _p(String path) => provider.convertPath(path); 256 String _p(String path) => provider.convertPath(path);
171 257
172 void _setSdkLibraries(String code) { 258 void _setSdkLibraries(String code) {
173 provider.newFile( 259 provider.newFile(
174 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code); 260 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code);
175 } 261 }
176 } 262 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/sdk/patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698