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

Side by Side Diff: pkg/analysis_server/test/analysis_notification_outline_test.dart

Issue 406583002: Use futures uniformly rather than a mix of futures and CPS in tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 test.domain.analysis.notification.outline; 5 library test.domain.analysis.notification.outline;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/computer/computer_outline.dart'; 10 import 'package:analysis_server/src/computer/computer_outline.dart';
(...skipping 10 matching lines...) Expand all
21 group('notification.outline', () { 21 group('notification.outline', () {
22 runReflectiveTests(_AnalysisNotificationOutlineTest); 22 runReflectiveTests(_AnalysisNotificationOutlineTest);
23 }); 23 });
24 } 24 }
25 25
26 26
27 @ReflectiveTestCase() 27 @ReflectiveTestCase()
28 class _AnalysisNotificationOutlineTest extends AbstractAnalysisTest { 28 class _AnalysisNotificationOutlineTest extends AbstractAnalysisTest {
29 Outline outline; 29 Outline outline;
30 30
31 Future prepareOutline(then()) { 31 Future prepareOutline() {
32 addAnalysisSubscription(AnalysisService.OUTLINE, testFile); 32 addAnalysisSubscription(AnalysisService.OUTLINE, testFile);
33 return waitForTasksFinished().then((_) { 33 return waitForTasksFinished();
34 then();
35 });
36 } 34 }
37 35
38 void processNotification(Notification notification) { 36 void processNotification(Notification notification) {
39 if (notification.event == ANALYSIS_OUTLINE) { 37 if (notification.event == ANALYSIS_OUTLINE) {
40 String file = notification.getParameter(FILE); 38 String file = notification.getParameter(FILE);
41 if (file == testFile) { 39 if (file == testFile) {
42 Map<String, Object> json = notification.getParameter(OUTLINE); 40 Map<String, Object> json = notification.getParameter(OUTLINE);
43 outline = new Outline.fromJson(json); 41 outline = new Outline.fromJson(json);
44 } 42 }
45 } 43 }
46 } 44 }
47 45
48 @override 46 @override
49 void setUp() { 47 void setUp() {
50 super.setUp(); 48 super.setUp();
51 createProject(); 49 createProject();
52 } 50 }
53 51
54 test_afterAnalysis() { 52 test_afterAnalysis() {
55 addTestFile(''' 53 addTestFile('''
56 class AAA { 54 class AAA {
57 } 55 }
58 class BBB { 56 class BBB {
59 } 57 }
60 '''); 58 ''');
61 return waitForTasksFinished().then((_) { 59 return waitForTasksFinished().then((_) {
62 expect(outline, isNull); 60 expect(outline, isNull);
63 return prepareOutline(() { 61 return prepareOutline().then((_) {
64 Outline unitOutline = outline; 62 Outline unitOutline = outline;
65 List<Outline> outlines = unitOutline.children; 63 List<Outline> outlines = unitOutline.children;
66 expect(outlines, hasLength(2)); 64 expect(outlines, hasLength(2));
67 }); 65 });
68 }); 66 });
69 } 67 }
70 68
71 test_class() { 69 test_class() {
72 addTestFile(''' 70 addTestFile('''
73 class A { 71 class A {
74 int fa, fb; 72 int fa, fb;
75 String fc; 73 String fc;
76 A(int i, String s); 74 A(int i, String s);
77 A.name(num p); 75 A.name(num p);
78 A._privateName(num p); 76 A._privateName(num p);
79 static String ma(int pa) => null; 77 static String ma(int pa) => null;
80 _mb(int pb); 78 _mb(int pb);
81 String get propA => null; 79 String get propA => null;
82 set propB(int v) {} 80 set propB(int v) {}
83 } 81 }
84 class B { 82 class B {
85 B(int p); 83 B(int p);
86 }"); 84 }");
87 '''); 85 ''');
88 return prepareOutline(() { 86 return prepareOutline().then((_) {
89 Outline unitOutline = outline; 87 Outline unitOutline = outline;
90 List<Outline> topOutlines = unitOutline.children; 88 List<Outline> topOutlines = unitOutline.children;
91 expect(topOutlines, hasLength(2)); 89 expect(topOutlines, hasLength(2));
92 // A 90 // A
93 { 91 {
94 Outline outline_A = topOutlines[0]; 92 Outline outline_A = topOutlines[0];
95 Element element_A = outline_A.element; 93 Element element_A = outline_A.element;
96 expect(element_A.kind, ElementKind.CLASS); 94 expect(element_A.kind, ElementKind.CLASS);
97 expect(element_A.name, "A"); 95 expect(element_A.name, "A");
98 { 96 {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 local_m() {} 272 local_m() {}
275 } 273 }
276 } 274 }
277 f() { 275 f() {
278 local_f1(int i) {} 276 local_f1(int i) {}
279 local_f2(String s) { 277 local_f2(String s) {
280 local_f21(int p) {} 278 local_f21(int p) {}
281 } 279 }
282 } 280 }
283 '''); 281 ''');
284 return prepareOutline(() { 282 return prepareOutline().then((_) {
285 Outline unitOutline = outline; 283 Outline unitOutline = outline;
286 List<Outline> topOutlines = unitOutline.children; 284 List<Outline> topOutlines = unitOutline.children;
287 expect(topOutlines, hasLength(2)); 285 expect(topOutlines, hasLength(2));
288 // A 286 // A
289 { 287 {
290 Outline outline_A = topOutlines[0]; 288 Outline outline_A = topOutlines[0];
291 Element element_A = outline_A.element; 289 Element element_A = outline_A.element;
292 expect(element_A.kind, ElementKind.CLASS); 290 expect(element_A.kind, ElementKind.CLASS);
293 expect(element_A.name, "A"); 291 expect(element_A.name, "A");
294 { 292 {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 }); 420 });
423 } 421 }
424 422
425 test_sourceRange_inClass() { 423 test_sourceRange_inClass() {
426 addTestFile(''' 424 addTestFile('''
427 class A { // leftA 425 class A { // leftA
428 int methodA() {} // endA 426 int methodA() {} // endA
429 int methodB() {} // endB 427 int methodB() {} // endB
430 } 428 }
431 '''); 429 ''');
432 return prepareOutline(() { 430 return prepareOutline().then((_) {
433 Outline unitOutline = outline; 431 Outline unitOutline = outline;
434 List<Outline> outlines = unitOutline.children[0].children; 432 List<Outline> outlines = unitOutline.children[0].children;
435 expect(outlines, hasLength(2)); 433 expect(outlines, hasLength(2));
436 // methodA 434 // methodA
437 { 435 {
438 Outline outline = outlines[0]; 436 Outline outline = outlines[0];
439 Element element = outline.element; 437 Element element = outline.element;
440 expect(element.kind, ElementKind.METHOD); 438 expect(element.kind, ElementKind.METHOD);
441 expect(element.name, "methodA"); 439 expect(element.name, "methodA");
442 { 440 {
(...skipping 19 matching lines...) Expand all
462 }); 460 });
463 } 461 }
464 462
465 test_sourceRange_inClass_inVariableList() { 463 test_sourceRange_inClass_inVariableList() {
466 addTestFile(''' 464 addTestFile('''
467 class A { // leftA 465 class A { // leftA
468 int fieldA, fieldB, fieldC; // marker 466 int fieldA, fieldB, fieldC; // marker
469 int fieldD; // marker2 467 int fieldD; // marker2
470 } 468 }
471 '''); 469 ''');
472 return prepareOutline(() { 470 return prepareOutline().then((_) {
473 Outline unitOutline = outline; 471 Outline unitOutline = outline;
474 List<Outline> outlines = unitOutline.children[0].children; 472 List<Outline> outlines = unitOutline.children[0].children;
475 expect(outlines, hasLength(4)); 473 expect(outlines, hasLength(4));
476 // fieldA 474 // fieldA
477 { 475 {
478 Outline outline = outlines[0]; 476 Outline outline = outlines[0];
479 Element element = outline.element; 477 Element element = outline.element;
480 expect(element.kind, ElementKind.FIELD); 478 expect(element.kind, ElementKind.FIELD);
481 expect(element.name, "fieldA"); 479 expect(element.name, "fieldA");
482 { 480 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 }); 526 });
529 } 527 }
530 528
531 test_sourceRange_inUnit() { 529 test_sourceRange_inUnit() {
532 addTestFile(''' 530 addTestFile('''
533 class A { 531 class A {
534 } // endA 532 } // endA
535 class B { 533 class B {
536 } // endB 534 } // endB
537 '''); 535 ''');
538 return prepareOutline(() { 536 return prepareOutline().then((_) {
539 Outline unitOutline = outline; 537 Outline unitOutline = outline;
540 List<Outline> topOutlines = unitOutline.children; 538 List<Outline> topOutlines = unitOutline.children;
541 expect(topOutlines, hasLength(2)); 539 expect(topOutlines, hasLength(2));
542 // A 540 // A
543 { 541 {
544 Outline outline = topOutlines[0]; 542 Outline outline = topOutlines[0];
545 Element element = outline.element; 543 Element element = outline.element;
546 expect(element.kind, ElementKind.CLASS); 544 expect(element.kind, ElementKind.CLASS);
547 expect(element.name, "A"); 545 expect(element.name, "A");
548 { 546 {
(...skipping 17 matching lines...) Expand all
566 } 564 }
567 } 565 }
568 }); 566 });
569 } 567 }
570 568
571 test_sourceRange_inUnit_inVariableList() { 569 test_sourceRange_inUnit_inVariableList() {
572 addTestFile(''' 570 addTestFile('''
573 int fieldA, fieldB, fieldC; // marker 571 int fieldA, fieldB, fieldC; // marker
574 int fieldD; // marker2 572 int fieldD; // marker2
575 '''); 573 ''');
576 return prepareOutline(() { 574 return prepareOutline().then((_) {
577 Outline unitOutline = outline; 575 Outline unitOutline = outline;
578 List<Outline> outlines = unitOutline.children; 576 List<Outline> outlines = unitOutline.children;
579 expect(outlines, hasLength(4)); 577 expect(outlines, hasLength(4));
580 // fieldA 578 // fieldA
581 { 579 {
582 Outline outline = outlines[0]; 580 Outline outline = outlines[0];
583 Element element = outline.element; 581 Element element = outline.element;
584 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); 582 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE);
585 expect(element.name, "fieldA"); 583 expect(element.name, "fieldA");
586 { 584 {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 typedef String FTA(int i, String s); 635 typedef String FTA(int i, String s);
638 typedef FTB(int p); 636 typedef FTB(int p);
639 class A {} 637 class A {}
640 class B {} 638 class B {}
641 class CTA = A with B; 639 class CTA = A with B;
642 String fA(int i, String s) => null; 640 String fA(int i, String s) => null;
643 fB(int p) => null; 641 fB(int p) => null;
644 String get propA => null; 642 String get propA => null;
645 set propB(int v) {} 643 set propB(int v) {}
646 '''); 644 ''');
647 return prepareOutline(() { 645 return prepareOutline().then((_) {
648 Outline unitOutline = outline; 646 Outline unitOutline = outline;
649 List<Outline> topOutlines = unitOutline.children; 647 List<Outline> topOutlines = unitOutline.children;
650 expect(topOutlines, hasLength(9)); 648 expect(topOutlines, hasLength(9));
651 // FTA 649 // FTA
652 { 650 {
653 Outline outline = topOutlines[0]; 651 Outline outline = topOutlines[0];
654 Element element = outline.element; 652 Element element = outline.element;
655 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); 653 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS);
656 expect(element.name, "FTA"); 654 expect(element.name, "FTA");
657 { 655 {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 Location location = element.location; 740 Location location = element.location;
743 expect(location.offset, testCode.indexOf("propB(int v) {}")); 741 expect(location.offset, testCode.indexOf("propB(int v) {}"));
744 expect(location.length, "propB".length); 742 expect(location.length, "propB".length);
745 } 743 }
746 expect(element.parameters, "(int v)"); 744 expect(element.parameters, "(int v)");
747 expect(element.returnType, ""); 745 expect(element.returnType, "");
748 } 746 }
749 }); 747 });
750 } 748 }
751 } 749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698