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

Side by Side Diff: test/async_memoizer_test.dart

Issue 1324743003: Add AsyncMemoizer.future. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Mark as -dev Created 5 years, 3 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
« lib/src/async_memoizer.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:async/async.dart'; 7 import 'package:async/async.dart';
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 9
10 main() { 10 main() {
11 var cache; 11 var cache;
12 setUp(() => cache = new AsyncMemoizer()); 12 setUp(() => cache = new AsyncMemoizer());
13 13
14 test("runs the function only the first time runOnce() is called", () async { 14 test("runs the function only the first time runOnce() is called", () async {
15 var count = 0; 15 var count = 0;
16 expect(await cache.runOnce(() => count++), equals(0)); 16 expect(await cache.runOnce(() => count++), equals(0));
17 expect(count, equals(1)); 17 expect(count, equals(1));
18 18
19 expect(await cache.runOnce(() => count++), equals(0)); 19 expect(await cache.runOnce(() => count++), equals(0));
20 expect(count, equals(1)); 20 expect(count, equals(1));
21 }); 21 });
22 22
23 test("forwards the return value from the function", () async { 23 test("forwards the return value from the function", () async {
24 expect(cache.future, completion(equals("value")));
24 expect(cache.runOnce(() => "value"), completion(equals("value"))); 25 expect(cache.runOnce(() => "value"), completion(equals("value")));
25 expect(cache.runOnce(() {}), completion(equals("value"))); 26 expect(cache.runOnce(() {}), completion(equals("value")));
26 }); 27 });
27 28
28 test("forwards the return value from an async function", () async { 29 test("forwards the return value from an async function", () async {
30 expect(cache.future, completion(equals("value")));
29 expect(cache.runOnce(() async => "value"), completion(equals("value"))); 31 expect(cache.runOnce(() async => "value"), completion(equals("value")));
30 expect(cache.runOnce(() {}), completion(equals("value"))); 32 expect(cache.runOnce(() {}), completion(equals("value")));
31 }); 33 });
32 34
33 test("forwards the error from an async function", () async { 35 test("forwards the error from an async function", () async {
36 expect(cache.future, throwsA("error"));
34 expect(cache.runOnce(() async => throw "error"), throwsA("error")); 37 expect(cache.runOnce(() async => throw "error"), throwsA("error"));
35 expect(cache.runOnce(() {}), throwsA("error")); 38 expect(cache.runOnce(() {}), throwsA("error"));
36 }); 39 });
37 } 40 }
OLDNEW
« lib/src/async_memoizer.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698