@@ -8,8 +8,8 @@ import 'dart:math';
8
8
import 'dart:typed_data' ;
9
9
import 'dart:ui' ;
10
10
11
- import 'package:litetest/litetest.dart' ;
12
11
import 'package:path/path.dart' as path;
12
+ import 'package:test/test.dart' ;
13
13
import 'package:vector_math/vector_math_64.dart' ;
14
14
15
15
import 'goldens.dart' ;
@@ -189,7 +189,10 @@ void main() async {
189
189
canvas.drawRawAtlas (image, Float32List (0 ), Float32List (0 ), Int32List (0 ), BlendMode .src, null , paint);
190
190
canvas.drawRawAtlas (image, Float32List (0 ), Float32List (0 ), null , null , rect, paint);
191
191
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
+ );
193
196
});
194
197
195
198
test ('Data lengths must match for drawAtlas methods' , () async {
@@ -208,15 +211,15 @@ void main() async {
208
211
canvas.drawRawAtlas (image, Float32List (4 ), Float32List (4 ), Int32List (1 ), BlendMode .src, rect, paint);
209
212
canvas.drawRawAtlas (image, Float32List (4 ), Float32List (4 ), null , null , rect, paint);
210
213
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 );
220
223
});
221
224
222
225
test ('Canvas preserves perspective data in Matrix4' , () async {
@@ -489,7 +492,7 @@ void main() async {
489
492
490
493
final ByteData dataSync = await drawOnCanvas (toImageImage);
491
494
final ByteData data = await drawOnCanvas (toImageSyncImage);
492
- expect (data, listEquals (dataSync));
495
+ expect (data.buffer. asUint8List (), equals (dataSync.buffer. asUint8List () ));
493
496
});
494
497
495
498
test ('Canvas.drawParagraph throws when Paragraph.layout was not called' , () async {
@@ -646,39 +649,6 @@ void main() async {
646
649
await comparer.addGoldenImage (image, 'render_unordered_rects.png' );
647
650
});
648
651
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
-
682
652
test ('Canvas.translate affects canvas.getTransform' , () async {
683
653
final PictureRecorder recorder = PictureRecorder ();
684
654
final Canvas canvas = Canvas (recorder);
@@ -688,7 +658,7 @@ void main() async {
688
658
expect (curMatrix, closeToTransform (matrix));
689
659
canvas.translate (10 , 10 );
690
660
final Float64List newCurMatrix = canvas.getTransform ();
691
- expect (newCurMatrix, notCloseToTransform ( matrix));
661
+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
692
662
expect (curMatrix, closeToTransform (matrix));
693
663
});
694
664
@@ -701,7 +671,7 @@ void main() async {
701
671
expect (curMatrix, closeToTransform (matrix));
702
672
canvas.scale (10 , 10 );
703
673
final Float64List newCurMatrix = canvas.getTransform ();
704
- expect (newCurMatrix, notCloseToTransform ( matrix));
674
+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
705
675
expect (curMatrix, closeToTransform (matrix));
706
676
});
707
677
@@ -714,7 +684,7 @@ void main() async {
714
684
expect (curMatrix, closeToTransform (matrix));
715
685
canvas.rotate (pi / 2 );
716
686
final Float64List newCurMatrix = canvas.getTransform ();
717
- expect (newCurMatrix, notCloseToTransform ( matrix));
687
+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
718
688
expect (curMatrix, closeToTransform (matrix));
719
689
});
720
690
@@ -727,7 +697,7 @@ void main() async {
727
697
expect (curMatrix, closeToTransform (matrix));
728
698
canvas.skew (10 , 10 );
729
699
final Float64List newCurMatrix = canvas.getTransform ();
730
- expect (newCurMatrix, notCloseToTransform ( matrix));
700
+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
731
701
expect (curMatrix, closeToTransform (matrix));
732
702
});
733
703
@@ -740,31 +710,10 @@ void main() async {
740
710
expect (curMatrix, closeToTransform (matrix));
741
711
canvas.translate (10 , 10 );
742
712
final Float64List newCurMatrix = canvas.getTransform ();
743
- expect (newCurMatrix, notCloseToTransform ( matrix));
713
+ expect (newCurMatrix, isNot ( closeToTransform ( matrix) ));
744
714
expect (curMatrix, closeToTransform (matrix));
745
715
});
746
716
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
-
768
717
test ('Canvas.clipRect affects canvas.getClipBounds' , () async {
769
718
void testRect (Rect clipRect, bool doAA) {
770
719
final PictureRecorder recorder = PictureRecorder ();
@@ -798,8 +747,8 @@ void main() async {
798
747
canvas.save ();
799
748
canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ));
800
749
// 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) ));
803
752
// Previous return values have not changed
804
753
expect (initialLocalBounds, closeToRect (clipExpandedBounds));
805
754
expect (initialDestinationBounds, closeToRect (clipExpandedBounds));
@@ -881,8 +830,8 @@ void main() async {
881
830
canvas.save ();
882
831
canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ));
883
832
// 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) ));
886
835
// Previous return values have not changed
887
836
expect (initialLocalBounds, closeToRect (clipExpandedBounds));
888
837
expect (initialDestinationBounds, closeToRect (clipExpandedBounds));
@@ -921,8 +870,8 @@ void main() async {
921
870
canvas.save ();
922
871
canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ), doAntiAlias: false );
923
872
// 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) ));
926
875
// Previous return values have not changed
927
876
expect (initialLocalBounds, closeToRect (clipBounds));
928
877
expect (initialDestinationBounds, closeToRect (clipBounds));
@@ -985,8 +934,8 @@ void main() async {
985
934
canvas.save ();
986
935
canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ));
987
936
// 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) ));
990
939
// Previous return values have not changed
991
940
expect (initialLocalBounds, closeToRect (clipExpandedBounds));
992
941
expect (initialDestinationBounds, closeToRect (clipExpandedBounds));
@@ -1025,8 +974,8 @@ void main() async {
1025
974
canvas.save ();
1026
975
canvas.clipRect (const Rect .fromLTRB (0 , 0 , 15 , 15 ), doAntiAlias: false );
1027
976
// 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) ));
1030
979
// Previous return values have not changed
1031
980
expect (initialLocalBounds, closeToRect (clipBounds));
1032
981
expect (initialDestinationBounds, closeToRect (clipBounds));
@@ -1300,7 +1249,6 @@ void main() async {
1300
1249
final ByteData ? data = await resultImage.toByteData ();
1301
1250
if (data == null ) {
1302
1251
fail ('Expected non-null byte data' );
1303
- return ;
1304
1252
}
1305
1253
final int rgba = data.buffer.asUint32List ()[0 ];
1306
1254
expect (rgba, 0xFF0000FF );
@@ -1315,11 +1263,51 @@ Future<Image> createTestImage() async {
1315
1263
return picture.toImage (1 , 1 );
1316
1264
}
1317
1265
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 ;
1324
1307
}
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