|
| 1 | +// Copyright (c) 2025, 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 | +import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 6 | + |
| 7 | +import '../../../../client/completion_driver_test.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + defineReflectiveSuite(() { |
| 11 | + defineReflectiveTests(DartDocTest); |
| 12 | + }); |
| 13 | +} |
| 14 | + |
| 15 | +@reflectiveTest |
| 16 | +class DartDocTest extends AbstractCompletionDriverTest { |
| 17 | + Future<void> test_class() async { |
| 18 | + allowedIdentifiers = const {'MyClass1'}; |
| 19 | + await computeSuggestions(''' |
| 20 | +/// This doc should suggest the commented class name [MyC^]. |
| 21 | +class MyClass1 {} |
| 22 | +'''); |
| 23 | + assertResponse(r''' |
| 24 | +replacement |
| 25 | + left: 3 |
| 26 | +suggestions |
| 27 | + MyClass1 |
| 28 | + kind: class |
| 29 | +'''); |
| 30 | + } |
| 31 | + |
| 32 | + Future<void> test_constructorInvocation() async { |
| 33 | + allowedIdentifiers = const {'constructor1'}; |
| 34 | + await computeSuggestions(''' |
| 35 | +class MyClass1 { |
| 36 | + /// This doc should suggest the commented constructor name [MyClass1.^]. |
| 37 | + MyClass1.constructor1(); |
| 38 | +} |
| 39 | +'''); |
| 40 | + assertResponse(r''' |
| 41 | +suggestions |
| 42 | + constructor1 |
| 43 | + kind: constructorInvocation |
| 44 | +'''); |
| 45 | + } |
| 46 | + |
| 47 | + Future<void> test_constructorParameter() async { |
| 48 | + allowedIdentifiers = const {'param1'}; |
| 49 | + await computeSuggestions(''' |
| 50 | +class MyClass1 { |
| 51 | + /// This doc should suggest the commented constructor parameter name [par^]. |
| 52 | + MyClass1([int param1 = 0]); |
| 53 | +} |
| 54 | +'''); |
| 55 | + assertResponse(r''' |
| 56 | +replacement |
| 57 | + left: 3 |
| 58 | +suggestions |
| 59 | + param1 |
| 60 | + kind: parameter |
| 61 | +'''); |
| 62 | + } |
| 63 | + |
| 64 | + @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/59724') |
| 65 | + Future<void> test_extension() async { |
| 66 | + allowedIdentifiers = const {'MyExt'}; |
| 67 | + await computeSuggestions(''' |
| 68 | +/// This doc should suggest the commented extension name [MyE^]. |
| 69 | +extension MyExt on int {} |
| 70 | +'''); |
| 71 | + assertResponse(r''' |
| 72 | +replacement |
| 73 | + left: 3 |
| 74 | +suggestions |
| 75 | + MyExt |
| 76 | + kind: extension |
| 77 | +'''); |
| 78 | + } |
| 79 | + |
| 80 | + Future<void> test_extensionType() async { |
| 81 | + allowedIdentifiers = const {'MyExtensionType'}; |
| 82 | + await computeSuggestions(''' |
| 83 | +/// This doc should suggest the commented extension type name [MyE^]. |
| 84 | +extension type MyExtensionType(int i) {} |
| 85 | +'''); |
| 86 | + assertResponse(r''' |
| 87 | +replacement |
| 88 | + left: 3 |
| 89 | +suggestions |
| 90 | + MyExtensionType |
| 91 | + kind: extensionType |
| 92 | +'''); |
| 93 | + } |
| 94 | + |
| 95 | + Future<void> test_field1() async { |
| 96 | + allowedIdentifiers = const {'myField'}; |
| 97 | + await computeSuggestions(''' |
| 98 | +class MyClass1 { |
| 99 | + /// This doc should suggest the commented field name [myF^]. |
| 100 | + int myField = 0; |
| 101 | +} |
| 102 | +'''); |
| 103 | + assertResponse(r''' |
| 104 | +replacement |
| 105 | + left: 3 |
| 106 | +suggestions |
| 107 | + myField |
| 108 | + kind: field |
| 109 | +'''); |
| 110 | + } |
| 111 | + |
| 112 | + @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/59724') |
| 113 | + Future<void> test_field2() async { |
| 114 | + allowedIdentifiers = const {'myField'}; |
| 115 | + await computeSuggestions(''' |
| 116 | +/// This is unrelated but should suggest name [MyClass1.myF^]. |
| 117 | +var myVariable = 0; |
| 118 | +
|
| 119 | +class MyClass1 { |
| 120 | + int myField = 0; |
| 121 | +} |
| 122 | +'''); |
| 123 | + assertResponse(r''' |
| 124 | +replacement |
| 125 | + left: 3 |
| 126 | +suggestions |
| 127 | + myField |
| 128 | + kind: field |
| 129 | +'''); |
| 130 | + } |
| 131 | + |
| 132 | + Future<void> test_function() async { |
| 133 | + allowedIdentifiers = const {'myFunction'}; |
| 134 | + await computeSuggestions(''' |
| 135 | +/// This doc should suggest the commented function name [myF^]. |
| 136 | +void myFunction() {} |
| 137 | +'''); |
| 138 | + assertResponse(r''' |
| 139 | +replacement |
| 140 | + left: 3 |
| 141 | +suggestions |
| 142 | + myFunction |
| 143 | + kind: function |
| 144 | +'''); |
| 145 | + } |
| 146 | + |
| 147 | + Future<void> test_getter() async { |
| 148 | + allowedIdentifiers = const {'myGetter'}; |
| 149 | + await computeSuggestions(''' |
| 150 | +class MyClass1 { |
| 151 | + /// This doc should suggest the commented getter name [myG^]. |
| 152 | + int get myGetter => 0; |
| 153 | +} |
| 154 | +'''); |
| 155 | + assertResponse(r''' |
| 156 | +replacement |
| 157 | + left: 3 |
| 158 | +suggestions |
| 159 | + myGetter |
| 160 | + kind: getter |
| 161 | +'''); |
| 162 | + } |
| 163 | + |
| 164 | + @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/59724') |
| 165 | + Future<void> test_importPrefix() async { |
| 166 | + allowedIdentifiers = const {'myPrefix'}; |
| 167 | + await computeSuggestions(''' |
| 168 | +/// This doc should suggest the commented import prefix name [myP^]. |
| 169 | +import 'dart:async' as myPrefix; |
| 170 | +'''); |
| 171 | + assertResponse(r''' |
| 172 | +replacement |
| 173 | + left: 3 |
| 174 | +suggestions |
| 175 | + myPrefix |
| 176 | + kind: importPrefix |
| 177 | +'''); |
| 178 | + } |
| 179 | + |
| 180 | + @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/59724') |
| 181 | + Future<void> test_library() async { |
| 182 | + allowedIdentifiers = const {'MyClass1'}; |
| 183 | + await computeSuggestions(''' |
| 184 | +/// This doc should suggest the class in the library [MyC^]. |
| 185 | +library; |
| 186 | +
|
| 187 | +class MyClass1 {} |
| 188 | +'''); |
| 189 | + assertResponse(r''' |
| 190 | +replacement |
| 191 | + left: 3 |
| 192 | +suggestions |
| 193 | + MyClass1 |
| 194 | + kind: class |
| 195 | +'''); |
| 196 | + } |
| 197 | + |
| 198 | + Future<void> test_method() async { |
| 199 | + allowedIdentifiers = const {'myMethod'}; |
| 200 | + await computeSuggestions(''' |
| 201 | +class MyClass1 { |
| 202 | + /// This doc should suggest the commented method name [myM^]. |
| 203 | + void myMethod() {} |
| 204 | +} |
| 205 | +'''); |
| 206 | + assertResponse(r''' |
| 207 | +replacement |
| 208 | + left: 3 |
| 209 | +suggestions |
| 210 | + myMethod |
| 211 | + kind: method |
| 212 | +'''); |
| 213 | + } |
| 214 | + |
| 215 | + Future<void> test_mixin() async { |
| 216 | + allowedIdentifiers = const {'MyMixin'}; |
| 217 | + await computeSuggestions(''' |
| 218 | +/// This doc should suggest the commented mixin name [MyM^]. |
| 219 | +mixin MyMixin {} |
| 220 | +'''); |
| 221 | + assertResponse(r''' |
| 222 | +replacement |
| 223 | + left: 3 |
| 224 | +suggestions |
| 225 | + MyMixin |
| 226 | + kind: mixin |
| 227 | +'''); |
| 228 | + } |
| 229 | + |
| 230 | + Future<void> test_namedParameter() async { |
| 231 | + allowedIdentifiers = const {'param1'}; |
| 232 | + await computeSuggestions(''' |
| 233 | +/// This doc should suggest the commented named parameter name [par^]. |
| 234 | +void myFunction({int param1}) {} |
| 235 | +'''); |
| 236 | + assertResponse(r''' |
| 237 | +replacement |
| 238 | + left: 3 |
| 239 | +suggestions |
| 240 | + param1 |
| 241 | + kind: parameter |
| 242 | +'''); |
| 243 | + } |
| 244 | + |
| 245 | + Future<void> test_parameter() async { |
| 246 | + allowedIdentifiers = const {'param1'}; |
| 247 | + await computeSuggestions(''' |
| 248 | +/// This doc should suggest the commented parameter name [par^]. |
| 249 | +void myFunction(int param1) {} |
| 250 | +'''); |
| 251 | + assertResponse(r''' |
| 252 | +replacement |
| 253 | + left: 3 |
| 254 | +suggestions |
| 255 | + param1 |
| 256 | + kind: parameter |
| 257 | +'''); |
| 258 | + } |
| 259 | + |
| 260 | + Future<void> test_setter() async { |
| 261 | + allowedIdentifiers = const {'mySetter'}; |
| 262 | + await computeSuggestions(''' |
| 263 | +class MyClass1 { |
| 264 | + /// This doc should suggest the commented setter name [myS^]. |
| 265 | + set mySetter(int value) {} |
| 266 | +} |
| 267 | +'''); |
| 268 | + assertResponse(r''' |
| 269 | +replacement |
| 270 | + left: 3 |
| 271 | +suggestions |
| 272 | + mySetter |
| 273 | + kind: setter |
| 274 | +'''); |
| 275 | + } |
| 276 | + |
| 277 | + Future<void> test_topLevelGetter() async { |
| 278 | + allowedIdentifiers = const {'myTopLevelGetter'}; |
| 279 | + await computeSuggestions(''' |
| 280 | +/// This doc should suggest the commented top-level getter name [myT^]. |
| 281 | +int get myTopLevelGetter => 0; |
| 282 | +'''); |
| 283 | + assertResponse(r''' |
| 284 | +replacement |
| 285 | + left: 3 |
| 286 | +suggestions |
| 287 | + myTopLevelGetter |
| 288 | + kind: getter |
| 289 | +'''); |
| 290 | + } |
| 291 | + |
| 292 | + Future<void> test_topLevelSetter() async { |
| 293 | + allowedIdentifiers = const {'myTopLevelSetter'}; |
| 294 | + await computeSuggestions(''' |
| 295 | +/// This doc should suggest the commented top-level setter name [myT^]. |
| 296 | +set myTopLevelSetter(int value) {} |
| 297 | +'''); |
| 298 | + assertResponse(r''' |
| 299 | +replacement |
| 300 | + left: 3 |
| 301 | +suggestions |
| 302 | + myTopLevelSetter |
| 303 | + kind: setter |
| 304 | +'''); |
| 305 | + } |
| 306 | + |
| 307 | + @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/59724') |
| 308 | + Future<void> test_typedef() async { |
| 309 | + allowedIdentifiers = const {'MyTypedef'}; |
| 310 | + await computeSuggestions(''' |
| 311 | +/// This doc should suggest the commented typedef name [MyT^]. |
| 312 | +typedef MyTypedef = int Function(); |
| 313 | +'''); |
| 314 | + assertResponse(r''' |
| 315 | +replacement |
| 316 | + left: 3 |
| 317 | +suggestions |
| 318 | + MyTypedef |
| 319 | + kind: typedef |
| 320 | +'''); |
| 321 | + } |
| 322 | + |
| 323 | + Future<void> test_typeParameter() async { |
| 324 | + allowedIdentifiers = const {'TypeParam'}; |
| 325 | + await computeSuggestions(''' |
| 326 | +/// This doc should suggest the commented type parameter name [T^]. |
| 327 | +void myFunction<TypeParam>() {} |
| 328 | +'''); |
| 329 | + assertResponse(r''' |
| 330 | +replacement |
| 331 | + left: 1 |
| 332 | +suggestions |
| 333 | + TypeParam |
| 334 | + kind: typeParameter |
| 335 | +'''); |
| 336 | + } |
| 337 | + |
| 338 | + Future<void> test_variable() async { |
| 339 | + allowedIdentifiers = const {'myVar'}; |
| 340 | + await computeSuggestions(''' |
| 341 | +/// This doc should suggest the commented variable name [myV^]. |
| 342 | +int myVar = 0; |
| 343 | +'''); |
| 344 | + assertResponse(r''' |
| 345 | +replacement |
| 346 | + left: 3 |
| 347 | +suggestions |
| 348 | + myVar |
| 349 | + kind: topLevelVariable |
| 350 | +'''); |
| 351 | + } |
| 352 | +} |
0 commit comments