Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9cb9cc5

Browse files
committed
migrated to flutter:test
1 parent cff3880 commit 9cb9cc5

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

testing/dart/color_test.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,31 @@ import 'dart:ui';
66

77
import 'package:test/test.dart';
88

9-
/// Positive result when the Colors will map to the same argb8888 color.
10-
Matcher colorMatches(dynamic o) => (v) {
11-
Expect.isTrue(o is Color);
12-
Expect.isTrue(v is Color);
13-
if (o is Color && v is Color) {
14-
Expect.equals(o.colorSpace, v.colorSpace);
15-
Expect.approxEquals(o.a, v.a, 1 / 255);
16-
Expect.approxEquals(o.r, v.r, 1 / 255);
17-
Expect.approxEquals(o.g, v.g, 1 / 255);
18-
Expect.approxEquals(o.b, v.b, 1 / 255);
9+
class _ColorMatcher extends Matcher {
10+
_ColorMatcher(this._target, this._threshold);
11+
12+
final Color _target;
13+
final double _threshold;
14+
15+
@override
16+
Description describe(Description description) {
17+
return description.add('matches color "$_target" with threshold "$_threshold".');
1918
}
20-
};
19+
20+
@override
21+
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
22+
return item is Color &&
23+
item.colorSpace == _target.colorSpace &&
24+
(item.a - _target.a).abs() <= _threshold &&
25+
(item.r - _target.r).abs() <= _threshold &&
26+
(item.g - _target.g).abs() <= _threshold &&
27+
(item.b - _target.b).abs() <= _threshold;
28+
}
29+
}
30+
31+
Matcher colorMatches(Color color, {double threshold = 1/255}) {
32+
return _ColorMatcher(color, threshold);
33+
}
2134

2235
class NotAColor extends Color {
2336
const NotAColor(super.value);

0 commit comments

Comments
 (0)