Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: pkg/observe/test/observe_test_utils.dart

Issue 19771010: implement dirty checking for @observable objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library observe.test.observe_test_utils;
6
7 import 'dart:async';
8 import 'package:observe/observe.dart';
9 import 'package:unittest/unittest.dart';
10
11 // TODO(jmesserly): use matchers when we have a way to compare ChangeRecords.
12 // For now just use the toString.
13 expectChanges(actual, expected, {reason}) =>
14 expect('$actual', '$expected', reason: reason);
15
16 void performMicrotaskCheckpoint() {
17 Observable.dirtyCheck();
18
19 while (_pending.length > 0) {
20 var pending = _pending;
21 _pending = [];
22
23 for (var callback in pending) {
24 try {
25 callback();
26 } catch (e, s) {
27 new Completer().completeError(e, s);
28 }
29 }
30
31 Observable.dirtyCheck();
32 }
33 }
34
35 List<Function> _pending = [];
36
37 wrapMicrotask(void testCase()) {
38 return () {
39 runZonedExperimental(() {
40 try {
41 testCase();
42 } finally {
43 performMicrotaskCheckpoint();
44 }
45 }, onRunAsync: (callback) => _pending.add(callback));
46 };
47 }
48
49 observeTest(name, testCase) => test(name, wrapMicrotask(testCase));
50
51 solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698