more test cleanup
diff --git a/test/list_change_test.dart b/test/list_change_test.dart
index 2c7446e..cf2ac53 100644
--- a/test/list_change_test.dart
+++ b/test/list_change_test.dart
@@ -12,21 +12,19 @@
// This file contains code ported from:
// https://github.com/rafaelw/ChangeSummary/blob/master/tests/test.js
-main() => listChangeTests();
-
// TODO(jmesserly): port or write array fuzzer tests
-listChangeTests() {
+void main() {
StreamSubscription sub;
- var model;
+ ObservableList model;
- tearDown(() {
- sub?.cancel();
+ tearDown(() async {
+ await sub?.cancel();
model = null;
});
_delta(i, r, a) => new ListChangeRecord(model, i, removed: r, addedCount: a);
- test('sequential adds', () {
+ test('sequential adds', () async {
model = toObservable([]);
model.add(0);
@@ -37,38 +35,42 @@
model.add(2);
expect(summary, null);
- return new Future(() => expectChanges(summary, [_delta(1, [], 2)]));
+ await newMicrotask();
+ expectChanges(summary, [_delta(1, [], 2)]);
});
- test('List Splice Truncate And Expand With Length', () {
+ test('List Splice Truncate And Expand With Length', () async {
model = toObservable(['a', 'b', 'c', 'd', 'e']);
var summary;
sub = model.listChanges.listen((r) => summary = r);
model.length = 2;
- return new Future(() {
- expectChanges(summary, [
- _delta(2, ['c', 'd', 'e'], 0)
- ]);
- summary = null;
- model.length = 5;
- }).then(newMicrotask).then((_) {
- expectChanges(summary, [_delta(2, [], 3)]);
- });
+
+ await newMicrotask();
+ expectChanges(summary, [
+ _delta(2, ['c', 'd', 'e'], 0)
+ ]);
+ summary = null;
+ model.length = 5;
+
+ await newMicrotask();
+
+ expectChanges(summary, [_delta(2, [], 3)]);
});
group('List deltas can be applied', () {
- applyAndCheckDeltas(model, copy, changes) => changes.then((summary) {
- // apply deltas to the copy
- for (ListChangeRecord delta in summary) {
- delta.apply(copy);
- }
+ Future applyAndCheckDeltas(model, copy, Future changes) async {
+ var summary = await changes;
+ // apply deltas to the copy
+ for (ListChangeRecord delta in summary) {
+ delta.apply(copy);
+ }
- expect('$copy', '$model', reason: 'summary $summary');
- });
+ expect('$copy', '$model', reason: 'summary $summary');
+ }
- test('Contained', () {
+ test('Contained', () async {
var model = toObservable(['a', 'b']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -78,10 +80,10 @@
model.removeRange(1, 3);
model.insert(1, 'f');
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Delete Empty', () {
+ test('Delete Empty', () async {
var model = toObservable([1]);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -89,10 +91,10 @@
model.removeAt(0);
model.insertAll(0, ['a', 'b', 'c']);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Right Non Overlap', () {
+ test('Right Non Overlap', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -102,10 +104,10 @@
model.removeRange(2, 3);
model.insertAll(2, ['f', 'g']);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Left Non Overlap', () {
+ test('Left Non Overlap', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -115,10 +117,10 @@
model.removeRange(0, 1);
model.insert(0, 'e');
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Right Adjacent', () {
+ test('Right Adjacent', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -128,10 +130,10 @@
model.removeRange(2, 3);
model.insertAll(0, ['f', 'g']);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Left Adjacent', () {
+ test('Left Adjacent', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -142,10 +144,10 @@
model.removeAt(1);
model.insertAll(1, ['f', 'g']);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Right Overlap', () {
+ test('Right Overlap', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -155,10 +157,10 @@
model.removeAt(1);
model.insertAll(1, ['f', 'g']);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Left Overlap', () {
+ test('Left Overlap', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -170,10 +172,10 @@
model.insertAll(1, ['h', 'i', 'j']);
// a [h i j] f g d
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Prefix And Suffix One In', () {
+ test('Prefix And Suffix One In', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -181,20 +183,20 @@
model.insert(0, 'z');
model.add('z');
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Remove First', () {
+ test('Remove First', () async {
var model = toObservable([16, 15, 15]);
var copy = model.toList();
var changes = model.listChanges.first;
model.removeAt(0);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Update Remove', () {
+ test('Update Remove', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
@@ -204,60 +206,61 @@
model[0] = 'h';
model.removeAt(1);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
- test('Remove Mid List', () {
+ test('Remove Mid List', () async {
var model = toObservable(['a', 'b', 'c', 'd']);
var copy = model.toList();
var changes = model.listChanges.first;
model.removeAt(2);
- return applyAndCheckDeltas(model, copy, changes);
+ await applyAndCheckDeltas(model, copy, changes);
});
});
group('edit distance', () {
- assertEditDistance(orig, changes, expectedDist) => changes.then((summary) {
- var actualDistance = 0;
- for (var delta in summary) {
- actualDistance += delta.addedCount + delta.removed.length;
- }
+ Future assertEditDistance(orig, Future changes, expectedDist) async {
+ var summary = await changes;
+ var actualDistance = 0;
+ for (var delta in summary) {
+ actualDistance += delta.addedCount + delta.removed.length;
+ }
- expect(actualDistance, expectedDist);
- });
+ expect(actualDistance, expectedDist);
+ }
- test('add items', () {
+ test('add items', () async {
var model = toObservable([]);
var changes = model.listChanges.first;
model.addAll([1, 2, 3]);
- return assertEditDistance(model, changes, 3);
+ await assertEditDistance(model, changes, 3);
});
- test('trunacte and add, sharing a contiguous block', () {
+ test('trunacte and add, sharing a contiguous block', () async {
var model = toObservable(['x', 'x', 'x', 'x', '1', '2', '3']);
var changes = model.listChanges.first;
model.length = 0;
model.addAll(['1', '2', '3', 'y', 'y', 'y', 'y']);
- return assertEditDistance(model, changes, 8);
+ await assertEditDistance(model, changes, 8);
});
- test('truncate and add, sharing a discontiguous block', () {
+ test('truncate and add, sharing a discontiguous block', () async {
var model = toObservable(['1', '2', '3', '4', '5']);
var changes = model.listChanges.first;
model.length = 0;
model.addAll(['a', '2', 'y', 'y', '4', '5', 'z', 'z']);
- return assertEditDistance(model, changes, 7);
+ await assertEditDistance(model, changes, 7);
});
- test('insert at beginning and end', () {
+ test('insert at beginning and end', () async {
var model = toObservable([2, 3, 4]);
var changes = model.listChanges.first;
model.insert(0, 5);
model[2] = 6;
model.add(7);
- return assertEditDistance(model, changes, 4);
+ await assertEditDistance(model, changes, 4);
});
});
}
diff --git a/test/observable_map_test.dart b/test/observable_map_test.dart
index 795328b..bddc091 100644
--- a/test/observable_map_test.dart
+++ b/test/observable_map_test.dart
@@ -9,9 +9,7 @@
import 'observable_test_utils.dart';
-main() => _runTests();
-
-_runTests() {
+void main() {
// TODO(jmesserly): need all standard Map API tests.
StreamSubscription sub;
diff --git a/test/observable_test.dart b/test/observable_test.dart
index fb07552..c902ba8 100644
--- a/test/observable_test.dart
+++ b/test/observable_test.dart
@@ -9,18 +9,16 @@
import 'observable_test_utils.dart';
-main() => observableTests();
-
-void observableTests() {
+void main() {
// Track the subscriptions so we can clean them up in tearDown.
- List subs;
+ List<StreamSubscription> subs;
setUp(() {
- subs = [];
+ subs = <StreamSubscription>[];
});
- tearDown(() {
- for (var sub in subs) sub.cancel();
+ tearDown(() async {
+ for (var sub in subs) await sub.cancel();
});
test('no observers', () {
@@ -83,7 +81,7 @@
t.value = 42;
});
- test('async processing model', () {
+ test('async processing model', () async {
var t = createModel(123);
var records = [];
subs.add(t.changes.listen((r) {
@@ -93,15 +91,16 @@
t.value = 42;
expectChanges(records, [], reason: 'changes delived async');
- return new Future(() {
- expectPropertyChanges(records, 2);
- records.clear();
+ await newMicrotask();
- t.value = 777;
- expectChanges(records, [], reason: 'changes delived async');
- }).then(newMicrotask).then((_) {
- expectPropertyChanges(records, 1);
- });
+ expectPropertyChanges(records, 2);
+ records.clear();
+
+ t.value = 777;
+ expectChanges(records, [], reason: 'changes delived async');
+
+ await newMicrotask();
+ expectPropertyChanges(records, 1);
});
test('cancel listening', () {
diff --git a/test/observable_test_utils.dart b/test/observable_test_utils.dart
index 9ce9161..91164c8 100644
--- a/test/observable_test_utils.dart
+++ b/test/observable_test_utils.dart
@@ -13,7 +13,7 @@
/// to happen in the next microtask:
///
/// future.then(newMicrotask).then(...)
-newMicrotask(_) => new Future.value();
+Future newMicrotask() => new Future.value();
// TODO(jmesserly): use matchers when we have a way to compare ChangeRecords.
// For now just use the toString.