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

Side by Side Diff: pkg/analyzer/test/src/task/html_test.dart

Issue 1193143002: Next steps toward HTML support (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 years, 6 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/test/src/task/dart_test.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.task.html_test; 5 library test.src.task.html_test;
6 6
7 import 'package:analyzer/src/generated/source.dart'; 7 import 'package:analyzer/src/generated/source.dart';
8 import 'package:analyzer/src/task/html.dart'; 8 import 'package:analyzer/src/task/html.dart';
9 import 'package:analyzer/task/html.dart'; 9 import 'package:analyzer/task/html.dart';
10 import 'package:analyzer/task/model.dart'; 10 import 'package:analyzer/task/model.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 import '../../reflective_tests.dart'; 13 import '../../reflective_tests.dart';
14 import '../context/abstract_context.dart'; 14 import '../context/abstract_context.dart';
15 15
16 main() { 16 main() {
17 groupSep = ' | '; 17 groupSep = ' | ';
18 runReflectiveTests(DartScriptsTaskTest);
18 runReflectiveTests(HtmlErrorsTaskTest); 19 runReflectiveTests(HtmlErrorsTaskTest);
19 runReflectiveTests(ParseHtmlTaskTest); 20 runReflectiveTests(ParseHtmlTaskTest);
20 runReflectiveTests(ReferencedLibrariesTaskTest);
21 } 21 }
22 22
23 @reflectiveTest 23 @reflectiveTest
24 class HtmlErrorsTaskTest extends AbstractContextTest { 24 class DartScriptsTaskTest extends AbstractContextTest {
25 test_buildInputs() { 25 test_buildInputs() {
26 Source source = newSource('/test.html'); 26 Source source = newSource('/test.html');
27 Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source); 27 Map<String, TaskInput> inputs = DartScriptsTask.buildInputs(source);
28 expect(inputs, isNotNull); 28 expect(inputs, isNotNull);
29 expect( 29 expect(inputs.keys, unorderedEquals([DartScriptsTask.DOCUMENT_INPUT]));
30 inputs.keys, unorderedEquals([HtmlErrorsTask.DOCUMENT_ERRORS_INPUT]));
31 } 30 }
32 31
33 test_constructor() { 32 test_constructor() {
34 Source source = newSource('/test.html'); 33 Source source = newSource('/test.html');
35 HtmlErrorsTask task = new HtmlErrorsTask(context, source); 34 DartScriptsTask task = new DartScriptsTask(context, source);
36 expect(task, isNotNull); 35 expect(task, isNotNull);
37 expect(task.context, context); 36 expect(task.context, context);
38 expect(task.target, source); 37 expect(task.target, source);
39 } 38 }
40 39
41 test_createTask() { 40 test_createTask() {
42 Source source = newSource('/test.html'); 41 Source source = newSource('/test.html');
43 HtmlErrorsTask task = HtmlErrorsTask.createTask(context, source); 42 DartScriptsTask task = DartScriptsTask.createTask(context, source);
44 expect(task, isNotNull); 43 expect(task, isNotNull);
45 expect(task.context, context); 44 expect(task.context, context);
46 expect(task.target, source); 45 expect(task.target, source);
47 } 46 }
48 47
49 test_description() { 48 test_description() {
50 Source source = newSource('/test.html'); 49 Source source = newSource('/test.html');
51 HtmlErrorsTask task = new HtmlErrorsTask(null, source); 50 DartScriptsTask task = new DartScriptsTask(null, source);
52 expect(task.description, isNotNull); 51 expect(task.description, isNotNull);
53 } 52 }
54 53
55 test_descriptor() { 54 test_descriptor() {
56 TaskDescriptor descriptor = HtmlErrorsTask.DESCRIPTOR; 55 TaskDescriptor descriptor = DartScriptsTask.DESCRIPTOR;
57 expect(descriptor, isNotNull); 56 expect(descriptor, isNotNull);
58 } 57 }
59 58
60 test_perform() { 59 void test_perform_embedded_source() {
60 String content = r'''
61 void buttonPressed() {}
62 ''';
63 AnalysisTarget target = newSource('/test.html', '''
64 <!DOCTYPE html>
65 <html>
66 <head>
67 <script type='application/dart'>$content</script>
68 </head>
69 <body>
70 </body>
71 </html>''');
72 computeResult(target, REFERENCED_LIBRARIES);
73 expect(task, new isInstanceOf<DartScriptsTask>());
74 expect(outputs[REFERENCED_LIBRARIES], hasLength(0));
75 expect(outputs[DART_SCRIPTS], hasLength(1));
76 DartScript script = outputs[DART_SCRIPTS][0];
77 expect(script.fragments, hasLength(1));
78 ScriptFragment fragment = script.fragments[0];
79 expect(fragment.content, content);
80 }
81
82 void test_perform_empty_source_reference() {
61 AnalysisTarget target = newSource('/test.html', r''' 83 AnalysisTarget target = newSource('/test.html', r'''
62 <!DOCTYPE html> 84 <!DOCTYPE html>
63 <html> 85 <html>
86 <head>
87 <script type='application/dart' src=''/>
88 </head>
89 <body>
90 </body>
91 </html>''');
92 computeResult(target, REFERENCED_LIBRARIES);
93 expect(task, new isInstanceOf<DartScriptsTask>());
94 expect(outputs[REFERENCED_LIBRARIES], hasLength(0));
95 expect(outputs[DART_SCRIPTS], hasLength(0));
96 }
97
98 void test_perform_invalid_source_reference() {
99 AnalysisTarget target = newSource('/test.html', r'''
100 <!DOCTYPE html>
101 <html>
102 <head>
103 <script type='application/dart' src='an;invalid:[]uri'/>
104 </head>
105 <body>
106 </body>
107 </html>''');
108 computeResult(target, REFERENCED_LIBRARIES);
109 expect(task, new isInstanceOf<DartScriptsTask>());
110 expect(outputs[REFERENCED_LIBRARIES], hasLength(0));
111 expect(outputs[DART_SCRIPTS], hasLength(0));
112 }
113
114 void test_perform_non_existing_source_reference() {
115 AnalysisTarget target = newSource('/test.html', r'''
116 <!DOCTYPE html>
117 <html>
118 <head>
119 <script type='application/dart' src='does/not/exist.dart'/>
120 </head>
121 <body>
122 </body>
123 </html>''');
124 computeResult(target, REFERENCED_LIBRARIES);
125 expect(task, new isInstanceOf<DartScriptsTask>());
126 expect(outputs[REFERENCED_LIBRARIES], hasLength(1));
127 expect(outputs[DART_SCRIPTS], hasLength(0));
128 }
129
130 test_perform_none() {
131 AnalysisTarget target = newSource('/test.html', r'''
132 <!DOCTYPE html>
133 <html>
64 <head> 134 <head>
65 <title>test page</title> 135 <title>test page</title>
66 </head> 136 </head>
67 <body> 137 <body>
68 Test 138 Test
69 </body> 139 </body>
70 </html> 140 </html>
71 '''); 141 ''');
72 computeResult(target, HTML_ERRORS); 142 computeResult(target, REFERENCED_LIBRARIES);
73 expect(task, new isInstanceOf<HtmlErrorsTask>()); 143 expect(task, new isInstanceOf<DartScriptsTask>());
74 expect(outputs[HTML_ERRORS], isEmpty); 144 expect(outputs[REFERENCED_LIBRARIES], hasLength(0));
145 expect(outputs[DART_SCRIPTS], hasLength(0));
146 }
147
148 void test_perform_referenced_source() {
149 AnalysisTarget target = newSource('/test.html', r'''
150 <!DOCTYPE html>
151 <html>
152 <head>
153 <script type='application/dart' src='test.dart'/>
154 </head>
155 <body>
156 </body>
157 </html>''');
158 computeResult(target, REFERENCED_LIBRARIES);
159 expect(task, new isInstanceOf<DartScriptsTask>());
160 expect(outputs[REFERENCED_LIBRARIES], hasLength(1));
161 expect(outputs[DART_SCRIPTS], hasLength(0));
75 } 162 }
76 } 163 }
77 164
78 @reflectiveTest 165 @reflectiveTest
79 class ParseHtmlTaskTest extends AbstractContextTest { 166 class HtmlErrorsTaskTest extends AbstractContextTest {
80 test_buildInputs() { 167 test_buildInputs() {
81 Source source = newSource('/test.html'); 168 Source source = newSource('/test.html');
82 Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source); 169 Map<String, TaskInput> inputs = HtmlErrorsTask.buildInputs(source);
83 expect(inputs, isNotNull); 170 expect(inputs, isNotNull);
84 expect(inputs.keys, unorderedEquals([ParseHtmlTask.CONTENT_INPUT_NAME])); 171 expect(inputs.keys, unorderedEquals([
172 HtmlErrorsTask.DART_ERRORS_INPUT,
173 HtmlErrorsTask.DOCUMENT_ERRORS_INPUT
174 ]));
85 } 175 }
86 176
87 test_constructor() { 177 test_constructor() {
88 Source source = newSource('/test.html'); 178 Source source = newSource('/test.html');
89 ParseHtmlTask task = new ParseHtmlTask(context, source); 179 HtmlErrorsTask task = new HtmlErrorsTask(context, source);
90 expect(task, isNotNull); 180 expect(task, isNotNull);
91 expect(task.context, context); 181 expect(task.context, context);
92 expect(task.target, source); 182 expect(task.target, source);
93 } 183 }
94 184
95 test_createTask() { 185 test_createTask() {
96 Source source = newSource('/test.html'); 186 Source source = newSource('/test.html');
97 ParseHtmlTask task = ParseHtmlTask.createTask(context, source); 187 HtmlErrorsTask task = HtmlErrorsTask.createTask(context, source);
98 expect(task, isNotNull); 188 expect(task, isNotNull);
99 expect(task.context, context); 189 expect(task.context, context);
100 expect(task.target, source); 190 expect(task.target, source);
101 } 191 }
102 192
103 test_description() { 193 test_description() {
104 Source source = newSource('/test.html'); 194 Source source = newSource('/test.html');
105 ParseHtmlTask task = new ParseHtmlTask(null, source); 195 HtmlErrorsTask task = new HtmlErrorsTask(null, source);
106 expect(task.description, isNotNull); 196 expect(task.description, isNotNull);
107 } 197 }
108 198
109 test_descriptor() { 199 test_descriptor() {
110 TaskDescriptor descriptor = ParseHtmlTask.DESCRIPTOR; 200 TaskDescriptor descriptor = HtmlErrorsTask.DESCRIPTOR;
111 expect(descriptor, isNotNull); 201 expect(descriptor, isNotNull);
112 } 202 }
113 203
114 test_perform() { 204 test_perform_dartErrors() {
205 AnalysisTarget target = newSource('/test.html', r'''
206 <!DOCTYPE html>
207 <html>
208 <head>
209 <title>test page</title>
210 <script type='application/dart'>
211 void buttonPressed() {
212 </script>
213 </head>
214 <body>Test</body>
215 </html>
216 ''');
217 computeResult(target, HTML_ERRORS);
218 expect(task, new isInstanceOf<HtmlErrorsTask>());
219 expect(outputs[HTML_ERRORS], hasLength(1));
220 }
221
222 test_perform_htmlErrors() {
223 AnalysisTarget target = newSource('/test.html', r'''
224 <html>
225 <head>
226 <title>test page</title>
227 </head>
228 <body>
229 Test
230 </body>
231 </html>
232 ''');
233 computeResult(target, HTML_ERRORS);
234 expect(task, new isInstanceOf<HtmlErrorsTask>());
235 expect(outputs[HTML_ERRORS], hasLength(1));
236 }
237
238 test_perform_noErrors() {
115 AnalysisTarget target = newSource('/test.html', r''' 239 AnalysisTarget target = newSource('/test.html', r'''
116 <!DOCTYPE html> 240 <!DOCTYPE html>
117 <html> 241 <html>
118 <head> 242 <head>
119 <title>test page</title> 243 <title>test page</title>
120 </head> 244 </head>
121 <body> 245 <body>
122 <h1 Test> 246 Test
123 </body> 247 </body>
124 </html> 248 </html>
125 '''); 249 ''');
126 computeResult(target, HTML_DOCUMENT); 250 computeResult(target, HTML_ERRORS);
127 expect(task, new isInstanceOf<ParseHtmlTask>()); 251 expect(task, new isInstanceOf<HtmlErrorsTask>());
128 expect(outputs[HTML_DOCUMENT], isNotNull); 252 expect(outputs[HTML_ERRORS], isEmpty);
129 expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty);
130 } 253 }
131 } 254 }
132 255
133 @reflectiveTest 256 @reflectiveTest
134 class ReferencedLibrariesTaskTest extends AbstractContextTest { 257 class ParseHtmlTaskTest extends AbstractContextTest {
135 test_buildInputs() { 258 test_buildInputs() {
136 Source source = newSource('/test.html'); 259 Source source = newSource('/test.html');
137 Map<String, TaskInput> inputs = ReferencedLibrariesTask.buildInputs(source); 260 Map<String, TaskInput> inputs = ParseHtmlTask.buildInputs(source);
138 expect(inputs, isNotNull); 261 expect(inputs, isNotNull);
139 expect( 262 expect(inputs.keys, unorderedEquals([ParseHtmlTask.CONTENT_INPUT_NAME]));
140 inputs.keys, unorderedEquals([ReferencedLibrariesTask.DOCUMENT_INPUT]));
141 } 263 }
142 264
143 test_constructor() { 265 test_constructor() {
144 Source source = newSource('/test.html'); 266 Source source = newSource('/test.html');
145 ReferencedLibrariesTask task = new ReferencedLibrariesTask(context, source); 267 ParseHtmlTask task = new ParseHtmlTask(context, source);
146 expect(task, isNotNull); 268 expect(task, isNotNull);
147 expect(task.context, context); 269 expect(task.context, context);
148 expect(task.target, source); 270 expect(task.target, source);
149 } 271 }
150 272
151 test_createTask() { 273 test_createTask() {
152 Source source = newSource('/test.html'); 274 Source source = newSource('/test.html');
153 ReferencedLibrariesTask task = 275 ParseHtmlTask task = ParseHtmlTask.createTask(context, source);
154 ReferencedLibrariesTask.createTask(context, source);
155 expect(task, isNotNull); 276 expect(task, isNotNull);
156 expect(task.context, context); 277 expect(task.context, context);
157 expect(task.target, source); 278 expect(task.target, source);
158 } 279 }
159 280
160 test_description() { 281 test_description() {
161 Source source = newSource('/test.html'); 282 Source source = newSource('/test.html');
162 ReferencedLibrariesTask task = new ReferencedLibrariesTask(null, source); 283 ParseHtmlTask task = new ParseHtmlTask(null, source);
163 expect(task.description, isNotNull); 284 expect(task.description, isNotNull);
164 } 285 }
165 286
166 test_descriptor() { 287 test_descriptor() {
167 TaskDescriptor descriptor = ReferencedLibrariesTask.DESCRIPTOR; 288 TaskDescriptor descriptor = ParseHtmlTask.DESCRIPTOR;
168 expect(descriptor, isNotNull); 289 expect(descriptor, isNotNull);
169 } 290 }
170 291
171 void test_perform_embedded_source() { 292 test_perform() {
172 AnalysisTarget target = newSource('/test.html', r''' 293 AnalysisTarget target = newSource('/test.html', r'''
173 <!DOCTYPE html> 294 <!DOCTYPE html>
174 <html> 295 <html>
175 <head>
176 <script type='application/dart'>
177 void buttonPressed() {}
178 </script>
179 </head>
180 <body>
181 </body>
182 </html>''');
183 computeResult(target, REFERENCED_LIBRARIES);
184 expect(task, new isInstanceOf<ReferencedLibrariesTask>());
185 expect(outputs[REFERENCED_LIBRARIES], hasLength(0));
186 }
187
188 void test_perform_empty_source_reference() {
189 AnalysisTarget target = newSource('/test.html', r'''
190 <!DOCTYPE html>
191 <html>
192 <head>
193 <script type='application/dart' src=''/>
194 </head>
195 <body>
196 </body>
197 </html>''');
198 computeResult(target, REFERENCED_LIBRARIES);
199 expect(task, new isInstanceOf<ReferencedLibrariesTask>());
200 expect(outputs[REFERENCED_LIBRARIES], hasLength(0));
201 }
202
203 void test_perform_invalid_source_reference() {
204 AnalysisTarget target = newSource('/test.html', r'''
205 <!DOCTYPE html>
206 <html>
207 <head>
208 <script type='application/dart' src='an;invalid:[]uri'/>
209 </head>
210 <body>
211 </body>
212 </html>''');
213 computeResult(target, REFERENCED_LIBRARIES);
214 expect(task, new isInstanceOf<ReferencedLibrariesTask>());
215 expect(outputs[REFERENCED_LIBRARIES], hasLength(0));
216 }
217
218 void test_perform_non_existing_source_reference() {
219 AnalysisTarget target = newSource('/test.html', r'''
220 <!DOCTYPE html>
221 <html>
222 <head>
223 <script type='application/dart' src='does/not/exist.dart'/>
224 </head>
225 <body>
226 </body>
227 </html>''');
228 computeResult(target, REFERENCED_LIBRARIES);
229 expect(task, new isInstanceOf<ReferencedLibrariesTask>());
230 expect(outputs[REFERENCED_LIBRARIES], hasLength(1));
231 }
232
233 test_perform_none() {
234 AnalysisTarget target = newSource('/test.html', r'''
235 <!DOCTYPE html>
236 <html>
237 <head> 296 <head>
238 <title>test page</title> 297 <title>test page</title>
239 </head> 298 </head>
240 <body> 299 <body>
241 Test 300 <h1 Test>
242 </body> 301 </body>
243 </html> 302 </html>
244 '''); 303 ''');
245 computeResult(target, REFERENCED_LIBRARIES); 304 computeResult(target, HTML_DOCUMENT);
246 expect(task, new isInstanceOf<ReferencedLibrariesTask>()); 305 expect(task, new isInstanceOf<ParseHtmlTask>());
247 expect(outputs[REFERENCED_LIBRARIES], isEmpty); 306 expect(outputs[HTML_DOCUMENT], isNotNull);
248 } 307 expect(outputs[HTML_DOCUMENT_ERRORS], isNotEmpty);
249
250 void test_perform_referenced_source() {
251 AnalysisTarget target = newSource('/test.html', r'''
252 <!DOCTYPE html>
253 <html>
254 <head>
255 <script type='application/dart' src='test.dart'/>
256 </head>
257 <body>
258 </body>
259 </html>''');
260 computeResult(target, REFERENCED_LIBRARIES);
261 expect(task, new isInstanceOf<ReferencedLibrariesTask>());
262 expect(outputs[REFERENCED_LIBRARIES], hasLength(1));
263 } 308 }
264 } 309 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/task/dart_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698