| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.services.completion.dart.local; | |
| 6 | |
| 7 import 'package:analysis_services/src/completion/local_computer.dart'; | |
| 8 import 'package:analysis_testing/reflective_tests.dart'; | |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 | |
| 11 import 'completion_test_util.dart'; | |
| 12 | |
| 13 main() { | |
| 14 groupSep = ' | '; | |
| 15 runReflectiveTests(LocalComputerTest); | |
| 16 } | |
| 17 | |
| 18 @ReflectiveTestCase() | |
| 19 class LocalComputerTest extends AbstractCompletionTest { | |
| 20 | |
| 21 @override | |
| 22 void setUp() { | |
| 23 super.setUp(); | |
| 24 computer = new LocalComputer(); | |
| 25 } | |
| 26 | |
| 27 test_block() { | |
| 28 addTestSource('class A {a() {var f; {var x;} ^ var g;}}'); | |
| 29 expect(computeFast(), isTrue); | |
| 30 assertSuggestLocalVariable('f'); | |
| 31 assertNotSuggested('g'); | |
| 32 assertNotSuggested('x'); | |
| 33 } | |
| 34 | |
| 35 test_catch() { | |
| 36 addTestSource('class A {a() {try{} catch (e) {^}}}'); | |
| 37 expect(computeFast(), isTrue); | |
| 38 assertSuggestParameter('e'); | |
| 39 } | |
| 40 | |
| 41 test_catch2() { | |
| 42 addTestSource('class A {a() {try{} catch (e, s) {^}}}'); | |
| 43 expect(computeFast(), isTrue); | |
| 44 assertSuggestParameter('e'); | |
| 45 assertSuggestParameter('s'); | |
| 46 } | |
| 47 | |
| 48 test_compilationUnit_declarations() { | |
| 49 addTestSource('class A {^} class B {} var T;'); | |
| 50 expect(computeFast(), isTrue); | |
| 51 assertSuggestClass('A'); | |
| 52 assertSuggestClass('B'); | |
| 53 assertSuggestTopLevelVar('T'); | |
| 54 } | |
| 55 | |
| 56 test_compilationUnit_directives() { | |
| 57 addTestSource('import "boo.dart" as x; class A {^}'); | |
| 58 expect(computeFast(), isTrue); | |
| 59 assertSuggestLibraryPrefix('x'); | |
| 60 } | |
| 61 | |
| 62 test_field_name() { | |
| 63 addTestSource('class A {B ^}}'); | |
| 64 expect(computeFast(), isTrue); | |
| 65 assertNotSuggested('A'); | |
| 66 } | |
| 67 | |
| 68 test_field_name2() { | |
| 69 addTestSource('class A {var ^}}'); | |
| 70 expect(computeFast(), isTrue); | |
| 71 //TODO (danrubel) should not be suggested | |
| 72 // but var ^ in this test | |
| 73 // parses differently than B ^ in test above | |
| 74 assertSuggestClass('A'); | |
| 75 } | |
| 76 | |
| 77 test_for() { | |
| 78 addTestSource('main(args) {for (int i; i < 10; ++i) {^}}'); | |
| 79 expect(computeFast(), isTrue); | |
| 80 assertSuggestLocalVariable('i'); | |
| 81 } | |
| 82 | |
| 83 test_forEach() { | |
| 84 addTestSource('main(args) {for (foo in bar) {^}}'); | |
| 85 expect(computeFast(), isTrue); | |
| 86 assertSuggestLocalVariable('foo'); | |
| 87 } | |
| 88 | |
| 89 test_function() { | |
| 90 addTestSource('main(args) {x.then((b) {^});}'); | |
| 91 expect(computeFast(), isTrue); | |
| 92 assertSuggestFunction('main'); | |
| 93 assertSuggestParameter('args'); | |
| 94 assertSuggestParameter('b'); | |
| 95 } | |
| 96 | |
| 97 test_local_name() { | |
| 98 addTestSource('class A {a() {var f; A ^}}'); | |
| 99 expect(computeFast(), isTrue); | |
| 100 //TODO (danrubel) should not be suggested | |
| 101 // but A ^ in this test | |
| 102 // parses differently than var ^ in test below | |
| 103 assertSuggestClass('A'); | |
| 104 assertSuggestMethodName('a'); | |
| 105 assertSuggestLocalVariable('f'); | |
| 106 } | |
| 107 | |
| 108 test_local_name2() { | |
| 109 addTestSource('class A {a() {var f; var ^}}'); | |
| 110 expect(computeFast(), isTrue); | |
| 111 assertNotSuggested('A'); | |
| 112 assertNotSuggested('a'); | |
| 113 assertNotSuggested('f'); | |
| 114 } | |
| 115 | |
| 116 test_members() { | |
| 117 addTestSource('class A {var f; a() {^} var g;}'); | |
| 118 expect(computeFast(), isTrue); | |
| 119 assertSuggestMethodName('a'); | |
| 120 assertSuggestField('f'); | |
| 121 assertSuggestField('g'); | |
| 122 } | |
| 123 | |
| 124 test_methodParam_named() { | |
| 125 addTestSource('class A {a(x, {y: boo}) {^}}'); | |
| 126 expect(computeFast(), isTrue); | |
| 127 assertSuggestMethodName('a'); | |
| 128 assertSuggestParameter('x'); | |
| 129 assertSuggestParameter('y'); | |
| 130 } | |
| 131 | |
| 132 test_methodParam_positional() { | |
| 133 addTestSource('class A {a(x, [y=1]) {^}}'); | |
| 134 expect(computeFast(), isTrue); | |
| 135 assertSuggestMethodName('a'); | |
| 136 assertSuggestParameter('x'); | |
| 137 assertSuggestParameter('y'); | |
| 138 } | |
| 139 | |
| 140 test_topLevelVar_name() { | |
| 141 addTestSource('class A {} B ^'); | |
| 142 expect(computeFast(), isTrue); | |
| 143 assertNotSuggested('A'); | |
| 144 } | |
| 145 | |
| 146 test_topLevelVar_name2() { | |
| 147 addTestSource('class A {} var ^'); | |
| 148 expect(computeFast(), isTrue); | |
| 149 // TODO (danrubel) should not be suggested | |
| 150 // but var ^ in this test | |
| 151 // parses differently than B ^ in test above | |
| 152 assertSuggestClass('A'); | |
| 153 } | |
| 154 | |
| 155 test_variableDeclaration() { | |
| 156 addTestSource('main() {int a = 1, b = 2 + ^;}'); | |
| 157 expect(computeFast(), isTrue); | |
| 158 assertSuggestLocalVariable('a'); | |
| 159 assertNotSuggested('b'); | |
| 160 } | |
| 161 } | |
| OLD | NEW |