Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
17a27358
Unverified
Commit
17a27358
authored
Mar 14, 2024
by
Nate
Committed by
GitHub
Mar 14, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implementing switch expressions in `flutter/test/` (#144580)
Migrates test code to new `switch` syntax.
parent
dff03432
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
115 additions
and
189 deletions
+115
-189
route_test.dart
packages/flutter/test/cupertino/route_test.dart
+8
-15
dropdown_menu_test.dart
packages/flutter/test/material/dropdown_menu_test.dart
+4
-11
viewport_test.dart
packages/flutter/test/rendering/viewport_test.dart
+4
-6
fake_platform_views.dart
packages/flutter/test/services/fake_platform_views.dart
+24
-39
raw_keyboard_test.dart
packages/flutter/test/services/raw_keyboard_test.dart
+18
-32
dismissible_test.dart
packages/flutter/test/widgets/dismissible_test.dart
+18
-33
html_element_view_test.dart
packages/flutter/test/widgets/html_element_view_test.dart
+5
-7
image_resolution_test.dart
packages/flutter/test/widgets/image_resolution_test.dart
+10
-17
page_forward_transitions_test.dart
...s/flutter/test/widgets/page_forward_transitions_test.dart
+4
-6
render_object_widget_test.dart
packages/flutter/test/widgets/render_object_widget_test.dart
+4
-7
slotted_render_object_widget_test.dart
...utter/test/widgets/slotted_render_object_widget_test.dart
+5
-8
text_selection_test.dart
packages/flutter/test/widgets/text_selection_test.dart
+11
-8
No files found.
packages/flutter/test/cupertino/route_test.dart
View file @
17a27358
...
...
@@ -2662,21 +2662,14 @@ class _TestPostRouteCancelState extends State<_TestPostRouteCancel> {
Widget
build
(
BuildContext
context
)
{
return
CupertinoApp
(
initialRoute:
'home'
,
onGenerateRoute:
(
RouteSettings
settings
)
{
return
CupertinoPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
{
switch
(
settings
.
name
)
{
case
'home'
:
return
_buildHome
(
context
);
case
'sub'
:
return
_buildSub
(
context
);
default
:
throw
UnimplementedError
();
}
},
);
},
onGenerateRoute:
(
RouteSettings
settings
)
=>
CupertinoPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
=>
switch
(
settings
.
name
)
{
'home'
=>
_buildHome
(
context
),
'sub'
=>
_buildSub
(
context
),
_
=>
throw
UnimplementedError
(),
},
),
);
}
}
...
...
packages/flutter/test/material/dropdown_menu_test.dart
View file @
17a27358
...
...
@@ -1119,17 +1119,10 @@ void main() {
await
tester
.
tap
(
find
.
byType
(
DropdownMenu
<
TestMenu
>));
await
tester
.
pump
();
late
final
bool
isMobile
;
switch
(
themeData
.
platform
)
{
case
TargetPlatform
.
android
:
case
TargetPlatform
.
iOS
:
case
TargetPlatform
.
fuchsia
:
isMobile
=
true
;
case
TargetPlatform
.
macOS
:
case
TargetPlatform
.
linux
:
case
TargetPlatform
.
windows
:
isMobile
=
false
;
}
final
bool
isMobile
=
switch
(
themeData
.
platform
)
{
TargetPlatform
.
android
||
TargetPlatform
.
iOS
||
TargetPlatform
.
fuchsia
=>
true
,
TargetPlatform
.
macOS
||
TargetPlatform
.
linux
||
TargetPlatform
.
windows
=>
false
,
};
int
expectedCount
=
isMobile
?
0
:
1
;
// Test onSelected on key press
...
...
packages/flutter/test/rendering/viewport_test.dart
View file @
17a27358
...
...
@@ -1259,12 +1259,10 @@ void main() {
}
final
RenderBox
renderBox
=
renderObject
as
RenderBox
;
switch
(
axis
)
{
case
Axis
.
horizontal
:
return
renderBox
.
size
.
width
;
case
Axis
.
vertical
:
return
renderBox
.
size
.
height
;
}
return
switch
(
axis
)
{
Axis
.
horizontal
=>
renderBox
.
size
.
width
,
Axis
.
vertical
=>
renderBox
.
size
.
height
,
};
}
group
(
'animated:
$animated
, scrollDirection:
$axis
'
,
()
{
...
...
packages/flutter/test/services/fake_platform_views.dart
View file @
17a27358
...
...
@@ -188,23 +188,16 @@ class FakeAndroidPlatformViewsController {
}
Future
<
dynamic
>
_onMethodCall
(
MethodCall
call
)
{
switch
(
call
.
method
)
{
case
'create'
:
return
_create
(
call
);
case
'dispose'
:
return
_dispose
(
call
);
case
'resize'
:
return
_resize
(
call
);
case
'touch'
:
return
_touch
(
call
);
case
'setDirection'
:
return
_setDirection
(
call
);
case
'clearFocus'
:
return
_clearFocus
(
call
);
case
'offset'
:
return
_offset
(
call
);
}
return
Future
<
dynamic
>.
sync
(()
=>
null
);
return
switch
(
call
.
method
)
{
'create'
=>
_create
(
call
),
'dispose'
=>
_dispose
(
call
),
'resize'
=>
_resize
(
call
),
'touch'
=>
_touch
(
call
),
'setDirection'
=>
_setDirection
(
call
),
'clearFocus'
=>
_clearFocus
(
call
),
'offset'
=>
_offset
(
call
),
_
=>
Future
<
dynamic
>.
sync
(()
=>
null
),
};
}
Future
<
dynamic
>
_create
(
MethodCall
call
)
async
{
...
...
@@ -400,17 +393,13 @@ class FakeIosPlatformViewsController {
}
Future
<
dynamic
>
_onMethodCall
(
MethodCall
call
)
{
switch
(
call
.
method
)
{
case
'create'
:
return
_create
(
call
);
case
'dispose'
:
return
_dispose
(
call
);
case
'acceptGesture'
:
return
_acceptGesture
(
call
);
case
'rejectGesture'
:
return
_rejectGesture
(
call
);
}
return
Future
<
dynamic
>.
sync
(()
=>
null
);
return
switch
(
call
.
method
)
{
'create'
=>
_create
(
call
),
'dispose'
=>
_dispose
(
call
),
'acceptGesture'
=>
_acceptGesture
(
call
),
'rejectGesture'
=>
_rejectGesture
(
call
),
_
=>
Future
<
dynamic
>.
sync
(()
=>
null
),
};
}
Future
<
dynamic
>
_create
(
MethodCall
call
)
async
{
...
...
@@ -503,17 +492,13 @@ class FakeMacosPlatformViewsController {
}
Future
<
dynamic
>
_onMethodCall
(
MethodCall
call
)
{
switch
(
call
.
method
)
{
case
'create'
:
return
_create
(
call
);
case
'dispose'
:
return
_dispose
(
call
);
case
'acceptGesture'
:
return
_acceptGesture
(
call
);
case
'rejectGesture'
:
return
_rejectGesture
(
call
);
}
return
Future
<
dynamic
>.
sync
(()
=>
null
);
return
switch
(
call
.
method
)
{
'create'
=>
_create
(
call
),
'dispose'
=>
_dispose
(
call
),
'acceptGesture'
=>
_acceptGesture
(
call
),
'rejectGesture'
=>
_rejectGesture
(
call
),
_
=>
Future
<
dynamic
>.
sync
(()
=>
null
),
};
}
Future
<
dynamic
>
_create
(
MethodCall
call
)
async
{
...
...
packages/flutter/test/services/raw_keyboard_test.dart
View file @
17a27358
...
...
@@ -2241,22 +2241,15 @@ void main() {
// How modifiers are interpreted depends upon the keyCode for GLFW.
int
keyCodeForModifier
(
int
modifier
,
{
required
bool
isLeft
})
{
switch
(
modifier
)
{
case
GLFWKeyHelper
.
modifierAlt
:
return
isLeft
?
342
:
346
;
case
GLFWKeyHelper
.
modifierShift
:
return
isLeft
?
340
:
344
;
case
GLFWKeyHelper
.
modifierControl
:
return
isLeft
?
341
:
345
;
case
GLFWKeyHelper
.
modifierMeta
:
return
isLeft
?
343
:
347
;
case
GLFWKeyHelper
.
modifierNumericPad
:
return
282
;
case
GLFWKeyHelper
.
modifierCapsLock
:
return
280
;
default
:
return
65
;
// keyA
}
return
switch
(
modifier
)
{
GLFWKeyHelper
.
modifierAlt
=>
isLeft
?
342
:
346
,
GLFWKeyHelper
.
modifierShift
=>
isLeft
?
340
:
344
,
GLFWKeyHelper
.
modifierControl
=>
isLeft
?
341
:
345
,
GLFWKeyHelper
.
modifierMeta
=>
isLeft
?
343
:
347
,
GLFWKeyHelper
.
modifierNumericPad
=>
282
,
GLFWKeyHelper
.
modifierCapsLock
=>
280
,
_
=>
65
,
// keyA
};
}
test
(
'modifier keys are recognized individually'
,
()
{
...
...
@@ -2473,22 +2466,15 @@ void main() {
// How modifiers are interpreted depends upon the keyCode for GTK.
int
keyCodeForModifier
(
int
modifier
,
{
required
bool
isLeft
})
{
switch
(
modifier
)
{
case
GtkKeyHelper
.
modifierMod1
:
return
65513
;
case
GtkKeyHelper
.
modifierShift
:
return
isLeft
?
65505
:
65506
;
case
GtkKeyHelper
.
modifierControl
:
return
isLeft
?
65507
:
65508
;
case
GtkKeyHelper
.
modifierMeta
:
return
isLeft
?
65515
:
65516
;
case
GtkKeyHelper
.
modifierMod2
:
return
65407
;
case
GtkKeyHelper
.
modifierCapsLock
:
return
65509
;
default
:
return
65
;
// keyA
}
return
switch
(
modifier
)
{
GtkKeyHelper
.
modifierShift
=>
isLeft
?
65505
:
65506
,
GtkKeyHelper
.
modifierControl
=>
isLeft
?
65507
:
65508
,
GtkKeyHelper
.
modifierMeta
=>
isLeft
?
65515
:
65516
,
GtkKeyHelper
.
modifierMod1
=>
65513
,
GtkKeyHelper
.
modifierMod2
=>
65407
,
GtkKeyHelper
.
modifierCapsLock
=>
65509
,
_
=>
65
,
// keyA
};
}
test
(
'modifier keys are recognized individually'
,
()
{
...
...
packages/flutter/test/widgets/dismissible_test.dart
View file @
17a27358
...
...
@@ -119,32 +119,22 @@ Future<void> dismissElement(WidgetTester tester, Finder finder, { required AxisD
}
Future
<
void
>
dragElement
(
WidgetTester
tester
,
Finder
finder
,
{
required
AxisDirection
gestureDirection
,
required
double
amount
})
async
{
Offset
delta
;
switch
(
gestureDirection
)
{
case
AxisDirection
.
left
:
delta
=
Offset
(-
amount
,
0.0
);
case
AxisDirection
.
right
:
delta
=
Offset
(
amount
,
0.0
);
case
AxisDirection
.
up
:
delta
=
Offset
(
0.0
,
-
amount
);
case
AxisDirection
.
down
:
delta
=
Offset
(
0.0
,
amount
);
}
final
Offset
delta
=
switch
(
gestureDirection
)
{
AxisDirection
.
left
=>
Offset
(-
amount
,
0.0
),
AxisDirection
.
right
=>
Offset
(
amount
,
0.0
),
AxisDirection
.
up
=>
Offset
(
0.0
,
-
amount
),
AxisDirection
.
down
=>
Offset
(
0.0
,
amount
),
};
await
tester
.
drag
(
finder
,
delta
);
}
Future
<
void
>
flingElement
(
WidgetTester
tester
,
Finder
finder
,
{
required
AxisDirection
gestureDirection
,
double
initialOffsetFactor
=
0.0
})
async
{
Offset
delta
;
switch
(
gestureDirection
)
{
case
AxisDirection
.
left
:
delta
=
const
Offset
(-
300.0
,
0.0
);
case
AxisDirection
.
right
:
delta
=
const
Offset
(
300.0
,
0.0
);
case
AxisDirection
.
up
:
delta
=
const
Offset
(
0.0
,
-
300.0
);
case
AxisDirection
.
down
:
delta
=
const
Offset
(
0.0
,
300.0
);
}
final
Offset
delta
=
switch
(
gestureDirection
)
{
AxisDirection
.
left
=>
const
Offset
(-
300
,
0.0
),
AxisDirection
.
right
=>
const
Offset
(
300
,
0.0
),
AxisDirection
.
up
=>
const
Offset
(
0.0
,
-
300
),
AxisDirection
.
down
=>
const
Offset
(
0.0
,
300
),
};
await
tester
.
fling
(
finder
,
delta
,
1000.0
,
initialOffset:
delta
*
initialOffsetFactor
);
}
...
...
@@ -213,17 +203,12 @@ Future<void> checkFlingItemAfterMovement(
}
Future
<
void
>
rollbackElement
(
WidgetTester
tester
,
Finder
finder
,
{
required
AxisDirection
gestureDirection
,
double
initialOffsetFactor
=
0.0
})
async
{
Offset
delta
;
switch
(
gestureDirection
)
{
case
AxisDirection
.
left
:
delta
=
const
Offset
(-
30.0
,
0.0
);
case
AxisDirection
.
right
:
delta
=
const
Offset
(
30.0
,
0.0
);
case
AxisDirection
.
up
:
delta
=
const
Offset
(
0.0
,
-
30.0
);
case
AxisDirection
.
down
:
delta
=
const
Offset
(
0.0
,
30.0
);
}
final
Offset
delta
=
switch
(
gestureDirection
)
{
AxisDirection
.
left
=>
const
Offset
(-
30.0
,
0.0
),
AxisDirection
.
right
=>
const
Offset
(
30.0
,
0.0
),
AxisDirection
.
up
=>
const
Offset
(
0.0
,
-
30.0
),
AxisDirection
.
down
=>
const
Offset
(
0.0
,
30.0
),
};
await
tester
.
fling
(
finder
,
delta
,
1000.0
,
initialOffset:
delta
*
initialOffsetFactor
);
}
...
...
packages/flutter/test/widgets/html_element_view_test.dart
View file @
17a27358
...
...
@@ -442,13 +442,11 @@ class FakePlatformViewRegistry implements ui_web.PlatformViewRegistry {
}
Future
<
dynamic
>
_onMethodCall
(
MethodCall
call
)
{
switch
(
call
.
method
)
{
case
'create'
:
return
_create
(
call
);
case
'dispose'
:
return
_dispose
(
call
);
}
return
Future
<
dynamic
>.
sync
(()
=>
null
);
return
switch
(
call
.
method
)
{
'create'
=>
_create
(
call
),
'dispose'
=>
_dispose
(
call
),
_
=>
Future
<
dynamic
>.
sync
(()
=>
null
),
};
}
Future
<
dynamic
>
_create
(
MethodCall
call
)
async
{
...
...
packages/flutter/test/widgets/image_resolution_test.dart
View file @
17a27358
...
...
@@ -38,23 +38,16 @@ class TestAssetBundle extends CachingAssetBundle {
@override
Future
<
ByteData
>
load
(
String
key
)
{
late
ByteData
data
;
switch
(
key
)
{
case
'AssetManifest.bin'
:
data
=
manifest
;
case
'assets/image.png'
:
data
=
testByteData
(
1.0
);
case
'assets/1.0x/image.png'
:
data
=
testByteData
(
10.0
);
// see "...with a main asset and a 1.0x asset"
case
'assets/1.5x/image.png'
:
data
=
testByteData
(
1.5
);
case
'assets/2.0x/image.png'
:
data
=
testByteData
(
2.0
);
case
'assets/3.0x/image.png'
:
data
=
testByteData
(
3.0
);
case
'assets/4.0x/image.png'
:
data
=
testByteData
(
4.0
);
}
final
ByteData
data
=
switch
(
key
)
{
'AssetManifest.bin'
=>
manifest
,
'assets/image.png'
=>
testByteData
(
1.0
),
'assets/1.0x/image.png'
=>
testByteData
(
10.0
),
// see "...with a main asset and a 1.0x asset"
'assets/1.5x/image.png'
=>
testByteData
(
1.5
),
'assets/2.0x/image.png'
=>
testByteData
(
2.0
),
'assets/3.0x/image.png'
=>
testByteData
(
3.0
),
'assets/4.0x/image.png'
=>
testByteData
(
4.0
),
_
=>
throw
ArgumentError
(
'Unexpected key:
$key
'
),
};
return
SynchronousFuture
<
ByteData
>(
data
);
}
...
...
packages/flutter/test/widgets/page_forward_transitions_test.dart
View file @
17a27358
...
...
@@ -199,12 +199,10 @@ void main() {
testWidgets
(
'Check onstage/offstage handling of barriers around transitions'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
onGenerateRoute:
(
RouteSettings
settings
)
{
switch
(
settings
.
name
)
{
case
'/'
:
return
TestRoute
<
void
>(
settings:
settings
,
child:
const
Text
(
'A'
));
case
'/1'
:
return
TestRoute
<
void
>(
settings:
settings
,
barrierColor:
const
Color
(
0xFFFFFF00
),
child:
const
Text
(
'B'
));
}
return
null
;
onGenerateRoute:
(
RouteSettings
settings
)
=>
switch
(
settings
.
name
)
{
'/'
=>
TestRoute
<
void
>(
settings:
settings
,
child:
const
Text
(
'A'
)),
'/1'
=>
TestRoute
<
void
>(
settings:
settings
,
barrierColor:
const
Color
(
0xFFFFFF00
),
child:
const
Text
(
'B'
)),
_
=>
null
,
},
),
);
...
...
packages/flutter/test/widgets/render_object_widget_test.dart
View file @
17a27358
...
...
@@ -26,13 +26,10 @@ class TestOrientedBox extends SingleChildRenderObjectWidget {
const
TestOrientedBox
({
super
.
key
,
super
.
child
});
Decoration
_getDecoration
(
BuildContext
context
)
{
final
Orientation
orientation
=
MediaQuery
.
orientationOf
(
context
);
switch
(
orientation
)
{
case
Orientation
.
landscape
:
return
const
BoxDecoration
(
color:
Color
(
0xFF00FF00
));
case
Orientation
.
portrait
:
return
const
BoxDecoration
(
color:
Color
(
0xFF0000FF
));
}
return
switch
(
MediaQuery
.
orientationOf
(
context
))
{
Orientation
.
landscape
=>
const
BoxDecoration
(
color:
Color
(
0xFF00FF00
)),
Orientation
.
portrait
=>
const
BoxDecoration
(
color:
Color
(
0xFF0000FF
)),
};
}
@override
...
...
packages/flutter/test/widgets/slotted_render_object_widget_test.dart
View file @
17a27358
...
...
@@ -286,14 +286,11 @@ class _Diagonal extends RenderObjectWidget with SlottedMultiChildRenderObjectWid
@override
Widget
?
childForSlot
(
_DiagonalSlot
?
slot
)
{
switch
(
slot
)
{
case
null
:
return
nullSlot
;
case
_DiagonalSlot
.
topLeft
:
return
topLeft
;
case
_DiagonalSlot
.
bottomRight
:
return
bottomRight
;
}
return
switch
(
slot
)
{
null
=>
nullSlot
,
_DiagonalSlot
.
topLeft
=>
topLeft
,
_DiagonalSlot
.
bottomRight
=>
bottomRight
,
};
}
@override
...
...
packages/flutter/test/widgets/text_selection_test.dart
View file @
17a27358
...
...
@@ -2008,14 +2008,17 @@ class TextSelectionControlsSpy extends TextSelectionControls {
@override
Widget
buildHandle
(
BuildContext
context
,
TextSelectionHandleType
type
,
double
textLineHeight
,
[
VoidCallback
?
onTap
])
{
switch
(
type
)
{
case
TextSelectionHandleType
.
left
:
return
ElevatedButton
(
onPressed:
onTap
,
child:
Text
(
'height
${textLineHeight.toInt()}
'
,
key:
leftHandleKey
));
case
TextSelectionHandleType
.
right
:
return
ElevatedButton
(
onPressed:
onTap
,
child:
Text
(
'height
${textLineHeight.toInt()}
'
,
key:
rightHandleKey
));
case
TextSelectionHandleType
.
collapsed
:
return
ElevatedButton
(
onPressed:
onTap
,
child:
Text
(
'height
${textLineHeight.toInt()}
'
,
key:
collapsedHandleKey
));
}
return
ElevatedButton
(
onPressed:
onTap
,
child:
Text
(
key:
switch
(
type
)
{
TextSelectionHandleType
.
left
=>
leftHandleKey
,
TextSelectionHandleType
.
right
=>
rightHandleKey
,
TextSelectionHandleType
.
collapsed
=>
collapsedHandleKey
,
},
'height
${textLineHeight.toInt()}
'
,
),
);
}
@override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment