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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1182303006: Re-enable and add new HTML support (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Move a private constant 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
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 test.src.context.context_test; 5 library test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/src/cancelable_future.dart'; 9 import 'package:analyzer/src/cancelable_future.dart';
10 import 'package:analyzer/src/context/cache.dart'; 10 import 'package:analyzer/src/context/cache.dart';
(...skipping 25 matching lines...) Expand all
36 import 'package:analyzer/src/generated/source.dart'; 36 import 'package:analyzer/src/generated/source.dart';
37 import 'package:analyzer/task/dart.dart'; 37 import 'package:analyzer/task/dart.dart';
38 import 'package:path/path.dart' as pathos; 38 import 'package:path/path.dart' as pathos;
39 import 'package:unittest/unittest.dart'; 39 import 'package:unittest/unittest.dart';
40 import 'package:watcher/src/utils.dart'; 40 import 'package:watcher/src/utils.dart';
41 41
42 import '../../generated/engine_test.dart'; 42 import '../../generated/engine_test.dart';
43 import '../../generated/test_support.dart'; 43 import '../../generated/test_support.dart';
44 import '../../reflective_tests.dart'; 44 import '../../reflective_tests.dart';
45 import 'abstract_context.dart'; 45 import 'abstract_context.dart';
46 import 'package:html/dom.dart' show Document;
46 47
47 main() { 48 main() {
48 groupSep = ' | '; 49 groupSep = ' | ';
49 runReflectiveTests(AnalysisContextImplTest); 50 runReflectiveTests(AnalysisContextImplTest);
50 } 51 }
51 52
52 @reflectiveTest 53 @reflectiveTest
53 class AnalysisContextImplTest extends AbstractContextTest { 54 class AnalysisContextImplTest extends AbstractContextTest {
54 void fail_applyChanges_empty() { 55 void fail_applyChanges_empty() {
55 context.applyChanges(new ChangeSet()); 56 context.applyChanges(new ChangeSet());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 expect(errors.length > 0, isTrue); 153 expect(errors.length > 0, isTrue);
153 } 154 }
154 155
155 void test_computeErrors_dart_some() { 156 void test_computeErrors_dart_some() {
156 Source source = addSource("/lib.dart", "library 'lib';"); 157 Source source = addSource("/lib.dart", "library 'lib';");
157 List<AnalysisError> errors = context.computeErrors(source); 158 List<AnalysisError> errors = context.computeErrors(source);
158 expect(errors, isNotNull); 159 expect(errors, isNotNull);
159 expect(errors.length > 0, isTrue); 160 expect(errors.length > 0, isTrue);
160 } 161 }
161 162
162 void fail_computeErrors_html_none() { 163 void test_computeErrors_html_none() {
163 Source source = addSource("/test.html", "<html></html>"); 164 Source source = addSource("/test.html", "<!DOCTYPE html><html></html>");
164 List<AnalysisError> errors = context.computeErrors(source); 165 List<AnalysisError> errors = context.computeErrors(source);
165 expect(errors, hasLength(0)); 166 expect(errors, hasLength(0));
166 } 167 }
167 168
168 void fail_computeHtmlElement_valid() { 169 void fail_computeHtmlElement_valid() {
169 Source source = addSource("/test.html", "<html></html>"); 170 Source source = addSource("/test.html", "<html></html>");
170 HtmlElement element = context.computeHtmlElement(source); 171 HtmlElement element = context.computeHtmlElement(source);
171 expect(element, isNotNull); 172 expect(element, isNotNull);
172 expect(context.computeHtmlElement(source), same(element)); 173 expect(context.computeHtmlElement(source), same(element));
173 } 174 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 Source source = addSource("/test.html", "<html></html>"); 326 Source source = addSource("/test.html", "<html></html>");
326 AnalysisErrorInfo errorInfo = context.getErrors(source); 327 AnalysisErrorInfo errorInfo = context.getErrors(source);
327 expect(errorInfo, isNotNull); 328 expect(errorInfo, isNotNull);
328 List<AnalysisError> errors = errorInfo.errors; 329 List<AnalysisError> errors = errorInfo.errors;
329 expect(errors, hasLength(0)); 330 expect(errors, hasLength(0));
330 context.computeErrors(source); 331 context.computeErrors(source);
331 errors = errorInfo.errors; 332 errors = errorInfo.errors;
332 expect(errors, hasLength(0)); 333 expect(errors, hasLength(0));
333 } 334 }
334 335
335 void fail_getErrors_html_some() { 336 void test_getErrors_html_some() {
336 Source source = addSource("/test.html", r''' 337 Source source = addSource("/test.html", r'''
337 <html><head> 338 <html><head>
338 <script type='application/dart' src='test.dart'/> 339 <script type='application/dart' src='test.dart'/>
339 </head></html>'''); 340 </head></html>''');
340 AnalysisErrorInfo errorInfo = context.getErrors(source); 341 AnalysisErrorInfo errorInfo = context.getErrors(source);
341 expect(errorInfo, isNotNull); 342 expect(errorInfo, isNotNull);
342 List<AnalysisError> errors = errorInfo.errors; 343 List<AnalysisError> errors = errorInfo.errors;
343 expect(errors, hasLength(0)); 344 expect(errors, hasLength(0));
344 context.computeErrors(source); 345 errors = context.computeErrors(source);
345 errors = errorInfo.errors; 346 expect(errors, hasLength(3));
346 expect(errors, hasLength(1));
347 } 347 }
348 348
349 void fail_getHtmlElement_html() { 349 void fail_getHtmlElement_html() {
350 Source source = addSource("/test.html", "<html></html>"); 350 Source source = addSource("/test.html", "<html></html>");
351 HtmlElement element = context.getHtmlElement(source); 351 HtmlElement element = context.getHtmlElement(source);
352 expect(element, isNull); 352 expect(element, isNull);
353 context.computeHtmlElement(source); 353 context.computeHtmlElement(source);
354 element = context.getHtmlElement(source); 354 element = context.getHtmlElement(source);
355 expect(element, isNotNull); 355 expect(element, isNotNull);
356 } 356 }
357 357
358 void fail_getHtmlFilesReferencing_library() { 358 void test_getHtmlFilesReferencing_library() {
359 Source htmlSource = addSource("/test.html", r''' 359 Source htmlSource = addSource("/test.html", r'''
360 <!DOCTYPE html>
360 <html><head> 361 <html><head>
361 <script type='application/dart' src='test.dart'/> 362 <script type='application/dart' src='test.dart'/>
362 <script type='application/dart' src='test.js'/> 363 <script type='application/dart' src='test.js'/>
363 </head></html>'''); 364 </head></html>''');
364 Source librarySource = addSource("/test.dart", "library lib;"); 365 Source librarySource = addSource("/test.dart", "library lib;");
366 context.computeLibraryElement(librarySource);
365 List<Source> result = context.getHtmlFilesReferencing(librarySource); 367 List<Source> result = context.getHtmlFilesReferencing(librarySource);
366 expect(result, hasLength(0)); 368 expect(result, hasLength(0));
367 context.parseHtmlUnit(htmlSource); 369 context.computeHtmlElement(htmlSource);
368 result = context.getHtmlFilesReferencing(librarySource); 370 result = context.getHtmlFilesReferencing(librarySource);
369 expect(result, hasLength(1)); 371 expect(result, hasLength(1));
370 expect(result[0], htmlSource); 372 expect(result[0], htmlSource);
371 } 373 }
372 374
373 void fail_getHtmlFilesReferencing_part() { 375 void test_getHtmlFilesReferencing_part() {
374 Source htmlSource = addSource("/test.html", r''' 376 Source htmlSource = addSource("/test.html", r'''
377 <!DOCTYPE html>
375 <html><head> 378 <html><head>
376 <script type='application/dart' src='test.dart'/> 379 <script type='application/dart' src='test.dart'/>
377 <script type='application/dart' src='test.js'/> 380 <script type='application/dart' src='test.js'/>
378 </head></html>'''); 381 </head></html>''');
379 Source librarySource = 382 Source librarySource =
380 addSource("/test.dart", "library lib; part 'part.dart';"); 383 addSource("/test.dart", "library lib; part 'part.dart';");
381 Source partSource = addSource("/part.dart", "part of lib;"); 384 Source partSource = addSource("/part.dart", "part of lib;");
382 context.computeLibraryElement(librarySource); 385 context.computeLibraryElement(librarySource);
383 List<Source> result = context.getHtmlFilesReferencing(partSource); 386 List<Source> result = context.getHtmlFilesReferencing(partSource);
384 expect(result, hasLength(0)); 387 expect(result, hasLength(0));
385 context.parseHtmlUnit(htmlSource); 388 context.computeHtmlElement(htmlSource);
386 result = context.getHtmlFilesReferencing(partSource); 389 result = context.getHtmlFilesReferencing(partSource);
387 expect(result, hasLength(1)); 390 expect(result, hasLength(1));
388 expect(result[0], htmlSource); 391 expect(result[0], htmlSource);
389 } 392 }
390 393
391 void fail_getHtmlSources() { 394 void test_getHtmlSources() {
392 List<Source> sources = context.htmlSources; 395 List<Source> sources = context.htmlSources;
393 expect(sources, hasLength(0)); 396 expect(sources, hasLength(0));
394 Source source = addSource("/test.html", ""); 397 Source source = addSource("/test.html", "");
395 context.computeKindOf(source);
396 sources = context.htmlSources; 398 sources = context.htmlSources;
397 expect(sources, hasLength(1)); 399 expect(sources, hasLength(1));
398 expect(sources[0], source); 400 expect(sources[0], source);
399 } 401 }
400 402
401 void fail_getLibrariesReferencedFromHtml() { 403 void test_getLibrariesReferencedFromHtml() {
402 Source htmlSource = addSource("/test.html", r''' 404 Source htmlSource = addSource("/test.html", r'''
405 <!DOCTYPE html>
403 <html><head> 406 <html><head>
404 <script type='application/dart' src='test.dart'/> 407 <script type='application/dart' src='test.dart'/>
405 <script type='application/dart' src='test.js'/> 408 <script type='application/dart' src='test.js'/>
406 </head></html>'''); 409 </head></html>''');
407 Source librarySource = addSource("/test.dart", "library lib;"); 410 Source librarySource = addSource("/test.dart", "library lib;");
408 context.computeLibraryElement(librarySource); 411 context.computeLibraryElement(librarySource);
409 context.parseHtmlUnit(htmlSource); 412 context.computeHtmlElement(htmlSource);
410 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); 413 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource);
411 expect(result, hasLength(1)); 414 expect(result, hasLength(1));
412 expect(result[0], librarySource); 415 expect(result[0], librarySource);
413 } 416 }
414 417
415 void test_getResolvedCompilationUnit_library() { 418 void test_getResolvedCompilationUnit_library() {
416 Source source = addSource("/lib.dart", "library libb;"); 419 Source source = addSource("/lib.dart", "library libb;");
417 LibraryElement library = context.computeLibraryElement(source); 420 LibraryElement library = context.computeLibraryElement(source);
418 context.computeErrors(source); // Force the resolved unit to be built. 421 context.computeErrors(source); // Force the resolved unit to be built.
419 expect(context.getResolvedCompilationUnit(source, library), isNotNull); 422 expect(context.getResolvedCompilationUnit(source, library), isNotNull);
420 context.setContents(source, "library lib;"); 423 context.setContents(source, "library lib;");
421 expect(context.getResolvedCompilationUnit(source, library), isNull); 424 expect(context.getResolvedCompilationUnit(source, library), isNull);
422 } 425 }
423 426
424 void fail_getResolvedHtmlUnit() { 427 void fail_getResolvedHtmlUnit() {
425 Source source = addSource("/test.html", "<html></html>"); 428 Source source = addSource("/test.html", "<html></html>");
426 expect(context.getResolvedHtmlUnit(source), isNull); 429 expect(context.getResolvedHtmlUnit(source), isNull);
427 context.resolveHtmlUnit(source); 430 context.resolveHtmlUnit(source);
428 expect(context.getResolvedHtmlUnit(source), isNotNull); 431 expect(context.getResolvedHtmlUnit(source), isNotNull);
429 } 432 }
430 433
431 void fail_mergeContext() { 434 void fail_mergeContext() {
432 fail("Implement this"); 435 fail("Implement this");
433 } 436 }
434 437
438 void test_parseDocument() {
439 Source source = addSource("/lib.html", "<!DOCTYPE html><html></html>");
440 Document unit = context.parseDocument(source);
441 expect(unit, isNotNull);
442 }
443
435 void fail_parseHtmlUnit_noErrors() { 444 void fail_parseHtmlUnit_noErrors() {
436 Source source = addSource("/lib.html", "<html></html>"); 445 Source source = addSource("/lib.html", "<html></html>");
437 ht.HtmlUnit unit = context.parseHtmlUnit(source); 446 ht.HtmlUnit unit = context.parseHtmlUnit(source);
438 expect(unit, isNotNull); 447 expect(unit, isNotNull);
439 } 448 }
440 449
441 void fail_parseHtmlUnit_resolveDirectives() { 450 void fail_parseHtmlUnit_resolveDirectives() {
442 Source libSource = addSource("/lib.dart", r''' 451 Source libSource = addSource("/lib.dart", r'''
443 library lib; 452 library lib;
444 class ClassA {}'''); 453 class ClassA {}''');
445 Source source = addSource("/lib.html", r''' 454 Source source = addSource("/lib.html", r'''
455 <!DOCTYPE html>
446 <html> 456 <html>
447 <head> 457 <head>
448 <script type='application/dart'> 458 <script type='application/dart'>
449 import 'lib.dart'; 459 import 'lib.dart';
450 ClassA v = null; 460 ClassA v = null;
451 </script> 461 </script>
452 </head> 462 </head>
453 <body> 463 <body>
454 </body> 464 </body>
455 </html>'''); 465 </html>''');
(...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 : super(name, pathos.toUri(name), UriKind.FILE_URI); 2179 : super(name, pathos.toUri(name), UriKind.FILE_URI);
2170 2180
2171 @override 2181 @override
2172 TimestampedData<String> get contents { 2182 TimestampedData<String> get contents {
2173 throw 'Read error'; 2183 throw 'Read error';
2174 } 2184 }
2175 2185
2176 @override 2186 @override
2177 bool exists() => true; 2187 bool exists() => true;
2178 } 2188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698