| OLD | NEW |
| 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.analysis.notification.outline; | 5 library test.analysis.notification.outline; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return prepareOutline().then((_) { | 53 return prepareOutline().then((_) { |
| 54 Outline unitOutline = outline; | 54 Outline unitOutline = outline; |
| 55 List<Outline> outlines = unitOutline.children; | 55 List<Outline> outlines = unitOutline.children; |
| 56 expect(outlines, hasLength(2)); | 56 expect(outlines, hasLength(2)); |
| 57 }); | 57 }); |
| 58 }); | 58 }); |
| 59 } | 59 } |
| 60 | 60 |
| 61 test_class() { | 61 test_class() { |
| 62 addTestFile(''' | 62 addTestFile(''' |
| 63 class A { | 63 class A<K, V> { |
| 64 int fa, fb; | 64 int fa, fb; |
| 65 String fc; | 65 String fc; |
| 66 A(int i, String s); | 66 A(int i, String s); |
| 67 A.name(num p); | 67 A.name(num p); |
| 68 A._privateName(num p); | 68 A._privateName(num p); |
| 69 static String ma(int pa) => null; | 69 static String ma(int pa) => null; |
| 70 _mb(int pb); | 70 _mb(int pb); |
| 71 String get propA => null; | 71 String get propA => null; |
| 72 set propB(int v) {} | 72 set propB(int v) {} |
| 73 } | 73 } |
| 74 class B { | 74 class B { |
| 75 B(int p); | 75 B(int p); |
| 76 }"); | 76 }"); |
| 77 '''); | 77 '''); |
| 78 return prepareOutline().then((_) { | 78 return prepareOutline().then((_) { |
| 79 Outline unitOutline = outline; | 79 Outline unitOutline = outline; |
| 80 List<Outline> topOutlines = unitOutline.children; | 80 List<Outline> topOutlines = unitOutline.children; |
| 81 expect(topOutlines, hasLength(2)); | 81 expect(topOutlines, hasLength(2)); |
| 82 // A | 82 // A |
| 83 { | 83 { |
| 84 Outline outline_A = topOutlines[0]; | 84 Outline outline_A = topOutlines[0]; |
| 85 Element element_A = outline_A.element; | 85 Element element_A = outline_A.element; |
| 86 expect(element_A.kind, ElementKind.CLASS); | 86 expect(element_A.kind, ElementKind.CLASS); |
| 87 expect(element_A.name, "A"); | 87 expect(element_A.name, "A"); |
| 88 expect(element_A.typeParameters, "<K, V>"); |
| 88 { | 89 { |
| 89 Location location = element_A.location; | 90 Location location = element_A.location; |
| 90 expect(location.offset, testCode.indexOf("A {")); | 91 expect(location.offset, testCode.indexOf("A<K, V> {")); |
| 91 expect(location.length, 1); | 92 expect(location.length, 1); |
| 92 } | 93 } |
| 93 expect(element_A.parameters, null); | 94 expect(element_A.parameters, null); |
| 94 expect(element_A.returnType, null); | 95 expect(element_A.returnType, null); |
| 95 // A children | 96 // A children |
| 96 List<Outline> outlines_A = outline_A.children; | 97 List<Outline> outlines_A = outline_A.children; |
| 97 expect(outlines_A, hasLength(10)); | 98 expect(outlines_A, hasLength(10)); |
| 98 { | 99 { |
| 99 Outline outline = outlines_A[0]; | 100 Outline outline = outlines_A[0]; |
| 100 Element element = outline.element; | 101 Element element = outline.element; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 expect(element.parameters, "(int v)"); | 221 expect(element.parameters, "(int v)"); |
| 221 expect(element.returnType, ""); | 222 expect(element.returnType, ""); |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 // B | 225 // B |
| 225 { | 226 { |
| 226 Outline outline_B = topOutlines[1]; | 227 Outline outline_B = topOutlines[1]; |
| 227 Element element_B = outline_B.element; | 228 Element element_B = outline_B.element; |
| 228 expect(element_B.kind, ElementKind.CLASS); | 229 expect(element_B.kind, ElementKind.CLASS); |
| 229 expect(element_B.name, "B"); | 230 expect(element_B.name, "B"); |
| 231 expect(element_B.typeParameters, isNull); |
| 230 { | 232 { |
| 231 Location location = element_B.location; | 233 Location location = element_B.location; |
| 232 expect(location.offset, testCode.indexOf("B {")); | 234 expect(location.offset, testCode.indexOf("B {")); |
| 233 expect(location.length, 1); | 235 expect(location.length, 1); |
| 234 } | 236 } |
| 235 expect(element_B.parameters, null); | 237 expect(element_B.parameters, null); |
| 236 expect(element_B.returnType, null); | 238 expect(element_B.returnType, null); |
| 237 // B children | 239 // B children |
| 238 List<Outline> outlines_B = outline_B.children; | 240 List<Outline> outlines_B = outline_B.children; |
| 239 expect(outlines_B, hasLength(1)); | 241 expect(outlines_B, hasLength(1)); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 int end = testCode.indexOf(" // marker2"); | 672 int end = testCode.indexOf(" // marker2"); |
| 671 expect(outline.offset, offset); | 673 expect(outline.offset, offset); |
| 672 expect(outline.length, end - offset); | 674 expect(outline.length, end - offset); |
| 673 } | 675 } |
| 674 } | 676 } |
| 675 }); | 677 }); |
| 676 } | 678 } |
| 677 | 679 |
| 678 test_topLevel() { | 680 test_topLevel() { |
| 679 addTestFile(''' | 681 addTestFile(''' |
| 680 typedef String FTA(int i, String s); | 682 typedef String FTA<K, V>(int i, String s); |
| 681 typedef FTB(int p); | 683 typedef FTB(int p); |
| 682 class A {} | 684 class A<T> {} |
| 683 class B {} | 685 class B {} |
| 684 class CTA = A with B; | 686 class CTA<T> = A<T> with B; |
| 687 class CTB = A with B; |
| 685 String fA(int i, String s) => null; | 688 String fA(int i, String s) => null; |
| 686 fB(int p) => null; | 689 fB(int p) => null; |
| 687 String get propA => null; | 690 String get propA => null; |
| 688 set propB(int v) {} | 691 set propB(int v) {} |
| 689 '''); | 692 '''); |
| 690 return prepareOutline().then((_) { | 693 return prepareOutline().then((_) { |
| 691 Outline unitOutline = outline; | 694 Outline unitOutline = outline; |
| 692 List<Outline> topOutlines = unitOutline.children; | 695 List<Outline> topOutlines = unitOutline.children; |
| 693 expect(topOutlines, hasLength(9)); | 696 expect(topOutlines, hasLength(10)); |
| 694 // FTA | 697 // FTA |
| 695 { | 698 { |
| 696 Outline outline = topOutlines[0]; | 699 Outline outline = topOutlines[0]; |
| 697 Element element = outline.element; | 700 Element element = outline.element; |
| 698 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); | 701 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); |
| 699 expect(element.name, "FTA"); | 702 expect(element.name, "FTA"); |
| 703 expect(element.typeParameters, "<K, V>"); |
| 700 { | 704 { |
| 701 Location location = element.location; | 705 Location location = element.location; |
| 702 expect(location.offset, testCode.indexOf("FTA(")); | 706 expect(location.offset, testCode.indexOf("FTA<K, V>(")); |
| 703 expect(location.length, "FTA".length); | 707 expect(location.length, "FTA".length); |
| 704 } | 708 } |
| 705 expect(element.parameters, "(int i, String s)"); | 709 expect(element.parameters, "(int i, String s)"); |
| 706 expect(element.returnType, "String"); | 710 expect(element.returnType, "String"); |
| 707 } | 711 } |
| 708 // FTB | 712 // FTB |
| 709 { | 713 { |
| 710 Outline outline = topOutlines[1]; | 714 Outline outline = topOutlines[1]; |
| 711 Element element = outline.element; | 715 Element element = outline.element; |
| 712 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); | 716 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); |
| 713 expect(element.name, "FTB"); | 717 expect(element.name, "FTB"); |
| 718 expect(element.typeParameters, isNull); |
| 714 { | 719 { |
| 715 Location location = element.location; | 720 Location location = element.location; |
| 716 expect(location.offset, testCode.indexOf("FTB(")); | 721 expect(location.offset, testCode.indexOf("FTB(")); |
| 717 expect(location.length, "FTB".length); | 722 expect(location.length, "FTB".length); |
| 718 } | 723 } |
| 719 expect(element.parameters, "(int p)"); | 724 expect(element.parameters, "(int p)"); |
| 720 expect(element.returnType, ""); | 725 expect(element.returnType, ""); |
| 721 } | 726 } |
| 722 // CTA | 727 // CTA |
| 723 { | 728 { |
| 724 Outline outline = topOutlines[4]; | 729 Outline outline = topOutlines[4]; |
| 725 Element element = outline.element; | 730 Element element = outline.element; |
| 726 expect(element.kind, ElementKind.CLASS_TYPE_ALIAS); | 731 expect(element.kind, ElementKind.CLASS_TYPE_ALIAS); |
| 727 expect(element.name, "CTA"); | 732 expect(element.name, "CTA"); |
| 733 expect(element.typeParameters, '<T>'); |
| 728 { | 734 { |
| 729 Location location = element.location; | 735 Location location = element.location; |
| 730 expect(location.offset, testCode.indexOf("CTA =")); | 736 expect(location.offset, testCode.indexOf("CTA<T> =")); |
| 731 expect(location.length, "CTA".length); | 737 expect(location.length, "CTA".length); |
| 732 } | 738 } |
| 733 expect(element.parameters, isNull); | 739 expect(element.parameters, isNull); |
| 734 expect(element.returnType, isNull); | 740 expect(element.returnType, isNull); |
| 735 } | 741 } |
| 742 // CTB |
| 743 { |
| 744 Outline outline = topOutlines[5]; |
| 745 Element element = outline.element; |
| 746 expect(element.kind, ElementKind.CLASS_TYPE_ALIAS); |
| 747 expect(element.name, 'CTB'); |
| 748 expect(element.typeParameters, isNull); |
| 749 expect(element.returnType, isNull); |
| 750 } |
| 736 // fA | 751 // fA |
| 737 { | 752 { |
| 738 Outline outline = topOutlines[5]; | 753 Outline outline = topOutlines[6]; |
| 739 Element element = outline.element; | 754 Element element = outline.element; |
| 740 expect(element.kind, ElementKind.FUNCTION); | 755 expect(element.kind, ElementKind.FUNCTION); |
| 741 expect(element.name, "fA"); | 756 expect(element.name, "fA"); |
| 742 { | 757 { |
| 743 Location location = element.location; | 758 Location location = element.location; |
| 744 expect(location.offset, testCode.indexOf("fA(")); | 759 expect(location.offset, testCode.indexOf("fA(")); |
| 745 expect(location.length, "fA".length); | 760 expect(location.length, "fA".length); |
| 746 } | 761 } |
| 747 expect(element.parameters, "(int i, String s)"); | 762 expect(element.parameters, "(int i, String s)"); |
| 748 expect(element.returnType, "String"); | 763 expect(element.returnType, "String"); |
| 749 } | 764 } |
| 750 // fB | 765 // fB |
| 751 { | 766 { |
| 752 Outline outline = topOutlines[6]; | 767 Outline outline = topOutlines[7]; |
| 753 Element element = outline.element; | 768 Element element = outline.element; |
| 754 expect(element.kind, ElementKind.FUNCTION); | 769 expect(element.kind, ElementKind.FUNCTION); |
| 755 expect(element.name, "fB"); | 770 expect(element.name, "fB"); |
| 756 { | 771 { |
| 757 Location location = element.location; | 772 Location location = element.location; |
| 758 expect(location.offset, testCode.indexOf("fB(")); | 773 expect(location.offset, testCode.indexOf("fB(")); |
| 759 expect(location.length, "fB".length); | 774 expect(location.length, "fB".length); |
| 760 } | 775 } |
| 761 expect(element.parameters, "(int p)"); | 776 expect(element.parameters, "(int p)"); |
| 762 expect(element.returnType, ""); | 777 expect(element.returnType, ""); |
| 763 } | 778 } |
| 764 // propA | 779 // propA |
| 765 { | 780 { |
| 766 Outline outline = topOutlines[7]; | 781 Outline outline = topOutlines[8]; |
| 767 Element element = outline.element; | 782 Element element = outline.element; |
| 768 expect(element.kind, ElementKind.GETTER); | 783 expect(element.kind, ElementKind.GETTER); |
| 769 expect(element.name, "propA"); | 784 expect(element.name, "propA"); |
| 770 { | 785 { |
| 771 Location location = element.location; | 786 Location location = element.location; |
| 772 expect(location.offset, testCode.indexOf("propA => null;")); | 787 expect(location.offset, testCode.indexOf("propA => null;")); |
| 773 expect(location.length, "propA".length); | 788 expect(location.length, "propA".length); |
| 774 } | 789 } |
| 775 expect(element.parameters, ""); | 790 expect(element.parameters, ""); |
| 776 expect(element.returnType, "String"); | 791 expect(element.returnType, "String"); |
| 777 } | 792 } |
| 778 // propB | 793 // propB |
| 779 { | 794 { |
| 780 Outline outline = topOutlines[8]; | 795 Outline outline = topOutlines[9]; |
| 781 Element element = outline.element; | 796 Element element = outline.element; |
| 782 expect(element.kind, ElementKind.SETTER); | 797 expect(element.kind, ElementKind.SETTER); |
| 783 expect(element.name, "propB"); | 798 expect(element.name, "propB"); |
| 784 { | 799 { |
| 785 Location location = element.location; | 800 Location location = element.location; |
| 786 expect(location.offset, testCode.indexOf("propB(int v) {}")); | 801 expect(location.offset, testCode.indexOf("propB(int v) {}")); |
| 787 expect(location.length, "propB".length); | 802 expect(location.length, "propB".length); |
| 788 } | 803 } |
| 789 expect(element.parameters, "(int v)"); | 804 expect(element.parameters, "(int v)"); |
| 790 expect(element.returnType, ""); | 805 expect(element.returnType, ""); |
| 791 } | 806 } |
| 792 }); | 807 }); |
| 793 } | 808 } |
| 794 | 809 |
| 795 void _isEnumConstant(Outline outline, String name) { | 810 void _isEnumConstant(Outline outline, String name) { |
| 796 Element element = outline.element; | 811 Element element = outline.element; |
| 797 expect(element.kind, ElementKind.ENUM_CONSTANT); | 812 expect(element.kind, ElementKind.ENUM_CONSTANT); |
| 798 expect(element.name, name); | 813 expect(element.name, name); |
| 799 expect(element.parameters, isNull); | 814 expect(element.parameters, isNull); |
| 800 expect(element.returnType, isNull); | 815 expect(element.returnType, isNull); |
| 801 } | 816 } |
| 802 } | 817 } |
| OLD | NEW |