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

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

Issue 1427513003: Compute documentation offsets for library, import, and export directive elements (issue 24756) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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/task/dart.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) 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/file_system/memory_file_system.dart'; 9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/src/cancelable_future.dart'; 10 import 'package:analyzer/src/cancelable_future.dart';
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 expect(sources, hasLength(1)); 390 expect(sources, hasLength(1));
391 expect(sources[0], same(libA)); 391 expect(sources[0], same(libA));
392 return pumpEventQueue().then((_) { 392 return pumpEventQueue().then((_) {
393 listener.assertEvent(wereSourcesAdded: true); 393 listener.assertEvent(wereSourcesAdded: true);
394 listener.assertEvent(wereSourcesAdded: true); 394 listener.assertEvent(wereSourcesAdded: true);
395 listener.assertEvent(wereSourcesRemovedOrDeleted: true); 395 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
396 listener.assertNoMoreEvents(); 396 listener.assertNoMoreEvents();
397 }); 397 });
398 } 398 }
399 399
400 void test_computeDocumentationComment_block() { 400 void test_computeDocumentationComment_class_block() {
401 String comment = "/** Comment */"; 401 String comment = "/** Comment */";
402 Source source = addSource( 402 Source source = addSource(
403 "/test.dart", 403 "/test.dart",
404 """ 404 """
405 $comment 405 $comment
406 class A {}"""); 406 class A {}""");
407 LibraryElement libraryElement = context.computeLibraryElement(source); 407 LibraryElement libraryElement = context.computeLibraryElement(source);
408 expect(libraryElement, isNotNull); 408 expect(libraryElement, isNotNull);
409 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 409 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
410 expect(libraryElement, isNotNull); 410 expect(libraryElement, isNotNull);
411 expect(context.computeDocumentationComment(classElement), comment); 411 expect(context.computeDocumentationComment(classElement), comment);
412 } 412 }
413 413
414 void test_computeDocumentationComment_none() { 414 void test_computeDocumentationComment_class_none() {
415 Source source = addSource("/test.dart", "class A {}"); 415 Source source = addSource("/test.dart", "class A {}");
416 LibraryElement libraryElement = context.computeLibraryElement(source); 416 LibraryElement libraryElement = context.computeLibraryElement(source);
417 expect(libraryElement, isNotNull); 417 expect(libraryElement, isNotNull);
418 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 418 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
419 expect(libraryElement, isNotNull); 419 expect(libraryElement, isNotNull);
420 expect(context.computeDocumentationComment(classElement), isNull); 420 expect(context.computeDocumentationComment(classElement), isNull);
421 } 421 }
422 422
423 void test_computeDocumentationComment_null() { 423 void test_computeDocumentationComment_class_singleLine_multiple_EOL_n() {
424 expect(context.computeDocumentationComment(null), isNull);
425 }
426
427 void test_computeDocumentationComment_singleLine_multiple_EOL_n() {
428 String comment = "/// line 1\n/// line 2\n/// line 3\n"; 424 String comment = "/// line 1\n/// line 2\n/// line 3\n";
429 Source source = addSource("/test.dart", "${comment}class A {}"); 425 Source source = addSource("/test.dart", "${comment}class A {}");
430 LibraryElement libraryElement = context.computeLibraryElement(source); 426 LibraryElement libraryElement = context.computeLibraryElement(source);
431 expect(libraryElement, isNotNull); 427 expect(libraryElement, isNotNull);
432 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 428 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
433 expect(libraryElement, isNotNull); 429 expect(libraryElement, isNotNull);
434 String actual = context.computeDocumentationComment(classElement); 430 String actual = context.computeDocumentationComment(classElement);
435 expect(actual, "/// line 1\n/// line 2\n/// line 3"); 431 expect(actual, "/// line 1\n/// line 2\n/// line 3");
436 } 432 }
437 433
438 void test_computeDocumentationComment_singleLine_multiple_EOL_rn() { 434 void test_computeDocumentationComment_class_singleLine_multiple_EOL_rn() {
439 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; 435 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n";
440 Source source = addSource("/test.dart", "${comment}class A {}"); 436 Source source = addSource("/test.dart", "${comment}class A {}");
441 LibraryElement libraryElement = context.computeLibraryElement(source); 437 LibraryElement libraryElement = context.computeLibraryElement(source);
442 expect(libraryElement, isNotNull); 438 expect(libraryElement, isNotNull);
443 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 439 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
444 expect(libraryElement, isNotNull); 440 expect(libraryElement, isNotNull);
445 String actual = context.computeDocumentationComment(classElement); 441 String actual = context.computeDocumentationComment(classElement);
446 expect(actual, "/// line 1\n/// line 2\n/// line 3"); 442 expect(actual, "/// line 1\n/// line 2\n/// line 3");
447 } 443 }
448 444
445 void test_computeDocumentationComment_exportDirective_block() {
446 String comment = '/** Comment */';
447 Source source = addSource(
448 "/test.dart",
449 '''
450 $comment
451 export 'dart:async';
452 ''');
453 LibraryElement libraryElement = context.computeLibraryElement(source);
454 expect(libraryElement, isNotNull);
455 ExportElement exportElement = libraryElement.exports[0];
456 expect(context.computeDocumentationComment(exportElement), comment);
457 }
458
459 void test_computeDocumentationComment_importDirective_block() {
460 String comment = '/** Comment */';
461 Source source = addSource(
462 "/test.dart",
463 '''
464 $comment
465 import 'dart:async';
466 ''');
467 LibraryElement libraryElement = context.computeLibraryElement(source);
468 expect(libraryElement, isNotNull);
469 ImportElement importElement = libraryElement.imports[0];
470 expect(context.computeDocumentationComment(importElement), comment);
471 }
472
473 void test_computeDocumentationComment_libraryDirective_block() {
474 String comment = '/** Comment */';
475 Source source = addSource(
476 "/test.dart",
477 '''
478 $comment
479 library lib;
480 ''');
481 LibraryElement libraryElement = context.computeLibraryElement(source);
482 expect(libraryElement, isNotNull);
483 expect(context.computeDocumentationComment(libraryElement), comment);
484 }
485
486 void test_computeDocumentationComment_null() {
487 expect(context.computeDocumentationComment(null), isNull);
488 }
489
449 void test_computeErrors_dart_none() { 490 void test_computeErrors_dart_none() {
450 Source source = addSource("/lib.dart", "library lib;"); 491 Source source = addSource("/lib.dart", "library lib;");
451 List<AnalysisError> errors = context.computeErrors(source); 492 List<AnalysisError> errors = context.computeErrors(source);
452 expect(errors, hasLength(0)); 493 expect(errors, hasLength(0));
453 } 494 }
454 495
455 void test_computeErrors_dart_part() { 496 void test_computeErrors_dart_part() {
456 Source librarySource = 497 Source librarySource =
457 addSource("/lib.dart", "library lib; part 'part.dart';"); 498 addSource("/lib.dart", "library lib; part 'part.dart';");
458 Source partSource = addSource("/part.dart", "part of 'lib';"); 499 Source partSource = addSource("/part.dart", "part of 'lib';");
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 } 2627 }
2587 } 2628 }
2588 2629
2589 class _AnalysisContextImplTest_test_applyChanges_removeContainer 2630 class _AnalysisContextImplTest_test_applyChanges_removeContainer
2590 implements SourceContainer { 2631 implements SourceContainer {
2591 Source libB; 2632 Source libB;
2592 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); 2633 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB);
2593 @override 2634 @override
2594 bool contains(Source source) => source == libB; 2635 bool contains(Source source) => source == libB;
2595 } 2636 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698