Improve test coverage (#5473)
These tests should hit some previously untested lines.
This commit is contained in:
parent
508b8c460c
commit
a60fefc131
@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -117,4 +118,35 @@ void main() {
|
|||||||
'global 2',
|
'global 2',
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Exceptions do not stop pointer routing', () {
|
||||||
|
List<String> log = <String>[];
|
||||||
|
PointerRouter router = new PointerRouter();
|
||||||
|
router.addRoute(2, (PointerEvent event) {
|
||||||
|
log.add('per-pointer 1');
|
||||||
|
});
|
||||||
|
router.addRoute(2, (PointerEvent event) {
|
||||||
|
log.add('per-pointer 2');
|
||||||
|
throw "Having a bad day!";
|
||||||
|
});
|
||||||
|
router.addRoute(2, (PointerEvent event) {
|
||||||
|
log.add('per-pointer 3');
|
||||||
|
});
|
||||||
|
|
||||||
|
FlutterExceptionHandler previousErrorHandler = FlutterError.onError;
|
||||||
|
FlutterError.onError = (FlutterErrorDetails details) {
|
||||||
|
log.add('error report');
|
||||||
|
};
|
||||||
|
|
||||||
|
TestPointer pointer2 = new TestPointer(2);
|
||||||
|
router.route(pointer2.down(Point.origin));
|
||||||
|
expect(log, equals(<String>[
|
||||||
|
'per-pointer 1',
|
||||||
|
'per-pointer 2',
|
||||||
|
'error report',
|
||||||
|
'per-pointer 3',
|
||||||
|
]));
|
||||||
|
|
||||||
|
FlutterError.onError = previousErrorHandler;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
27
packages/flutter/test/gestures/recognizer_test.dart
Normal file
27
packages/flutter/test/gestures/recognizer_test.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
|
||||||
|
class TestGestureRecognizer extends GestureRecognizer {
|
||||||
|
@override
|
||||||
|
String toString() => 'toString content';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void addPointer(PointerDownEvent event) {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void acceptGesture(int pointer) {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void rejectGesture(int pointer) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('GestureRecognizer.toStringShort defaults to toString', () {
|
||||||
|
TestGestureRecognizer recognizer = new TestGestureRecognizer();
|
||||||
|
expect(recognizer.toStringShort(), equals(recognizer.toString()));
|
||||||
|
});
|
||||||
|
}
|
@ -54,6 +54,8 @@ void main() {
|
|||||||
expect(velocity1, equals(new Velocity(pixelsPerSecond: new Offset(7.0, 0.0))));
|
expect(velocity1, equals(new Velocity(pixelsPerSecond: new Offset(7.0, 0.0))));
|
||||||
expect(velocity1, isNot(equals(velocity2)));
|
expect(velocity1, isNot(equals(velocity2)));
|
||||||
expect(velocity2 - velocity1, equals(new Velocity(pixelsPerSecond: new Offset(5.0, 0.0))));
|
expect(velocity2 - velocity1, equals(new Velocity(pixelsPerSecond: new Offset(5.0, 0.0))));
|
||||||
|
expect((-velocity1).pixelsPerSecond, new Offset(-7.0, 0.0));
|
||||||
|
expect(velocity1 + velocity2, equals(new Velocity(pixelsPerSecond: new Offset(19.0, 0.0))));
|
||||||
expect(velocity1.hashCode, isNot(equals(velocity2.hashCode)));
|
expect(velocity1.hashCode, isNot(equals(velocity2.hashCode)));
|
||||||
expect(velocity1, hasOneLineDescription);
|
expect(velocity1, hasOneLineDescription);
|
||||||
});
|
});
|
||||||
|
79
packages/flutter/test/painting/box_painter_test.dart
Normal file
79
packages/flutter/test/painting/box_painter_test.dart
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/painting.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test("BorderSide control test", () {
|
||||||
|
BorderSide side1 = new BorderSide();
|
||||||
|
BorderSide side2 = side1.copyWith(
|
||||||
|
color: const Color(0xFF00FFFF),
|
||||||
|
width: 2.0,
|
||||||
|
style: BorderStyle.solid,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(side1, hasOneLineDescription);
|
||||||
|
expect(side1.hashCode, isNot(equals(side2.hashCode)));
|
||||||
|
|
||||||
|
expect(side2.color, equals(const Color(0xFF00FFFF)));
|
||||||
|
expect(side2.width, equals(2.0));
|
||||||
|
expect(side2.style, equals(BorderStyle.solid));
|
||||||
|
|
||||||
|
expect(BorderSide.lerp(side1, side2, 0.0), equals(side1));
|
||||||
|
expect(BorderSide.lerp(side1, side2, 1.0), equals(side2));
|
||||||
|
expect(BorderSide.lerp(side1, side2, 0.5), equals(new BorderSide(
|
||||||
|
color: Color.lerp(const Color(0xFF000000), const Color(0xFF00FFFF), 0.5),
|
||||||
|
width: 1.5,
|
||||||
|
style: BorderStyle.solid,
|
||||||
|
)));
|
||||||
|
|
||||||
|
BorderSide side3 = side2.copyWith(style: BorderStyle.none);
|
||||||
|
BorderSide interpolated = BorderSide.lerp(side2, side3, 0.2);
|
||||||
|
expect(interpolated.style, equals(BorderStyle.solid));
|
||||||
|
expect(interpolated.color, equals(side2.color.withOpacity(0.8)));
|
||||||
|
|
||||||
|
interpolated = BorderSide.lerp(side3, side2, 0.2);
|
||||||
|
expect(interpolated.style, equals(BorderStyle.solid));
|
||||||
|
expect(interpolated.color, equals(side2.color.withOpacity(0.2)));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Border control test", () {
|
||||||
|
Border border1 = new Border.all(width: 4.0);
|
||||||
|
Border border2 = Border.lerp(null, border1, 0.25);
|
||||||
|
Border border3 = Border.lerp(border1, null, 0.25);
|
||||||
|
|
||||||
|
expect(border1, hasOneLineDescription);
|
||||||
|
expect(border1.hashCode, isNot(equals(border2.hashCode)));
|
||||||
|
|
||||||
|
expect(border2.top.width, equals(1.0));
|
||||||
|
expect(border3.bottom.width, equals(3.0));
|
||||||
|
|
||||||
|
Border border4 = Border.lerp(border2, border3, 0.5);
|
||||||
|
expect(border4.left.width, equals(2.0));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("BoxShadow control test", () {
|
||||||
|
BoxShadow shadow1 = new BoxShadow(blurRadius: 4.0);
|
||||||
|
BoxShadow shadow2 = BoxShadow.lerp(null, shadow1, 0.25);
|
||||||
|
BoxShadow shadow3 = BoxShadow.lerp(shadow1, null, 0.25);
|
||||||
|
|
||||||
|
expect(shadow1, hasOneLineDescription);
|
||||||
|
expect(shadow1.hashCode, isNot(equals(shadow2.hashCode)));
|
||||||
|
expect(shadow1, equals(new BoxShadow(blurRadius: 4.0)));
|
||||||
|
|
||||||
|
expect(shadow2.blurRadius, equals(1.0));
|
||||||
|
expect(shadow3.blurRadius, equals(3.0));
|
||||||
|
|
||||||
|
BoxShadow shadow4 = BoxShadow.lerp(shadow2, shadow3, 0.5);
|
||||||
|
expect(shadow4.blurRadius, equals(2.0));
|
||||||
|
|
||||||
|
List<BoxShadow> shadowList = BoxShadow.lerpList(
|
||||||
|
<BoxShadow>[shadow2, shadow1], <BoxShadow>[shadow3], 0.5);
|
||||||
|
expect(shadowList, equals(<BoxShadow>[shadow4, shadow1.scale(0.5)]));
|
||||||
|
shadowList = BoxShadow.lerpList(
|
||||||
|
<BoxShadow>[shadow2], <BoxShadow>[shadow3, shadow1], 0.5);
|
||||||
|
expect(shadowList, equals(<BoxShadow>[shadow4, shadow1.scale(0.5)]));
|
||||||
|
});
|
||||||
|
}
|
20
packages/flutter/test/rendering/debug_test.dart
Normal file
20
packages/flutter/test/rendering/debug_test.dart
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'package:vector_math/vector_math_64.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test("Describe transform control test", () {
|
||||||
|
Matrix4 identity = new Matrix4.identity();
|
||||||
|
List<String> description = debugDescribeTransform(identity);
|
||||||
|
expect(description, equals(<String>[
|
||||||
|
' [0] 1.0,0.0,0.0,0.0',
|
||||||
|
' [1] 0.0,1.0,0.0,0.0',
|
||||||
|
' [2] 0.0,0.0,1.0,0.0',
|
||||||
|
' [3] 0.0,0.0,0.0,1.0',
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user