|
| 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 'context_collection_resolution.dart'; |
| 8 | +import 'node_text_expectations.dart'; |
| 9 | + |
| 10 | +main() { |
| 11 | + defineReflectiveSuite(() { |
| 12 | + defineReflectiveTests(DotShorthandInvocationResolutionTest); |
| 13 | + defineReflectiveTests(UpdateNodeTextExpectations); |
| 14 | + }); |
| 15 | +} |
| 16 | + |
| 17 | +@reflectiveTest |
| 18 | +class DotShorthandInvocationResolutionTest extends PubPackageResolutionTest { |
| 19 | + test_dotShorthand_basic() async { |
| 20 | + await assertNoErrorsInCode(r''' |
| 21 | +class C { |
| 22 | + static C member() => C(1); |
| 23 | + int x; |
| 24 | + C(this.x); |
| 25 | +} |
| 26 | +
|
| 27 | +void main() { |
| 28 | + C c = .member(); |
| 29 | + print(c); |
| 30 | +} |
| 31 | +'''); |
| 32 | + |
| 33 | + var node = findNode.singleDotShorthandInvocation; |
| 34 | + assertResolvedNodeText(node, r''' |
| 35 | +DotShorthandInvocation |
| 36 | + period: . |
| 37 | + memberName: SimpleIdentifier |
| 38 | + token: member |
| 39 | + element: <testLibraryFragment>::@class::C::@method::member#element |
| 40 | + staticType: C Function() |
| 41 | + argumentList: ArgumentList |
| 42 | + leftParenthesis: ( |
| 43 | + rightParenthesis: ) |
| 44 | + staticInvokeType: C Function() |
| 45 | + staticType: C |
| 46 | +'''); |
| 47 | + } |
| 48 | + |
| 49 | + test_dotShorthand_basic_generic() async { |
| 50 | + await assertNoErrorsInCode(r''' |
| 51 | +class C<T> { |
| 52 | + static C member<U>(U x) => C(x); |
| 53 | + T x; |
| 54 | + C(this.x); |
| 55 | +} |
| 56 | +
|
| 57 | +void main() { |
| 58 | + C c = .member<int>(1); |
| 59 | + print(c); |
| 60 | +} |
| 61 | +'''); |
| 62 | + |
| 63 | + var node = findNode.singleDotShorthandInvocation; |
| 64 | + assertResolvedNodeText(node, r''' |
| 65 | +DotShorthandInvocation |
| 66 | + period: . |
| 67 | + memberName: SimpleIdentifier |
| 68 | + token: member |
| 69 | + element: <testLibraryFragment>::@class::C::@method::member#element |
| 70 | + staticType: C<dynamic> Function<U>(U) |
| 71 | + typeArguments: TypeArgumentList |
| 72 | + leftBracket: < |
| 73 | + arguments |
| 74 | + NamedType |
| 75 | + name: int |
| 76 | + element2: dart:core::@class::int |
| 77 | + type: int |
| 78 | + rightBracket: > |
| 79 | + argumentList: ArgumentList |
| 80 | + leftParenthesis: ( |
| 81 | + arguments |
| 82 | + IntegerLiteral |
| 83 | + literal: 1 |
| 84 | + correspondingParameter: ParameterMember |
| 85 | + baseElement: <testLibraryFragment>::@class::C::@method::member::@parameter::x#element |
| 86 | + substitution: {U: int} |
| 87 | + staticType: int |
| 88 | + rightParenthesis: ) |
| 89 | + staticInvokeType: C<dynamic> Function(int) |
| 90 | + staticType: C<dynamic> |
| 91 | + typeArgumentTypes |
| 92 | + int |
| 93 | +'''); |
| 94 | + } |
| 95 | + |
| 96 | + test_dotShorthand_basic_parameter() async { |
| 97 | + await assertNoErrorsInCode(r''' |
| 98 | +class C { |
| 99 | + static C member(int x) => C(x); |
| 100 | + int x; |
| 101 | + C(this.x); |
| 102 | +} |
| 103 | +
|
| 104 | +void main() { |
| 105 | + C c = .member(1); |
| 106 | + print(c); |
| 107 | +} |
| 108 | +'''); |
| 109 | + |
| 110 | + var node = findNode.singleDotShorthandInvocation; |
| 111 | + assertResolvedNodeText(node, r''' |
| 112 | +DotShorthandInvocation |
| 113 | + period: . |
| 114 | + memberName: SimpleIdentifier |
| 115 | + token: member |
| 116 | + element: <testLibraryFragment>::@class::C::@method::member#element |
| 117 | + staticType: C Function(int) |
| 118 | + argumentList: ArgumentList |
| 119 | + leftParenthesis: ( |
| 120 | + arguments |
| 121 | + IntegerLiteral |
| 122 | + literal: 1 |
| 123 | + correspondingParameter: <testLibraryFragment>::@class::C::@method::member::@parameter::x#element |
| 124 | + staticType: int |
| 125 | + rightParenthesis: ) |
| 126 | + staticInvokeType: C Function(int) |
| 127 | + staticType: C |
| 128 | +'''); |
| 129 | + } |
| 130 | +} |
0 commit comments