From 62a4643e4f32ae65304b859edc9b3750d423e128 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sat, 6 May 2023 10:10:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20`rect`=20argument=20to=20`=5F?= =?UTF-8?q?ArcPaintPredicate`=20for=20tests=20(#125953)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As preparation for #125945. The PR improves tests itself which allows the `arc` method to be available to check whether corresponding rects are drawn during tests. --- .../flutter/test/rendering/mock_canvas.dart | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/flutter/test/rendering/mock_canvas.dart b/packages/flutter/test/rendering/mock_canvas.dart index 7511d7aa84..61a0aac9ef 100644 --- a/packages/flutter/test/rendering/mock_canvas.dart +++ b/packages/flutter/test/rendering/mock_canvas.dart @@ -318,7 +318,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void arc({ Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style, StrokeCap? strokeCap }); + void arc({ Rect? rect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style, StrokeCap? strokeCap }); /// Indicates that a paragraph is expected next. /// @@ -769,8 +769,8 @@ class _TestRecordingCanvasPatternMatcher extends _TestRecordingCanvasMatcher imp } @override - void arc({ Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style, StrokeCap? strokeCap }) { - _predicates.add(_ArcPaintPredicate(color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, strokeCap: strokeCap)); + void arc({ Rect? rect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style, StrokeCap? strokeCap }) { + _predicates.add(_ArcPaintPredicate(rect: rect, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, strokeCap: strokeCap)); } @override @@ -1273,9 +1273,28 @@ class _LinePaintPredicate extends _DrawCommandPaintPredicate { } class _ArcPaintPredicate extends _DrawCommandPaintPredicate { - _ArcPaintPredicate({ Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style, StrokeCap? strokeCap }) : super( + _ArcPaintPredicate({ this.rect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style, StrokeCap? strokeCap }) : super( #drawArc, 'an arc', 5, 4, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, strokeCap: strokeCap, ); + + final Rect? rect; + + @override + void verifyArguments(List arguments) { + super.verifyArguments(arguments); + final Rect rectArgument = arguments[0] as Rect; + if (rect != null && rectArgument != rect) { + throw 'It called $methodName with a paint whose rect, $rectArgument, was not exactly the expected rect ($rect).'; + } + } + + @override + void debugFillDescription(List description) { + super.debugFillDescription(description); + if (rect != null) { + description.add('rect $rect'); + } + } } class _ShadowPredicate extends _PaintPredicate {