@@ -8,8 +8,8 @@ import 'dart:math';
88import 'dart:typed_data' ;
99import 'dart:ui' ;
1010
11- import 'package:litetest/litetest.dart' ;
1211import 'package:path/path.dart' as path;
12+ import 'package:test/test.dart' ;
1313import 'package:vector_math/vector_math_64.dart' ;
1414
1515import 'goldens.dart' ;
@@ -189,7 +189,10 @@ void main() async {
189189 canvas.drawRawAtlas (image, Float32List (0 ), Float32List (0 ), Int32List (0 ), BlendMode .src, null , paint);
190190 canvas.drawRawAtlas (image, Float32List (0 ), Float32List (0 ), null , null , rect, paint);
191191
192- expectAssertion (() => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [rect], < Color > [color], null , rect, paint));
192+ expect (
193+ () => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [rect], < Color > [color], null , rect, paint),
194+ throwsA (isA <AssertionError >()),
195+ );
193196 });
194197
195198 test ('Data lengths must match for drawAtlas methods' , () async {
@@ -208,15 +211,15 @@ void main() async {
208211 canvas.drawRawAtlas (image, Float32List (4 ), Float32List (4 ), Int32List (1 ), BlendMode .src, rect, paint);
209212 canvas.drawRawAtlas (image, Float32List (4 ), Float32List (4 ), null , null , rect, paint);
210213
211- expectArgumentError (() => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [], < Color > [color], BlendMode .src, rect, paint));
212- expectArgumentError (() => canvas.drawAtlas (image, < RSTransform > [], < Rect > [rect], < Color > [color], BlendMode .src, rect, paint));
213- expectArgumentError (() => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [rect], < Color > [color, color], BlendMode .src, rect, paint));
214- expectArgumentError (() => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [rect, rect], < Color > [color], BlendMode .src, rect, paint));
215- expectArgumentError (() => canvas.drawAtlas (image, < RSTransform > [transform, transform], < Rect > [rect], < Color > [color], BlendMode .src, rect, paint));
216- expectArgumentError (() => canvas.drawRawAtlas (image, Float32List (3 ), Float32List (3 ), null , null , rect, paint));
217- expectArgumentError (() => canvas.drawRawAtlas (image, Float32List (4 ), Float32List (0 ), null , null , rect, paint));
218- expectArgumentError (() => canvas.drawRawAtlas (image, Float32List (0 ), Float32List (4 ), null , null , rect, paint));
219- expectArgumentError (() => canvas.drawRawAtlas (image, Float32List (4 ), Float32List (4 ), Int32List (2 ), BlendMode .src, rect, paint));
214+ expect (() => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [], < Color > [color], BlendMode .src, rect, paint), throwsArgumentError );
215+ expect (() => canvas.drawAtlas (image, < RSTransform > [], < Rect > [rect], < Color > [color], BlendMode .src, rect, paint), throwsArgumentError );
216+ expect (() => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [rect], < Color > [color, color], BlendMode .src, rect, paint), throwsArgumentError );
217+ expect (() => canvas.drawAtlas (image, < RSTransform > [transform], < Rect > [rect, rect], < Color > [color], BlendMode .src, rect, paint), throwsArgumentError );
218+ expect (() => canvas.drawAtlas (image, < RSTransform > [transform, transform], < Rect > [rect], < Color > [color], BlendMode .src, rect, paint), throwsArgumentError );
219+ expect (() => canvas.drawRawAtlas (image, Float32List (3 ), Float32List (3 ), null , null , rect, paint), throwsArgumentError );
220+ expect (() => canvas.drawRawAtlas (image, Float32List (4 ), Float32List (0 ), null , null , rect, paint), throwsArgumentError );
221+ expect (() => canvas.drawRawAtlas (image, Float32List (0 ), Float32List (4 ), null , null , rect, paint), throwsArgumentError );
222+ expect (() => canvas.drawRawAtlas (image, Float32List (4 ), Float32List (4 ), Int32List (2 ), BlendMode .src, rect, paint), throwsArgumentError );
220223 });
221224
222225 test ('Canvas preserves perspective data in Matrix4' , () async {
@@ -489,7 +492,7 @@ void main() async {
489492
490493 final ByteData dataSync = await drawOnCanvas (toImageImage);
491494 final ByteData data = await drawOnCanvas (toImageSyncImage);
492- expect (data, listEquals (dataSync));
495+ expect (data.buffer. asUint8List (), equals (dataSync.buffer. asUint8List () ));
493496 });
494497
495498 test ('Canvas.drawParagraph throws when Paragraph.layout was not called' , () async {
@@ -646,39 +649,6 @@ void main() async {
646649 await comparer.addGoldenImage (image, 'render_unordered_rects.png' );
647650 });
648651
649- Matcher closeToTransform (Float64List expected) => (dynamic v) {
650- Expect .type <Float64List >(v);
651- final Float64List value = v as Float64List ;
652- expect (expected.length, equals (16 ));
653- expect (value.length, equals (16 ));
654- for (int r = 0 ; r < 4 ; r++ ) {
655- for (int c = 0 ; c < 4 ; c++ ) {
656- final double vActual = value[r* 4 + c];
657- final double vExpected = expected[r* 4 + c];
658- if ((vActual - vExpected).abs () > 1e-10 ) {
659- Expect .fail ('matrix mismatch at $r , $c , $vActual not close to $vExpected ' );
660- }
661- }
662- }
663- };
664-
665- Matcher notCloseToTransform (Float64List expected) => (dynamic v) {
666- Expect .type <Float64List >(v);
667- final Float64List value = v as Float64List ;
668- expect (expected.length, equals (16 ));
669- expect (value.length, equals (16 ));
670- for (int r = 0 ; r < 4 ; r++ ) {
671- for (int c = 0 ; c < 4 ; c++ ) {
672- final double vActual = value[r* 4 + c];
673- final double vExpected = expected[r* 4 + c];
674- if ((vActual - vExpected).abs () > 1e-10 ) {
675- return ;
676- }
677- }
678- }
679- Expect .fail ('$value is too close to $expected ' );
680- };
681-
682652 test ('Canvas.translate affects canvas.getTransform' , () async {
683653 final PictureRecorder recorder = PictureRecorder ();
684654 final Canvas canvas = Canvas (recorder);
@@ -688,7 +658,7 @@ void main() async {
688658 expect (curMatrix, closeToTransform (matrix));
689659 canvas.translate (10 , 10 );
690660 final Float64List newCurMatrix = canvas.getTransform ();
691- expect (newCurMatrix, notCloseToTransform ( matrix));
661+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
692662 expect (curMatrix, closeToTransform (matrix));
693663 });
694664
@@ -701,7 +671,7 @@ void main() async {
701671 expect (curMatrix, closeToTransform (matrix));
702672 canvas.scale (10 , 10 );
703673 final Float64List newCurMatrix = canvas.getTransform ();
704- expect (newCurMatrix, notCloseToTransform ( matrix));
674+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
705675 expect (curMatrix, closeToTransform (matrix));
706676 });
707677
@@ -714,7 +684,7 @@ void main() async {
714684 expect (curMatrix, closeToTransform (matrix));
715685 canvas.rotate (pi / 2 );
716686 final Float64List newCurMatrix = canvas.getTransform ();
717- expect (newCurMatrix, notCloseToTransform ( matrix));
687+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
718688 expect (curMatrix, closeToTransform (matrix));
719689 });
720690
@@ -727,7 +697,7 @@ void main() async {
727697 expect (curMatrix, closeToTransform (matrix));
728698 canvas.skew (10 , 10 );
729699 final Float64List newCurMatrix = canvas.getTransform ();
730- expect (newCurMatrix, notCloseToTransform ( matrix));
700+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
731701 expect (curMatrix, closeToTransform (matrix));
732702 });
733703
@@ -740,31 +710,10 @@ void main() async {
740710 expect (curMatrix, closeToTransform (matrix));
741711 canvas.translate (10 , 10 );
742712 final Float64List newCurMatrix = canvas.getTransform ();
743- expect (newCurMatrix, notCloseToTransform ( matrix));
713+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
744714 expect (curMatrix, closeToTransform (matrix));
745715 });
746716
747- Matcher closeToRect (Rect expected) => (dynamic v) {
748- Expect .type <Rect >(v);
749- final Rect value = v as Rect ;
750- expect (value.left, closeTo (expected.left, 1e-6 ));
751- expect (value.top, closeTo (expected.top, 1e-6 ));
752- expect (value.right, closeTo (expected.right, 1e-6 ));
753- expect (value.bottom, closeTo (expected.bottom, 1e-6 ));
754- };
755-
756- Matcher notCloseToRect (Rect expected) => (dynamic v) {
757- Expect .type <Rect >(v);
758- final Rect value = v as Rect ;
759- if ((value.left - expected.left).abs () > 1e-6 ||
760- (value.top - expected.top).abs () > 1e-6 ||
761- (value.right - expected.right).abs () > 1e-6 ||
762- (value.bottom - expected.bottom).abs () > 1e-6 ) {
763- return ;
764- }
765- Expect .fail ('$value is too close to $expected ' );
766- };
767-
768717 test ('Canvas.clipRect affects canvas.getClipBounds' , () async {
769718 void testRect (Rect clipRect, bool doAA) {
770719 final PictureRecorder recorder = PictureRecorder ();
@@ -798,8 +747,8 @@ void main() async {
798747 canvas.save ();
799748 canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ));
800749 // Both clip bounds have changed
801- expect (canvas.getLocalClipBounds (), notCloseToRect ( clipExpandedBounds));
802- expect (canvas.getDestinationClipBounds (), notCloseToRect ( clipExpandedBounds));
750+ expect (canvas.getLocalClipBounds (), isNot ( closeToRect ( clipExpandedBounds) ));
751+ expect (canvas.getDestinationClipBounds (), isNot ( closeToRect ( clipExpandedBounds) ));
803752 // Previous return values have not changed
804753 expect (initialLocalBounds, closeToRect (clipExpandedBounds));
805754 expect (initialDestinationBounds, closeToRect (clipExpandedBounds));
@@ -881,8 +830,8 @@ void main() async {
881830 canvas.save ();
882831 canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ));
883832 // Both clip bounds have changed
884- expect (canvas.getLocalClipBounds (), notCloseToRect ( clipExpandedBounds));
885- expect (canvas.getDestinationClipBounds (), notCloseToRect ( clipExpandedBounds));
833+ expect (canvas.getLocalClipBounds (), isNot ( closeToRect ( clipExpandedBounds) ));
834+ expect (canvas.getDestinationClipBounds (), isNot ( closeToRect ( clipExpandedBounds) ));
886835 // Previous return values have not changed
887836 expect (initialLocalBounds, closeToRect (clipExpandedBounds));
888837 expect (initialDestinationBounds, closeToRect (clipExpandedBounds));
@@ -921,8 +870,8 @@ void main() async {
921870 canvas.save ();
922871 canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ), doAntiAlias: false );
923872 // Both clip bounds have changed
924- expect (canvas.getLocalClipBounds (), notCloseToRect ( clipBounds));
925- expect (canvas.getDestinationClipBounds (), notCloseToRect ( clipBounds));
873+ expect (canvas.getLocalClipBounds (), isNot ( closeToRect ( clipBounds) ));
874+ expect (canvas.getDestinationClipBounds (), isNot ( closeToRect ( clipBounds) ));
926875 // Previous return values have not changed
927876 expect (initialLocalBounds, closeToRect (clipBounds));
928877 expect (initialDestinationBounds, closeToRect (clipBounds));
@@ -985,8 +934,8 @@ void main() async {
985934 canvas.save ();
986935 canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ));
987936 // Both clip bounds have changed
988- expect (canvas.getLocalClipBounds (), notCloseToRect ( clipExpandedBounds));
989- expect (canvas.getDestinationClipBounds (), notCloseToRect ( clipExpandedBounds));
937+ expect (canvas.getLocalClipBounds (), isNot ( closeToRect ( clipExpandedBounds) ));
938+ expect (canvas.getDestinationClipBounds (), isNot ( closeToRect ( clipExpandedBounds) ));
990939 // Previous return values have not changed
991940 expect (initialLocalBounds, closeToRect (clipExpandedBounds));
992941 expect (initialDestinationBounds, closeToRect (clipExpandedBounds));
@@ -1025,8 +974,8 @@ void main() async {
1025974 canvas.save ();
1026975 canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ), doAntiAlias: false );
1027976 // Both clip bounds have changed
1028- expect (canvas.getLocalClipBounds (), notCloseToRect ( clipBounds));
1029- expect (canvas.getDestinationClipBounds (), notCloseToRect ( clipBounds));
977+ expect (canvas.getLocalClipBounds (), isNot ( closeToRect ( clipBounds) ));
978+ expect (canvas.getDestinationClipBounds (), isNot ( closeToRect ( clipBounds) ));
1030979 // Previous return values have not changed
1031980 expect (initialLocalBounds, closeToRect (clipBounds));
1032981 expect (initialDestinationBounds, closeToRect (clipBounds));
@@ -1300,7 +1249,6 @@ void main() async {
13001249 final ByteData ? data = await resultImage.toByteData ();
13011250 if (data == null ) {
13021251 fail ('Expected non-null byte data' );
1303- return ;
13041252 }
13051253 final int rgba = data.buffer.asUint32List ()[0 ];
13061254 expect (rgba, 0xFF0000FF );
@@ -1315,11 +1263,51 @@ Future<Image> createTestImage() async {
13151263 return picture.toImage (1 , 1 );
13161264}
13171265
1318- Matcher listEquals (ByteData expected) => (dynamic v) {
1319- Expect .type <ByteData >(v);
1320- final ByteData value = v as ByteData ;
1321- expect (value.lengthInBytes, expected.lengthInBytes);
1322- for (int i = 0 ; i < value.lengthInBytes; i++ ) {
1323- expect (value.getUint8 (i), expected.getUint8 (i));
1266+ Matcher closeToRect (Rect rect) => _CloseToRectMatcher (rect);
1267+ final class _CloseToRectMatcher extends Matcher {
1268+ const _CloseToRectMatcher (this ._expectedRect);
1269+ final Rect _expectedRect;
1270+
1271+ @override
1272+ bool matches (Object ? item, Map <Object ?, Object ?> matchState) {
1273+ if (item is ! Rect ) {
1274+ return false ;
1275+ }
1276+ return (item.left - _expectedRect.left).abs () < 1e-6 &&
1277+ (item.top - _expectedRect.top).abs () < 1e-6 &&
1278+ (item.right - _expectedRect.right).abs () < 1e-6 &&
1279+ (item.bottom - _expectedRect.bottom).abs () < 1e-6 ;
1280+ }
1281+
1282+ @override
1283+ Description describe (Description description) {
1284+ return description.add ('Rect is close (within 1e-6) to $_expectedRect ' );
1285+ }
1286+ }
1287+
1288+ Matcher closeToTransform (Float64List expected) => _CloseToTransformMatcher (expected);
1289+ final class _CloseToTransformMatcher extends Matcher {
1290+ _CloseToTransformMatcher (this ._expected);
1291+ final Float64List _expected;
1292+
1293+ @override
1294+ bool matches (Object ? item, Map <Object ?, Object ?> matchState) {
1295+ if (item is ! Float64List ) {
1296+ return false ;
1297+ }
1298+ if (item.length != 16 || _expected.length != 16 ) {
1299+ return false ;
1300+ }
1301+ for (int i = 0 ; i < 16 ; i++ ) {
1302+ if ((item[i] - _expected[i]).abs () > 1e-10 ) {
1303+ return false ;
1304+ }
1305+ }
1306+ return true ;
13241307 }
1325- };
1308+
1309+ @override
1310+ Description describe (Description description) {
1311+ return description.add ('Transform is close (within 1e-10) to $_expected ' );
1312+ }
1313+ }
0 commit comments