-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Enum shorthands - Selector chain tests for cascades, ??, coll…
…ections and nested contexts. Tests for nested context types, such as a constructor with an argument that also uses an enum shorthand. Tests for selector chains. Multiple members and properties in one shorthand. Bug: #57038 Change-Id: Ie9609b7594ccbe4347a59026d9e758868015fe64 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402442 Reviewed-by: Lasse Nielsen <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
- Loading branch information
Showing
3 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Nested enum shorthands. | ||
|
||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../enum_shorthand_helper.dart'; | ||
|
||
void main() { | ||
StaticMember<StaticMember> memberMember = .memberType( | ||
.memberType(.member()), | ||
); | ||
|
||
StaticMemberExt<StaticMemberExt> memberMemberExt = .memberType( | ||
.memberType(.member()), | ||
); | ||
|
||
StaticMember<StaticMember> memberCtor = .memberType(.new(.member())); | ||
|
||
StaticMemberExt<StaticMemberExt> memberCtorExt = .memberType( | ||
.new(.member()), | ||
); | ||
|
||
StaticMember<Integer> memberProperty = .property(.one); | ||
|
||
StaticMemberExt<Integer> memberPropertyExt = .property(.one); | ||
|
||
StaticMember<ConstructorClass> memberCtorMember = .ctor( | ||
.staticMember(.member()), | ||
); | ||
|
||
StaticMemberExt<ConstructorClass> memberCtorMemberExt = .ctor( | ||
.staticMemberExt(.member()), | ||
); | ||
|
||
StaticMember<ConstructorClass> memberCtorProperty = .ctor(.integer(.one)); | ||
|
||
ConstructorClass ctorMember = .staticMember(.member()); | ||
|
||
ConstructorClass ctorMemberExt = .staticMemberExt(.member()); | ||
|
||
ConstructorClass ctorProperty = .integer(.one); | ||
|
||
ConstructorClass ctorCtor = .ctor(.new(1)); | ||
|
||
ConstructorClass ctorCtorCtor = .ctor(.ctor(.new(1))); | ||
|
||
ConstructorClass ctorMemberCtor = .staticMember(.ctor(.named(x: 1))); | ||
|
||
ConstructorClass ctorMemberCtorExt = .staticMemberExt(.ctor(.named(x: 1))); | ||
} |
87 changes: 87 additions & 0 deletions
87
tests/language/enum_shorthands/multiple/selector_chain_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Enum shorthands selector chains in collections, cascades, `??` and other | ||
// contexts. | ||
|
||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import 'dart:async'; | ||
|
||
import '../enum_shorthand_helper.dart'; | ||
|
||
class Cascade { | ||
late StaticMember member; | ||
late ConstructorWithNonFinal ctor; | ||
} | ||
|
||
void main() { | ||
StaticMember memberField = .member().field; | ||
StaticMember memberMethod = .member().method(); | ||
StaticMember memberMixed = .member().method().field; | ||
StaticMember memberMixed2 = .member().field.method(); | ||
|
||
ConstructorWithNonFinal ctorField = .new(1).field; | ||
ConstructorWithNonFinal ctorMethod = .new(1).method(); | ||
ConstructorWithNonFinal ctorMixed = | ||
.new(1).method().field; | ||
ConstructorWithNonFinal ctorMixed2 = | ||
.new(1).field.method(); | ||
|
||
// FutureOr | ||
FutureOr<StaticMember> futureOrMember = .member().field.method(); | ||
FutureOr<ConstructorWithNonFinal> futureOrCtor = | ||
.new(1).field.method(); | ||
|
||
// Collection literals | ||
var memberList = <StaticMember>[ | ||
.member().field, | ||
.member().field.method(), | ||
]; | ||
var memberSet = <StaticMember>{ | ||
.member().field, | ||
.member().field.method(), | ||
}; | ||
var memberMap = <StaticMember, StaticMember>{ | ||
.member().field: .member().field, | ||
.member().field.method(): .member().field.method(), | ||
}; | ||
|
||
var ctorList = <ConstructorWithNonFinal>[ | ||
.new(1).field, | ||
.new(1).method().field, | ||
]; | ||
var ctorSet = <ConstructorWithNonFinal>{ | ||
.new(1).field, | ||
.new(1).method().field, | ||
}; | ||
var ctorMap = <ConstructorWithNonFinal, ConstructorWithNonFinal>{ | ||
.new(1).field: .new(1).field, | ||
.new(1).method().field: | ||
.new(1).method().field, | ||
}; | ||
|
||
// Cascades | ||
Cascade() | ||
..member = .member().field.method() | ||
..ctor = .new(1).method().field; | ||
|
||
StaticMember memberCascade = .member().field.method()..toString(); | ||
ConstructorWithNonFinal ctorCascade = | ||
.new(1).method().field..toString(); | ||
|
||
// If-null | ||
StaticMember? staticMemberNull = null as StaticMember?; | ||
StaticMember ifNullMember = | ||
staticMemberNull ?? .member().field.method(); | ||
StaticMember ifNullMember2 = | ||
.member().field.methodNullable() ?? .member(); | ||
|
||
ConstructorWithNonFinal? ctorNull = null as ConstructorWithNonFinal?; | ||
ConstructorWithNonFinal ifNullCtor = | ||
ctorNull ?? .new(1).method().field; | ||
ConstructorWithNonFinal ifNullCtor2 = | ||
.new(1).method().field.methodNullable() ?? | ||
ConstructorWithNonFinal(1); | ||
} |