Chromium Code Reviews| Index: tests/corelib/src/FuturesTest.dart |
| =================================================================== |
| --- tests/corelib/src/FuturesTest.dart (revision 0) |
| +++ tests/corelib/src/FuturesTest.dart (revision 0) |
| @@ -0,0 +1,53 @@ |
| +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +class FuturesTest { |
| + static void testMain() { |
| + List<Future> futures = new List<Future>(); |
| + |
| + futures.add(testWaitEmpty()); |
| + futures.add(testCompleteAfterWait()); |
| + futures.add(testCompleteBeforeWait()); |
| + |
| + // Use a receive port for blocking the test. |
| + // Note that if the test fails, the program will not end. |
| + ReceivePort port = new ReceivePort(); |
| + Futures.wait(futures).then((List list) { |
| + Expect.equals(list.length, 3); |
|
kasperl
2012/01/06 09:06:46
Weird indentation. Emacs user?
kasperl
2012/01/06 09:06:46
Expect.equals(3, list.length) -- expectation, actu
Anders Johnsen
2012/01/06 09:28:33
Vim, fixed :)
|
| + port.close(); |
| + }); |
| + } |
| + |
| + static void testWaitEmpty() { |
|
kasperl
2012/01/06 09:06:46
Your void methods return values. Seems wrong.
Anders Johnsen
2012/01/06 09:28:33
Done.
|
| + List<Future> futures = new List<Future>(); |
| + |
| + return Futures.wait(futures); |
| + } |
| + |
| + static void testCompleteAfterWait() { |
| + List<Future> futures = new List<Future>(); |
| + Completer<Object> c = new Completer<Object>(); |
| + futures.add(c.future); |
| + |
|
kasperl
2012/01/06 09:06:46
I would use less newlines here.
Anders Johnsen
2012/01/06 09:28:33
Done.
|
| + Future future = Futures.wait(futures); |
| + |
| + c.complete(null); |
| + |
| + return future; |
| + } |
| + |
| + static void testCompleteBeforeWait() { |
| + List<Future> futures = new List<Future>(); |
| + Completer c = new Completer(); |
| + futures.add(c.future); |
| + |
|
kasperl
2012/01/06 09:06:46
.. and here.
Anders Johnsen
2012/01/06 09:28:33
Done.
|
| + c.complete(null); |
| + |
| + return Futures.wait(futures); |
| + } |
| +} |
| + |
| +main() { |
| + FuturesTest.testMain(); |
|
kasperl
2012/01/06 09:06:46
Maybe this would actually be nicer without the cla
Anders Johnsen
2012/01/06 09:28:33
Yeah, but using a class with static members follow
|
| +} |