From 20f029e3bce5213dc93394a73bbbedf4633f2469 Mon Sep 17 00:00:00 2001 From: Phil Quitslund Date: Tue, 3 May 2022 10:29:06 -0700 Subject: [PATCH] [devicelab, flutter_test, ...] rename local functions with `_`s (#102833) --- dev/devicelab/lib/tasks/microbenchmarks.dart | 36 +++--- .../flutter/test/material/app_bar_test.dart | 28 ++--- .../test/material/date_picker_test.dart | 10 +- .../flutter_test/lib/src/accessibility.dart | 4 +- .../lib/src/event_simulation.dart | 18 +-- .../flutter_test/test/accessibility_test.dart | 106 +++++++++--------- 6 files changed, 101 insertions(+), 101 deletions(-) diff --git a/dev/devicelab/lib/tasks/microbenchmarks.dart b/dev/devicelab/lib/tasks/microbenchmarks.dart index 0418861923..c36c1ed982 100644 --- a/dev/devicelab/lib/tasks/microbenchmarks.dart +++ b/dev/devicelab/lib/tasks/microbenchmarks.dart @@ -21,8 +21,8 @@ TaskFunction createMicrobenchmarkTask() { await device.unlock(); await device.clearLogs(); - Future> _runMicrobench(String benchmarkPath) async { - Future> _run() async { + Future> runMicrobench(String benchmarkPath) async { + Future> run() async { print('Running $benchmarkPath'); final Directory appDir = dir( path.join(flutterDirectory.path, 'dev/benchmarks/microbenchmarks')); @@ -45,25 +45,25 @@ TaskFunction createMicrobenchmarkTask() { return readJsonResults(flutterProcess); } - return _run(); + return run(); } final Map allResults = { - ...await _runMicrobench('lib/stocks/layout_bench.dart'), - ...await _runMicrobench('lib/stocks/build_bench.dart'), - ...await _runMicrobench('lib/geometry/matrix_utils_transform_bench.dart'), - ...await _runMicrobench('lib/geometry/rrect_contains_bench.dart'), - ...await _runMicrobench('lib/gestures/velocity_tracker_bench.dart'), - ...await _runMicrobench('lib/gestures/gesture_detector_bench.dart'), - ...await _runMicrobench('lib/stocks/animation_bench.dart'), - ...await _runMicrobench('lib/language/compute_bench.dart'), - ...await _runMicrobench('lib/language/sync_star_bench.dart'), - ...await _runMicrobench('lib/language/sync_star_semantics_bench.dart'), - ...await _runMicrobench('lib/foundation/all_elements_bench.dart'), - ...await _runMicrobench('lib/foundation/change_notifier_bench.dart'), - ...await _runMicrobench('lib/foundation/standard_method_codec_bench.dart'), - ...await _runMicrobench('lib/foundation/standard_message_codec_bench.dart'), - ...await _runMicrobench('lib/foundation/timeline_bench.dart'), + ...await runMicrobench('lib/stocks/layout_bench.dart'), + ...await runMicrobench('lib/stocks/build_bench.dart'), + ...await runMicrobench('lib/geometry/matrix_utils_transform_bench.dart'), + ...await runMicrobench('lib/geometry/rrect_contains_bench.dart'), + ...await runMicrobench('lib/gestures/velocity_tracker_bench.dart'), + ...await runMicrobench('lib/gestures/gesture_detector_bench.dart'), + ...await runMicrobench('lib/stocks/animation_bench.dart'), + ...await runMicrobench('lib/language/compute_bench.dart'), + ...await runMicrobench('lib/language/sync_star_bench.dart'), + ...await runMicrobench('lib/language/sync_star_semantics_bench.dart'), + ...await runMicrobench('lib/foundation/all_elements_bench.dart'), + ...await runMicrobench('lib/foundation/change_notifier_bench.dart'), + ...await runMicrobench('lib/foundation/standard_method_codec_bench.dart'), + ...await runMicrobench('lib/foundation/standard_message_codec_bench.dart'), + ...await runMicrobench('lib/foundation/timeline_bench.dart'), }; return TaskResult.success(allResults, diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index 089684736f..635e17c694 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -2636,7 +2636,7 @@ void main() { } group('SliverAppBar', () { - Widget _buildSliverApp({ + Widget buildSliverApp({ required double contentHeight, bool reverse = false, bool includeFlexibleSpace = false, @@ -2674,7 +2674,7 @@ void main() { testWidgets('backgroundColor', (WidgetTester tester) async { await tester.pumpWidget( - _buildSliverApp(contentHeight: 1200.0) + buildSliverApp(contentHeight: 1200.0) ); expect(getAppBarBackgroundColor(tester), defaultColor); @@ -2699,7 +2699,7 @@ void main() { testWidgets('backgroundColor with FlexibleSpace', (WidgetTester tester) async { await tester.pumpWidget( - _buildSliverApp(contentHeight: 1200.0, includeFlexibleSpace: true) + buildSliverApp(contentHeight: 1200.0, includeFlexibleSpace: true) ); expect(getAppBarBackgroundColor(tester), defaultColor); @@ -2724,7 +2724,7 @@ void main() { testWidgets('backgroundColor - reverse', (WidgetTester tester) async { await tester.pumpWidget( - _buildSliverApp(contentHeight: 1200.0, reverse: true) + buildSliverApp(contentHeight: 1200.0, reverse: true) ); expect(getAppBarBackgroundColor(tester), defaultColor); @@ -2749,7 +2749,7 @@ void main() { testWidgets('backgroundColor with FlexibleSpace - reverse', (WidgetTester tester) async { await tester.pumpWidget( - _buildSliverApp( + buildSliverApp( contentHeight: 1200.0, reverse: true, includeFlexibleSpace: true, @@ -2778,7 +2778,7 @@ void main() { testWidgets('backgroundColor - not triggered in reverse for short content', (WidgetTester tester) async { await tester.pumpWidget( - _buildSliverApp(contentHeight: 200, reverse: true) + buildSliverApp(contentHeight: 200, reverse: true) ); // In reverse, the content here is not long enough to scroll under the app @@ -2797,7 +2797,7 @@ void main() { testWidgets('backgroundColor with FlexibleSpace - not triggered in reverse for short content', (WidgetTester tester) async { await tester.pumpWidget( - _buildSliverApp( + buildSliverApp( contentHeight: 200, reverse: true, includeFlexibleSpace: true, @@ -2820,7 +2820,7 @@ void main() { }); group('AppBar', () { - Widget _buildAppBar({ + Widget buildAppBar({ required double contentHeight, bool reverse = false, bool includeFlexibleSpace = false @@ -2851,7 +2851,7 @@ void main() { testWidgets('backgroundColor', (WidgetTester tester) async { await tester.pumpWidget( - _buildAppBar(contentHeight: 1200.0) + buildAppBar(contentHeight: 1200.0) ); expect(getAppBarBackgroundColor(tester), defaultColor); @@ -2876,7 +2876,7 @@ void main() { testWidgets('backgroundColor with FlexibleSpace', (WidgetTester tester) async { await tester.pumpWidget( - _buildAppBar(contentHeight: 1200.0, includeFlexibleSpace: true) + buildAppBar(contentHeight: 1200.0, includeFlexibleSpace: true) ); expect(getAppBarBackgroundColor(tester), defaultColor); @@ -2901,7 +2901,7 @@ void main() { testWidgets('backgroundColor - reverse', (WidgetTester tester) async { await tester.pumpWidget( - _buildAppBar(contentHeight: 1200.0, reverse: true) + buildAppBar(contentHeight: 1200.0, reverse: true) ); await tester.pump(); @@ -2929,7 +2929,7 @@ void main() { testWidgets('backgroundColor with FlexibleSpace - reverse', (WidgetTester tester) async { await tester.pumpWidget( - _buildAppBar( + buildAppBar( contentHeight: 1200.0, reverse: true, includeFlexibleSpace: true, @@ -3027,7 +3027,7 @@ void main() { testWidgets('backgroundColor - not triggered in reverse for short content', (WidgetTester tester) async { await tester.pumpWidget( - _buildAppBar( + buildAppBar( contentHeight: 200.0, reverse: true, ) @@ -3050,7 +3050,7 @@ void main() { testWidgets('backgroundColor with FlexibleSpace - not triggered in reverse for short content', (WidgetTester tester) async { await tester.pumpWidget( - _buildAppBar( + buildAppBar( contentHeight: 200.0, reverse: true, includeFlexibleSpace: true, diff --git a/packages/flutter_localizations/test/material/date_picker_test.dart b/packages/flutter_localizations/test/material/date_picker_test.dart index bcbe59deb0..8487026c0c 100644 --- a/packages/flutter_localizations/test/material/date_picker_test.dart +++ b/packages/flutter_localizations/test/material/date_picker_test.dart @@ -226,7 +226,7 @@ void main() { const Size kCommonScreenSizePortrait = Size(1070, 1770); const Size kCommonScreenSizeLandscape = Size(1770, 1070); - Future _showPicker(WidgetTester tester, Locale locale, Size size) async { + Future showPicker(WidgetTester tester, Locale locale, Size size) async { tester.binding.window.physicalSizeTestValue = size; addTearDown(tester.binding.window.clearPhysicalSizeTestValue); tester.binding.window.devicePixelRatioTestValue = 1.0; @@ -260,22 +260,22 @@ void main() { // Regression test for https://github.com/flutter/flutter/issues/20171 testWidgets('common screen size - portrait - Chinese', (WidgetTester tester) async { - await _showPicker(tester, const Locale('zh', 'CN'), kCommonScreenSizePortrait); + await showPicker(tester, const Locale('zh', 'CN'), kCommonScreenSizePortrait); expect(tester.takeException(), isNull); }); testWidgets('common screen size - landscape - Chinese', (WidgetTester tester) async { - await _showPicker(tester, const Locale('zh', 'CN'), kCommonScreenSizeLandscape); + await showPicker(tester, const Locale('zh', 'CN'), kCommonScreenSizeLandscape); expect(tester.takeException(), isNull); }); testWidgets('common screen size - portrait - Japanese', (WidgetTester tester) async { - await _showPicker(tester, const Locale('ja', 'JA'), kCommonScreenSizePortrait); + await showPicker(tester, const Locale('ja', 'JA'), kCommonScreenSizePortrait); expect(tester.takeException(), isNull); }); testWidgets('common screen size - landscape - Japanese', (WidgetTester tester) async { - await _showPicker(tester, const Locale('ja', 'JA'), kCommonScreenSizeLandscape); + await showPicker(tester, const Locale('ja', 'JA'), kCommonScreenSizeLandscape); expect(tester.takeException(), isNull); }); }); diff --git a/packages/flutter_test/lib/src/accessibility.dart b/packages/flutter_test/lib/src/accessibility.dart index f23c589b81..32fb119e5b 100644 --- a/packages/flutter_test/lib/src/accessibility.dart +++ b/packages/flutter_test/lib/src/accessibility.dart @@ -638,7 +638,7 @@ Map _colorsWithinRect( final Map rgbaToCount = {}; - int _getPixel(ByteData data, int x, int y) { + int getPixel(ByteData data, int x, int y) { final int offset = (y * width + x) * 4; return data.getUint32(offset); } @@ -646,7 +646,7 @@ Map _colorsWithinRect( for (int x = leftX; x < rightX; x++) { for (int y = topY; y < bottomY; y++) { rgbaToCount.update( - _getPixel(data, x, y), + getPixel(data, x, y), (int count) => count + 1, ifAbsent: () => 1, ); diff --git a/packages/flutter_test/lib/src/event_simulation.dart b/packages/flutter_test/lib/src/event_simulation.dart index 92ccb7e7f9..2c241df136 100644 --- a/packages/flutter_test/lib/src/event_simulation.dart +++ b/packages/flutter_test/lib/src/event_simulation.dart @@ -757,7 +757,7 @@ class KeyEventSimulator { PhysicalKeyboardKey? physicalKey, String? character, }) async { - Future _simulateByRawEvent() { + Future simulateByRawEvent() { return _simulateKeyEventByRawEvent(() { platform ??= _defaultPlatform; return getKeyData(key, platform: platform!, physicalKey: physicalKey, character: character); @@ -765,7 +765,7 @@ class KeyEventSimulator { } switch (_transitMode) { case KeyDataTransitMode.rawKeyData: - return _simulateByRawEvent(); + return simulateByRawEvent(); case KeyDataTransitMode.keyDataThenRawKeyData: final LogicalKeyboardKey logicalKey = _getKeySynonym(key); final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData( @@ -778,7 +778,7 @@ class KeyEventSimulator { synthesized: false, ), ); - return (await _simulateByRawEvent()) || resultByKeyEvent; + return (await simulateByRawEvent()) || resultByKeyEvent; } } @@ -802,7 +802,7 @@ class KeyEventSimulator { String? platform, PhysicalKeyboardKey? physicalKey, }) async { - Future _simulateByRawEvent() { + Future simulateByRawEvent() { return _simulateKeyEventByRawEvent(() { platform ??= _defaultPlatform; return getKeyData(key, platform: platform!, isDown: false, physicalKey: physicalKey); @@ -810,7 +810,7 @@ class KeyEventSimulator { } switch (_transitMode) { case KeyDataTransitMode.rawKeyData: - return _simulateByRawEvent(); + return simulateByRawEvent(); case KeyDataTransitMode.keyDataThenRawKeyData: final LogicalKeyboardKey logicalKey = _getKeySynonym(key); final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData( @@ -823,7 +823,7 @@ class KeyEventSimulator { synthesized: false, ), ); - return (await _simulateByRawEvent()) || resultByKeyEvent; + return (await simulateByRawEvent()) || resultByKeyEvent; } } @@ -848,7 +848,7 @@ class KeyEventSimulator { PhysicalKeyboardKey? physicalKey, String? character, }) async { - Future _simulateByRawEvent() { + Future simulateByRawEvent() { return _simulateKeyEventByRawEvent(() { platform ??= _defaultPlatform; return getKeyData(key, platform: platform!, physicalKey: physicalKey, character: character); @@ -856,7 +856,7 @@ class KeyEventSimulator { } switch (_transitMode) { case KeyDataTransitMode.rawKeyData: - return _simulateByRawEvent(); + return simulateByRawEvent(); case KeyDataTransitMode.keyDataThenRawKeyData: final LogicalKeyboardKey logicalKey = _getKeySynonym(key); final bool resultByKeyEvent = ServicesBinding.instance.keyEventManager.handleKeyData( @@ -869,7 +869,7 @@ class KeyEventSimulator { synthesized: false, ), ); - return (await _simulateByRawEvent()) || resultByKeyEvent; + return (await simulateByRawEvent()) || resultByKeyEvent; } } } diff --git a/packages/flutter_test/test/accessibility_test.dart b/packages/flutter_test/test/accessibility_test.dart index 8876758b4f..cadb26a526 100644 --- a/packages/flutter_test/test/accessibility_test.dart +++ b/packages/flutter_test/test/accessibility_test.dart @@ -59,14 +59,14 @@ void main() { TextStyle(color: blue29, backgroundColor: surface, fontSize: 18), ]; - Widget _appWithTextWidget(TextStyle style) => _boilerplate( + Widget appWithTextWidget(TextStyle style) => _boilerplate( Text('this is text', style: style.copyWith(height: 30.0)), ); for (final TextStyle style in textStylesMeetingGuideline) { testWidgets('text with style $style', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - await tester.pumpWidget(_appWithTextWidget(style)); + await tester.pumpWidget(appWithTextWidget(style)); await expectLater(tester, meetsGuideline(textContrastGuideline)); handle.dispose(); }); @@ -75,7 +75,7 @@ void main() { for (final TextStyle style in textStylesDoesNotMeetingGuideline) { testWidgets('text with $style', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - await tester.pumpWidget(_appWithTextWidget(style)); + await tester.pumpWidget(appWithTextWidget(style)); await expectLater(tester, doesNotMeetGuideline(textContrastGuideline)); handle.dispose(); }); @@ -261,7 +261,7 @@ void main() { }); group('custom minimum contrast guideline', () { - Widget _icon({ + Widget iconWidget({ IconData icon = Icons.search, required Color color, required Color background, @@ -273,7 +273,7 @@ void main() { ); } - Widget _text({ + Widget textWidget({ String text = 'Text', required Color color, required Color background, @@ -285,16 +285,16 @@ void main() { ); } - Widget _row(List widgets) => _boilerplate(Row(children: widgets)); + Widget rowWidget(List widgets) => _boilerplate(Row(children: widgets)); final Finder findIcons = find.byWidgetPredicate((Widget widget) => widget is Icon); final Finder findTexts = find.byWidgetPredicate((Widget widget) => widget is Text); final Finder findIconsAndTexts = find.byWidgetPredicate((Widget widget) => widget is Icon || widget is Text); testWidgets('Black icons on white background', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.black, background: Colors.white), - _icon(color: Colors.black, background: Colors.white), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.black, background: Colors.white), + iconWidget(color: Colors.black, background: Colors.white), ])); await expectLater( @@ -304,9 +304,9 @@ void main() { }); testWidgets('Black icons on black background', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.black, background: Colors.black), - _icon(color: Colors.black, background: Colors.black), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.black, background: Colors.black), + iconWidget(color: Colors.black, background: Colors.black), ])); await expectLater( @@ -317,9 +317,9 @@ void main() { testWidgets('White icons on black background ("dark mode")', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.white, background: Colors.black), - _icon(color: Colors.white, background: Colors.black), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.white, background: Colors.black), + iconWidget(color: Colors.white, background: Colors.black), ])); await expectLater( @@ -329,11 +329,11 @@ void main() { }); testWidgets('Using different icons', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.black, background: Colors.white, icon: Icons.more_horiz), - _icon(color: Colors.black, background: Colors.white, icon: Icons.description), - _icon(color: Colors.black, background: Colors.white, icon: Icons.image), - _icon(color: Colors.black, background: Colors.white, icon: Icons.beach_access), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.black, background: Colors.white, icon: Icons.more_horiz), + iconWidget(color: Colors.black, background: Colors.white, icon: Icons.description), + iconWidget(color: Colors.black, background: Colors.white, icon: Icons.image), + iconWidget(color: Colors.black, background: Colors.white, icon: Icons.beach_access), ])); await expectLater( @@ -344,9 +344,9 @@ void main() { testWidgets('One invalid instance fails entire test', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.black, background: Colors.white), - _icon(color: Colors.black, background: Colors.black), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.black, background: Colors.white), + iconWidget(color: Colors.black, background: Colors.black), ])); await expectLater( @@ -357,11 +357,11 @@ void main() { testWidgets('White on different colors, passing', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.white, background: Colors.red[800]!, icon: Icons.more_horiz), - _icon(color: Colors.white, background: Colors.green[800]!, icon: Icons.description), - _icon(color: Colors.white, background: Colors.blue[800]!, icon: Icons.image), - _icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.white, background: Colors.red[800]!, icon: Icons.more_horiz), + iconWidget(color: Colors.white, background: Colors.green[800]!, icon: Icons.description), + iconWidget(color: Colors.white, background: Colors.blue[800]!, icon: Icons.image), + iconWidget(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access), ])); await expectLater(tester, @@ -370,11 +370,11 @@ void main() { testWidgets('White on different colors, failing', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.white, background: Colors.red[200]!, icon: Icons.more_horiz), - _icon(color: Colors.white, background: Colors.green[400]!, icon: Icons.description), - _icon(color: Colors.white, background: Colors.blue[600]!, icon: Icons.image), - _icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.white, background: Colors.red[200]!, icon: Icons.more_horiz), + iconWidget(color: Colors.white, background: Colors.green[400]!, icon: Icons.description), + iconWidget(color: Colors.white, background: Colors.blue[600]!, icon: Icons.image), + iconWidget(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access), ])); await expectLater( @@ -384,7 +384,7 @@ void main() { }); testWidgets('Absence of icons, passing', (WidgetTester tester) async { - await tester.pumpWidget(_row([])); + await tester.pumpWidget(rowWidget([])); await expectLater( tester, @@ -394,9 +394,9 @@ void main() { testWidgets('Absence of icons, passing - 2nd test', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _text(color: Colors.black, background: Colors.white), - _text(color: Colors.black, background: Colors.black), + await tester.pumpWidget(rowWidget([ + textWidget(color: Colors.black, background: Colors.white), + textWidget(color: Colors.black, background: Colors.black), ])); await expectLater( @@ -407,11 +407,11 @@ void main() { testWidgets('Guideline ignores widgets of other types', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.black, background: Colors.white), - _icon(color: Colors.black, background: Colors.white), - _text(color: Colors.black, background: Colors.white), - _text(color: Colors.black, background: Colors.black), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.black, background: Colors.white), + iconWidget(color: Colors.black, background: Colors.white), + textWidget(color: Colors.black, background: Colors.white), + textWidget(color: Colors.black, background: Colors.black), ])); await expectLater( @@ -429,9 +429,9 @@ void main() { }); testWidgets('Custom minimum ratio - Icons', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.blue, background: Colors.white), - _icon(color: Colors.black, background: Colors.white), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.blue, background: Colors.white), + iconWidget(color: Colors.black, background: Colors.white), ])); await expectLater( @@ -445,9 +445,9 @@ void main() { }); testWidgets('Custom minimum ratio - Texts', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _text(color: Colors.blue, background: Colors.white), - _text(color: Colors.black, background: Colors.white), + await tester.pumpWidget(rowWidget([ + textWidget(color: Colors.blue, background: Colors.white), + textWidget(color: Colors.black, background: Colors.white), ])); await expectLater( @@ -463,11 +463,11 @@ void main() { testWidgets( 'Custom minimum ratio - Different standards for icons and texts', (WidgetTester tester) async { - await tester.pumpWidget(_row([ - _icon(color: Colors.blue, background: Colors.white), - _icon(color: Colors.black, background: Colors.white), - _text(color: Colors.blue, background: Colors.white), - _text(color: Colors.black, background: Colors.white), + await tester.pumpWidget(rowWidget([ + iconWidget(color: Colors.blue, background: Colors.white), + iconWidget(color: Colors.black, background: Colors.white), + textWidget(color: Colors.blue, background: Colors.white), + textWidget(color: Colors.black, background: Colors.white), ])); await expectLater(