add a matcher for area covered by paths (#14469)

This commit is contained in:
amirh
2018-02-06 09:13:51 -08:00
committed by GitHub
parent 28c8fd10cf
commit 0da6bad656
2 changed files with 157 additions and 0 deletions

View File

@@ -209,4 +209,77 @@ void main() {
throwsArgumentError,
);
});
group('coversSameAreaAs', () {
test('empty Paths', () {
expect(
new Path(),
coversSameAreaAs(
new Path(),
areaToCompare: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0)
),
);
});
test('mismatch', () {
final Path rectPath = new Path()
..addRect(new Rect.fromLTRB(5.0, 5.0, 6.0, 6.0));
expect(
new Path(),
isNot(coversSameAreaAs(
rectPath,
areaToCompare: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0)
)),
);
});
test('mismatch out of examined area', () {
final Path rectPath = new Path()
..addRect(new Rect.fromLTRB(5.0, 5.0, 6.0, 6.0));
rectPath.addRect(new Rect.fromLTRB(5.0, 5.0, 6.0, 6.0));
expect(
new Path(),
coversSameAreaAs(
rectPath,
areaToCompare: new Rect.fromLTRB(0.0, 0.0, 4.0, 4.0)
),
);
});
test('differently constructed rects match', () {
final Path rectPath = new Path()
..addRect(new Rect.fromLTRB(5.0, 5.0, 6.0, 6.0));
final Path linePath = new Path()
..moveTo(5.0, 5.0)
..lineTo(5.0, 6.0)
..lineTo(6.0, 6.0)
..lineTo(6.0, 5.0)
..close();
expect(
linePath,
coversSameAreaAs(
rectPath,
areaToCompare: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0)
),
);
});
test('partially overlapping paths', () {
final Path rectPath = new Path()
..addRect(new Rect.fromLTRB(5.0, 5.0, 6.0, 6.0));
final Path linePath = new Path()
..moveTo(5.0, 5.0)
..lineTo(5.0, 6.0)
..lineTo(6.0, 6.0)
..lineTo(6.0, 5.5)
..close();
expect(
linePath,
isNot(coversSameAreaAs(
rectPath,
areaToCompare: new Rect.fromLTRB(0.0, 0.0, 10.0, 10.0)
)),
);
});
});
}