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

Side by Side Diff: test/result/result_flattenAll_test.dart

Issue 2996143002: Add methods to Result. Bump version to 2.0 and remove deprecated features. (Closed)
Patch Set: Address comments, run dartfmt on tests too. Created 3 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
« no previous file with comments | « test/result/result_captureAll_test.dart ('k') | test/result/result_future_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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 import "package:async/async.dart";
6 import "package:test/test.dart";
7
8 final someStack = StackTrace.current;
9 Result<T> res<T>(T n) => new Result<T>.value(n);
10 Result err(n) => new ErrorResult("$n", someStack);
11
12 /// Helper function creating an iterable of results.
13 Iterable<Result<int>> results(int count, {bool throwWhen(int index)}) sync* {
14 for (int i = 0; i < count; i++) {
15 if (throwWhen != null && throwWhen(i)) {
16 yield err(i);
17 } else {
18 yield res(i);
19 }
20 }
21 }
22
23 main() {
24 expectAll(result, expectation) {
25 if (expectation.isError) {
26 expect(result, expectation);
27 } else {
28 expect(result.isValue, true);
29 expect(result.asValue.value, expectation.asValue.value);
30 }
31 }
32
33 test("empty", () {
34 expectAll(Result.flattenAll<int>(results(0)), res([]));
35 });
36 test("single value", () {
37 expectAll(Result.flattenAll<int>(results(1)), res([0]));
38 });
39 test("single error", () {
40 expectAll(
41 Result.flattenAll<int>(results(1, throwWhen: (_) => true)), err(0));
42 });
43 test("multiple values", () {
44 expectAll(Result.flattenAll<int>(results(5)), res([0, 1, 2, 3, 4]));
45 });
46 test("multiple errors", () {
47 expectAll(Result.flattenAll<int>(results(5, throwWhen: (x) => x.isOdd)),
48 err(1)); // First error is result.
49 });
50 test("error last", () {
51 expectAll(
52 Result.flattenAll<int>(results(5, throwWhen: (x) => x == 4)), err(4));
53 });
54 }
OLDNEW
« no previous file with comments | « test/result/result_captureAll_test.dart ('k') | test/result/result_future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698