Skip to content

Commit 6994256

Browse files
authored
Add test for a field formal parameter with a default value (dart-lang#2726)
1 parent fbf79d8 commit 6994256

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

test/end2end/model_test.dart

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,8 +2363,7 @@ void main() {
23632363
function1,
23642364
topLevelFunction,
23652365
aFunctionUsingRenamedLib;
2366-
TopLevelVariable aSetterWithFunctionParameter,
2367-
incorrectDocReference,
2366+
TopLevelVariable incorrectDocReference,
23682367
incorrectDocReferenceFromEx,
23692368
nameWithTwoUnderscores,
23702369
nameWithSingleUnderscore,
@@ -2393,14 +2392,12 @@ void main() {
23932392
redHerring,
23942393
yetAnotherName,
23952394
somethingShadowyParameter;
2396-
Parameter fParam, fParamA, fParamB, fParamC;
23972395
Field forInheriting,
23982396
action,
23992397
initializeMe,
24002398
somethingShadowy,
24012399
aConstructorShadowedField,
24022400
aNameField,
2403-
anotherNameField,
24042401
yetAnotherNameField,
24052402
initViaFieldFormal;
24062403

@@ -2506,8 +2503,6 @@ void main() {
25062503

25072504
aNameField = FactoryConstructorThings.allFields
25082505
.firstWhere((f) => f.name == 'aName');
2509-
anotherNameField = FactoryConstructorThings.allFields
2510-
.firstWhere((f) => f.name == 'anotherName');
25112506
yetAnotherNameField = FactoryConstructorThings.allFields
25122507
.firstWhere((f) => f.name == 'yetAnotherName');
25132508
initViaFieldFormal = FactoryConstructorThings.allFields
@@ -2517,24 +2512,24 @@ void main() {
25172512
.firstWhere((m) => m.name == 'aMethod');
25182513
yetAnotherName =
25192514
aMethod.allParameters.firstWhere((p) => p.name == 'yetAnotherName');
2520-
2521-
aSetterWithFunctionParameter = fakeLibrary.properties
2522-
.firstWhere((p) => p.name == 'aSetterWithFunctionParameter');
2523-
fParam = aSetterWithFunctionParameter.parameters
2524-
.firstWhere((p) => p.name == 'fParam');
2525-
fParamA = (fParam.modelType as Callable)
2526-
.parameters
2527-
.firstWhere((p) => p.name == 'fParamA');
2528-
fParamB = (fParam.modelType as Callable)
2529-
.parameters
2530-
.firstWhere((p) => p.name == 'fParamB');
2531-
fParamC = (fParam.modelType as Callable)
2532-
.parameters
2533-
.firstWhere((p) => p.name == 'fParamC');
25342515
});
25352516

25362517
group('Parameter references work properly', () {
25372518
test('via a setter with a function parameter', () {
2519+
var aSetterWithFunctionParameter = fakeLibrary.properties
2520+
.firstWhere((p) => p.name == 'aSetterWithFunctionParameter');
2521+
var fParam = aSetterWithFunctionParameter.parameters
2522+
.firstWhere((p) => p.name == 'fParam');
2523+
var fParamA = (fParam.modelType as Callable)
2524+
.parameters
2525+
.firstWhere((p) => p.name == 'fParamA');
2526+
var fParamB = (fParam.modelType as Callable)
2527+
.parameters
2528+
.firstWhere((p) => p.name == 'fParamB');
2529+
var fParamC = (fParam.modelType as Callable)
2530+
.parameters
2531+
.firstWhere((p) => p.name == 'fParamC');
2532+
25382533
expect(bothLookup(aSetterWithFunctionParameter, 'fParam.fParamA'),
25392534
equals(MatchingLinkResult(fParamA)));
25402535
expect(bothLookup(aSetterWithFunctionParameter, 'fParam.fParamB'),
@@ -2546,6 +2541,8 @@ void main() {
25462541
test('in class scope overridden by fields', () {
25472542
expect(bothLookup(FactoryConstructorThings, 'aName'),
25482543
equals(MatchingLinkResult(aNameField)));
2544+
var anotherNameField = FactoryConstructorThings.allFields
2545+
.firstWhere((f) => f.name == 'anotherName');
25492546
expect(bothLookup(FactoryConstructorThings, 'anotherName'),
25502547
equals(MatchingLinkResult(anotherNameField)));
25512548
expect(bothLookup(FactoryConstructorThings, 'yetAnotherName'),
@@ -2769,6 +2766,14 @@ void main() {
27692766
expect(bothLookup(doAwesomeStuff, 'ExtendedBaseReexported.action'),
27702767
equals(MatchingLinkResult(action)));
27712768
});
2769+
2770+
test('displays default value of field formal parameter', () {
2771+
expect(
2772+
factoryConstructorThingsDefault.linkedParamsLines,
2773+
contains(
2774+
'<span class="parameter-name">fieldFormalWithDefault</span> = '
2775+
'<span class="default-value">7</span>}'));
2776+
});
27722777
});
27732778
});
27742779

testing/test_package/lib/fake.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,10 @@ class FactoryConstructorThings {
12631263
int anotherName;
12641264
String yetAnotherName;
12651265
final List<String> initViaFieldFormal;
1266+
final int fieldFormalWithDefault;
12661267

1267-
FactoryConstructorThings(this.initViaFieldFormal);
1268+
FactoryConstructorThings(this.initViaFieldFormal,
1269+
{this.fieldFormalWithDefault = 7});
12681270

12691271
factory FactoryConstructorThings.anotherName({
12701272
bool aName,

0 commit comments

Comments
 (0)