| 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.services.completion.util; | 5 library test.services.completion.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, | 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, |
| 10 ElementKind; | 10 ElementKind; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 (CompletionSuggestion cs) => cs.completion == completion, | 107 (CompletionSuggestion cs) => cs.completion == completion, |
| 108 orElse: () => null); | 108 orElse: () => null); |
| 109 if (suggestion != null) { | 109 if (suggestion != null) { |
| 110 failedCompletion('did not expect completion: $completion\n $suggestion'); | 110 failedCompletion('did not expect completion: $completion\n $suggestion'); |
| 111 } | 111 } |
| 112 return null; | 112 return null; |
| 113 } | 113 } |
| 114 | 114 |
| 115 CompletionSuggestion assertSuggest(String completion, | 115 CompletionSuggestion assertSuggest(String completion, |
| 116 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, | 116 {CompletionSuggestionKind csKind: CompletionSuggestionKind.INVOCATION, |
| 117 int relevance: DART_RELEVANCE_DEFAULT, protocol.ElementKind elemKind: | 117 int relevance: DART_RELEVANCE_DEFAULT, protocol.ElementKind elemKind: null
, |
| 118 null, bool isDeprecated: false, bool isPotential: false}) { | 118 bool isDeprecated: false, bool isPotential: false}) { |
| 119 CompletionSuggestion cs = | 119 CompletionSuggestion cs = |
| 120 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); | 120 getSuggest(completion: completion, csKind: csKind, elemKind: elemKind); |
| 121 if (cs == null) { | 121 if (cs == null) { |
| 122 failedCompletion( | 122 failedCompletion( |
| 123 'expected $completion $csKind $elemKind', | 123 'expected $completion $csKind $elemKind', |
| 124 request.suggestions); | 124 request.suggestions); |
| 125 } | 125 } |
| 126 expect(cs.kind, equals(csKind)); | 126 expect(cs.kind, equals(csKind)); |
| 127 if (isDeprecated) { | 127 if (isDeprecated) { |
| 128 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); | 128 expect(cs.relevance, equals(DART_RELEVANCE_LOW)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 expect(param[0], equals('(')); | 253 expect(param[0], equals('(')); |
| 254 expect(param[param.length - 1], equals(')')); | 254 expect(param[param.length - 1], equals(')')); |
| 255 expect( | 255 expect( |
| 256 element.returnType, | 256 element.returnType, |
| 257 equals(returnType != null ? returnType : 'dynamic')); | 257 equals(returnType != null ? returnType : 'dynamic')); |
| 258 assertHasParameterInfo(cs); | 258 assertHasParameterInfo(cs); |
| 259 return cs; | 259 return cs; |
| 260 } | 260 } |
| 261 | 261 |
| 262 CompletionSuggestion assertSuggestFunctionTypeAlias(String name, | 262 CompletionSuggestion assertSuggestFunctionTypeAlias(String name, |
| 263 String returnType, bool isDeprecated, [int relevance = | 263 String returnType, bool isDeprecated, [int relevance = DART_RELEVANCE_DEFA
ULT, |
| 264 DART_RELEVANCE_DEFAULT, CompletionSuggestionKind kind = | 264 CompletionSuggestionKind kind = CompletionSuggestionKind.INVOCATION]) { |
| 265 CompletionSuggestionKind.INVOCATION]) { | |
| 266 CompletionSuggestion cs = assertSuggest( | 265 CompletionSuggestion cs = assertSuggest( |
| 267 name, | 266 name, |
| 268 csKind: kind, | 267 csKind: kind, |
| 269 relevance: relevance, | 268 relevance: relevance, |
| 270 isDeprecated: isDeprecated); | 269 isDeprecated: isDeprecated); |
| 271 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); | 270 expect(cs.returnType, returnType != null ? returnType : 'dynamic'); |
| 272 protocol.Element element = cs.element; | 271 protocol.Element element = cs.element; |
| 273 expect(element, isNotNull); | 272 expect(element, isNotNull); |
| 274 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); | 273 expect(element.kind, equals(protocol.ElementKind.FUNCTION_TYPE_ALIAS)); |
| 275 expect(element.name, equals(name)); | 274 expect(element.name, equals(name)); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 return assertNotSuggested(name); | 665 return assertNotSuggested(name); |
| 667 } | 666 } |
| 668 } | 667 } |
| 669 | 668 |
| 670 CompletionSuggestion assertSuggestInvocationField(String name, String type, | 669 CompletionSuggestion assertSuggestInvocationField(String name, String type, |
| 671 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { | 670 {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecated: false}) { |
| 672 return assertNotSuggested(name); | 671 return assertNotSuggested(name); |
| 673 } | 672 } |
| 674 | 673 |
| 675 CompletionSuggestion assertSuggestInvocationGetter(String name, | 674 CompletionSuggestion assertSuggestInvocationGetter(String name, |
| 676 String returnType, {int relevance: DART_RELEVANCE_DEFAULT, | 675 String returnType, {int relevance: DART_RELEVANCE_DEFAULT, bool isDeprecat
ed: |
| 677 bool isDeprecated: false}) { | 676 false}) { |
| 678 if (computer is InvocationComputer) { | 677 if (computer is InvocationComputer) { |
| 679 return assertSuggestGetter( | 678 return assertSuggestGetter( |
| 680 name, | 679 name, |
| 681 returnType, | 680 returnType, |
| 682 relevance: relevance, | 681 relevance: relevance, |
| 683 isDeprecated: isDeprecated); | 682 isDeprecated: isDeprecated); |
| 684 } else { | 683 } else { |
| 685 return assertNotSuggested(name); | 684 return assertNotSuggested(name); |
| 686 } | 685 } |
| 687 } | 686 } |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 // SimpleStringLiteral ImportDirective | 1887 // SimpleStringLiteral ImportDirective |
| 1889 addTestSource(''' | 1888 addTestSource(''' |
| 1890 import "dart^"; | 1889 import "dart^"; |
| 1891 main() {}'''); | 1890 main() {}'''); |
| 1892 computeFast(); | 1891 computeFast(); |
| 1893 return computeFull((bool result) { | 1892 return computeFull((bool result) { |
| 1894 assertNoSuggestions(); | 1893 assertNoSuggestions(); |
| 1895 }); | 1894 }); |
| 1896 } | 1895 } |
| 1897 | 1896 |
| 1897 test_IndexExpression() { |
| 1898 // ExpressionStatement Block |
| 1899 addSource('/testA.dart', ''' |
| 1900 int T1; |
| 1901 F1() { } |
| 1902 class A {int x;}'''); |
| 1903 addTestSource(''' |
| 1904 import "/testA.dart"; |
| 1905 int T2; |
| 1906 F2() { } |
| 1907 class B {int x;} |
| 1908 class C {foo(){var f; {var x;} f[^]}}'''); |
| 1909 computeFast(); |
| 1910 return computeFull((bool result) { |
| 1911 assertNotSuggested('x'); |
| 1912 assertSuggestLocalVariable('f', null); |
| 1913 assertSuggestLocalMethod('foo', 'C', null); |
| 1914 assertSuggestLocalClass('C'); |
| 1915 assertSuggestLocalFunction('F2', null); |
| 1916 assertSuggestLocalTopLevelVar('T2', 'int'); |
| 1917 assertSuggestImportedClass('A'); |
| 1918 assertSuggestImportedFunction('F1', null); |
| 1919 // TODO (danrubel) getter is being suggested instead of top level var |
| 1920 //assertSuggestImportedTopLevelVar('T1', 'int'); |
| 1921 }); |
| 1922 } |
| 1923 |
| 1924 test_IndexExpression2() { |
| 1925 // SimpleIdentifier IndexExpression ExpressionStatement Block |
| 1926 addSource('/testA.dart', ''' |
| 1927 int T1; |
| 1928 F1() { } |
| 1929 class A {int x;}'''); |
| 1930 addTestSource(''' |
| 1931 import "/testA.dart"; |
| 1932 int T2; |
| 1933 F2() { } |
| 1934 class B {int x;} |
| 1935 class C {foo(){var f; {var x;} f[T^]}}'''); |
| 1936 computeFast(); |
| 1937 return computeFull((bool result) { |
| 1938 // top level results are partially filtered based on first char |
| 1939 assertSuggestLocalTopLevelVar('T2', 'int'); |
| 1940 // TODO (danrubel) getter is being suggested instead of top level var |
| 1941 //assertSuggestImportedTopLevelVar('T1', 'int'); |
| 1942 }); |
| 1943 } |
| 1944 |
| 1898 test_InstanceCreationExpression_imported() { | 1945 test_InstanceCreationExpression_imported() { |
| 1899 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression | 1946 // SimpleIdentifier TypeName ConstructorName InstanceCreationExpression |
| 1900 addSource('/testA.dart', ''' | 1947 addSource('/testA.dart', ''' |
| 1901 int T1; | 1948 int T1; |
| 1902 F1() { } | 1949 F1() { } |
| 1903 class A {int x;}'''); | 1950 class A {int x;}'''); |
| 1904 addTestSource(''' | 1951 addTestSource(''' |
| 1905 import "/testA.dart"; | 1952 import "/testA.dart"; |
| 1906 int T2; | 1953 int T2; |
| 1907 F2() { } | 1954 F2() { } |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2696 assertNotSuggested('bar2'); | 2743 assertNotSuggested('bar2'); |
| 2697 assertNotSuggested('_B'); | 2744 assertNotSuggested('_B'); |
| 2698 assertSuggestLocalClass('Y'); | 2745 assertSuggestLocalClass('Y'); |
| 2699 assertSuggestLocalClass('C'); | 2746 assertSuggestLocalClass('C'); |
| 2700 assertSuggestLocalVariable('f', null); | 2747 assertSuggestLocalVariable('f', null); |
| 2701 assertNotSuggested('x'); | 2748 assertNotSuggested('x'); |
| 2702 assertNotSuggested('e'); | 2749 assertNotSuggested('e'); |
| 2703 }); | 2750 }); |
| 2704 } | 2751 } |
| 2705 } | 2752 } |
| OLD | NEW |