Improve test coverage (#7564)
Also, fix some minor bugs with SynchronousFuture.
This commit is contained in:
@@ -42,7 +42,9 @@ class SynchronousFuture<T> implements Future<T> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<T> timeout(Duration timeLimit, { dynamic onTimeout() }) => new Completer<T>().future;
|
||||
Future<T> timeout(Duration timeLimit, { dynamic onTimeout() }) {
|
||||
return new Future<T>.value(_value).timeout(timeLimit, onTimeout: onTimeout);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<T> whenComplete(dynamic action()) {
|
||||
@@ -55,4 +57,4 @@ class SynchronousFuture<T> implements Future<T> {
|
||||
return new Future<T>.error(e, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +230,7 @@ class _MaterialButtonState extends State<MaterialButton> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assert(_colorBrightness != null);
|
||||
switch (_colorBrightness) {
|
||||
case Brightness.light:
|
||||
return Colors.black26;
|
||||
@@ -237,7 +238,6 @@ class _MaterialButtonState extends State<MaterialButton> {
|
||||
return Colors.white30;
|
||||
}
|
||||
}
|
||||
assert(_colorBrightness != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -269,4 +269,18 @@ void main() {
|
||||
controller.dispose();
|
||||
expect(controller, hasOneLineDescription);
|
||||
});
|
||||
|
||||
test('AnimationController error handling', () {
|
||||
AnimationController controller = new AnimationController(
|
||||
vsync: const TestVSync(),
|
||||
);
|
||||
|
||||
expect(controller.forward, throwsFlutterError);
|
||||
expect(controller.reverse, throwsFlutterError);
|
||||
expect(() { controller.animateTo(0.5); }, throwsFlutterError);
|
||||
expect(controller.repeat, throwsFlutterError);
|
||||
|
||||
controller.dispose();
|
||||
expect(controller.dispose, throwsFlutterError);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class BogusCurve extends Curve {
|
||||
@override
|
||||
double transform(double t) => 100.0;
|
||||
}
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -113,7 +118,6 @@ void main() {
|
||||
expect(animation.toString(), contains('no next'));
|
||||
});
|
||||
|
||||
|
||||
test('AnimationMean control test', () {
|
||||
AnimationController left = new AnimationController(
|
||||
value: 0.5,
|
||||
@@ -148,4 +152,13 @@ void main() {
|
||||
expect(mean.value, equals(0.50));
|
||||
expect(log, isEmpty);
|
||||
});
|
||||
|
||||
test('CurvedAnimation with bogus curve', () {
|
||||
AnimationController controller = new AnimationController(
|
||||
vsync: const TestVSync(),
|
||||
);
|
||||
CurvedAnimation curved = new CurvedAnimation(parent: controller, curve: new BogusCurve());
|
||||
|
||||
expect(() { curved.value; }, throwsFlutterError);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -90,4 +90,21 @@ void main() {
|
||||
expect(integers, equals(<int>[1, 2, 3, 4, 5]));
|
||||
expect(yieldCount, equals(5));
|
||||
});
|
||||
|
||||
test('The Caching Iterable: expand', () {
|
||||
Iterable<int> integers = new CachingIterable<int>(range(1, 5).iterator);
|
||||
expect(yieldCount, equals(0));
|
||||
|
||||
Iterable<int> expanded1 = integers.expand((int i) => <int>[i, i]);
|
||||
|
||||
expect(yieldCount, equals(0));
|
||||
expect(expanded1, equals(<int>[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]));
|
||||
expect(yieldCount, equals(5));
|
||||
|
||||
Iterable<int> expanded2 = integers.expand((int i) => <int>[i, i]);
|
||||
|
||||
expect(yieldCount, equals(5));
|
||||
expect(expanded2, equals(<int>[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]));
|
||||
expect(yieldCount, equals(5));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright 2017 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 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('SynchronousFuture control test', () async {
|
||||
Future<int> future = new SynchronousFuture<int>(42);
|
||||
|
||||
int result;
|
||||
future.then((int value) { result = value; });
|
||||
|
||||
expect(result, equals(42));
|
||||
result = null;
|
||||
|
||||
Future<int> futureWithTimeout = future.timeout(const Duration(milliseconds: 1));
|
||||
futureWithTimeout.then((int value) { result = value; });
|
||||
expect(result, isNull);
|
||||
await futureWithTimeout;
|
||||
expect(result, equals(42));
|
||||
result = null;
|
||||
|
||||
Stream<int> stream = future.asStream();
|
||||
|
||||
expect(await stream.single, equals(42));
|
||||
|
||||
bool ranAction = false;
|
||||
Future<int> completeResult = future.whenComplete(() {
|
||||
ranAction = true;
|
||||
return new Future<int>.value(31);
|
||||
});
|
||||
|
||||
expect(ranAction, isTrue);
|
||||
ranAction = false;
|
||||
|
||||
expect(await completeResult, equals(42));
|
||||
|
||||
Object exception;
|
||||
try {
|
||||
await future.whenComplete(() {
|
||||
throw null;
|
||||
});
|
||||
// Unreached.
|
||||
expect(false, isTrue);
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
}
|
||||
expect(exception, isNullThrownError);
|
||||
});
|
||||
}
|
||||
21
packages/flutter/test/material/icon_theme_data_test.dart
Normal file
21
packages/flutter/test/material/icon_theme_data_test.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('IconThemeData control test', () {
|
||||
IconThemeData data = new IconThemeData(color: Colors.green[500], opacity: 0.5, size: 16.0);
|
||||
|
||||
expect(data, hasOneLineDescription);
|
||||
expect(data, equals(data.copyWith()));
|
||||
expect(data.hashCode, equals(data.copyWith().hashCode));
|
||||
|
||||
IconThemeData lerped = IconThemeData.lerp(data, const IconThemeData.fallback(), 0.25);
|
||||
expect(lerped.color, equals(Color.lerp(Colors.green[500], Colors.black, 0.25)));
|
||||
expect(lerped.opacity, equals(0.625));
|
||||
expect(lerped.size, equals(18.0));
|
||||
});
|
||||
}
|
||||
@@ -6,6 +6,20 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('Theme data control test', () {
|
||||
ThemeData dark = new ThemeData.dark();
|
||||
|
||||
expect(dark, hasOneLineDescription);
|
||||
expect(dark, equals(dark.copyWith()));
|
||||
expect(dark.hashCode, equals(dark.copyWith().hashCode));
|
||||
|
||||
ThemeData light = new ThemeData.light();
|
||||
ThemeData dawn = ThemeData.lerp(dark, light, 0.25);
|
||||
|
||||
expect(dawn.brightness, Brightness.dark);
|
||||
expect(dawn.primaryColor, Color.lerp(dark.primaryColor, light.primaryColor, 0.25));
|
||||
});
|
||||
|
||||
test('Defaults to the default typography for the platform', () {
|
||||
for (TargetPlatform platform in TargetPlatform.values) {
|
||||
ThemeData theme = new ThemeData(platform: platform);
|
||||
|
||||
16
packages/flutter/test/scheduler/priority_test.dart
Normal file
16
packages/flutter/test/scheduler/priority_test.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2017 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/scheduler.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('Priority operators control test', () async {
|
||||
Priority priority = Priority.idle + (Priority.kMaxOffset + 100);
|
||||
expect(priority.value, equals(Priority.idle.value + Priority.kMaxOffset));
|
||||
|
||||
priority = Priority.animation - (Priority.kMaxOffset + 100);
|
||||
expect(priority.value, equals(Priority.animation.value - Priority.kMaxOffset));
|
||||
});
|
||||
}
|
||||
@@ -23,6 +23,8 @@ void main() {
|
||||
expect(ticker.isActive, isTrue);
|
||||
expect(tickCount, equals(0));
|
||||
|
||||
expect(ticker.start, throwsFlutterError);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 10));
|
||||
|
||||
expect(tickCount, equals(1));
|
||||
|
||||
Reference in New Issue
Block a user