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

Unified 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, 4 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/result/result_flattenAll_test.dart
diff --git a/test/result/result_flattenAll_test.dart b/test/result/result_flattenAll_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..caaf668e6a6299bbd63337477fed9720cf7cc2db
--- /dev/null
+++ b/test/result/result_flattenAll_test.dart
@@ -0,0 +1,54 @@
+// Copyright (c) 2017, 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.
+
+import "package:async/async.dart";
+import "package:test/test.dart";
+
+final someStack = StackTrace.current;
+Result<T> res<T>(T n) => new Result<T>.value(n);
+Result err(n) => new ErrorResult("$n", someStack);
+
+/// Helper function creating an iterable of results.
+Iterable<Result<int>> results(int count, {bool throwWhen(int index)}) sync* {
+ for (int i = 0; i < count; i++) {
+ if (throwWhen != null && throwWhen(i)) {
+ yield err(i);
+ } else {
+ yield res(i);
+ }
+ }
+}
+
+main() {
+ expectAll(result, expectation) {
+ if (expectation.isError) {
+ expect(result, expectation);
+ } else {
+ expect(result.isValue, true);
+ expect(result.asValue.value, expectation.asValue.value);
+ }
+ }
+
+ test("empty", () {
+ expectAll(Result.flattenAll<int>(results(0)), res([]));
+ });
+ test("single value", () {
+ expectAll(Result.flattenAll<int>(results(1)), res([0]));
+ });
+ test("single error", () {
+ expectAll(
+ Result.flattenAll<int>(results(1, throwWhen: (_) => true)), err(0));
+ });
+ test("multiple values", () {
+ expectAll(Result.flattenAll<int>(results(5)), res([0, 1, 2, 3, 4]));
+ });
+ test("multiple errors", () {
+ expectAll(Result.flattenAll<int>(results(5, throwWhen: (x) => x.isOdd)),
+ err(1)); // First error is result.
+ });
+ test("error last", () {
+ expectAll(
+ Result.flattenAll<int>(results(5, throwWhen: (x) => x == 4)), err(4));
+ });
+}
« 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