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

Unified Diff: tests/corelib/iterable_mapping_test.dart

Issue 12041045: List.mappedBy/skip/take returns a List. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
Index: tests/corelib/iterable_mapping_test.dart
diff --git a/tests/corelib/iterable_mapping_test.dart b/tests/corelib/iterable_mapping_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4278169bd1424f57d15e7e42d3675bdc3073875c
--- /dev/null
+++ b/tests/corelib/iterable_mapping_test.dart
@@ -0,0 +1,57 @@
+// Copyright (c) 2013, 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.
+
+main() {
+ List<int> list1 = <int>[1, 2, 3];
+ List<int> list2 = const <int>[4, 5];
+ List<String> list3 = <String>[];
+ Set<int> set1 = new Set<int>();
+ set1..add(11)
Lasse Reichstein Nielsen 2013/01/24 06:49:32 Why not set1.addAll([1, 2, 3]); ? What is the purp
floitsch 2013/01/24 13:48:34 Done.
+ ..add(12)
+ ..add(13);
+ Set set2 = new Set();
+
+ Iterable mapped = list1.mappedBy((x) => x + 1);
Lasse Reichstein Nielsen 2013/01/24 06:49:32 Why "Iterable" and not "List"?
floitsch 2013/01/24 13:48:34 Because I want to prepare for the change back.
+ Expect.isTrue(mapped is List);
+ Expect.listEquals([2, 3, 4], mapped.toList());
Lasse Reichstein Nielsen 2013/01/24 06:49:32 And why .toList then?
floitsch 2013/01/24 13:48:34 removed.
+
+ mapped = mapped.mappedBy((x) => x + 1);
+ Expect.isTrue(mapped is List);
+ Expect.listEquals([3, 4, 5], mapped.toList());
+
+ mapped = list2.mappedBy((x) => x + 1);
+ Expect.isTrue(mapped is List);
+ Expect.listEquals([5, 6], mapped.toList());
+
+ mapped = mapped.mappedBy((x) => x + 1);
+ Expect.isTrue(mapped is List);
+ Expect.listEquals([6, 7], mapped.toList());
+
+ mapped = list3.mappedBy((x) => x + 1);
+ Expect.isTrue(mapped is List);
+ Expect.listEquals([], mapped.toList());
+
+ mapped = mapped.mappedBy((x) => x + 1);
+ Expect.isTrue(mapped is List);
+ Expect.listEquals([], mapped.toList());
+
+ var expected = new Set<int>()..add(12)..add(13)..add(14);
+ mapped = set1.mappedBy((x) => x + 1);
+ Expect.isFalse(mapped is List);
+ Expect.setEquals(expected, mapped.toSet());
+
+ expected = new Set<int>()..add(13)..add(14)..add(15);
+ mapped = mapped.mappedBy((x) => x + 1);
+ Expect.isFalse(mapped is List);
+ Expect.setEquals(expected, mapped.toSet());
+
+ mapped = set2.mappedBy((x) => x + 1);
+ Expect.isFalse(mapped is List);
+ Expect.listEquals([], mapped.toList());
+
+ mapped = mapped.mappedBy((x) => x + 1);
+ Expect.isFalse(mapped is List);
+ Expect.listEquals([], mapped.toList());
+
+}

Powered by Google App Engine
This is Rietveld 408576698