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

Unified Diff: dart/tests/try/poi/source_update.dart

Issue 799403005: Avoid repeating common parts of ProgramResults. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42384. Created 6 years 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 | « dart/tests/try/poi/library_updater_test.dart ('k') | dart/tests/try/poi/source_update_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/tests/try/poi/source_update.dart
diff --git a/dart/tests/try/poi/source_update.dart b/dart/tests/try/poi/source_update.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6bd2395276262a3dc661c49242eaf8b98c7e45ab
--- /dev/null
+++ b/dart/tests/try/poi/source_update.dart
@@ -0,0 +1,41 @@
+// Copyright (c) 2014, 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.
+
+library trydart.source_update;
+
+/// Returns [updates] expanded to full compilation units/source files.
+///
+/// [updates] is a convenient way to write updates/patches to a single source
+/// file without repeating common parts.
+///
+/// For example:
+/// ["head ", ["v1", "v2"], " tail"]
+/// expands to:
+/// ["head v1 tail", "head v2 tail"]
+List<String> expandUpdates(List updates) {
+ int outputCount = updates.firstWhere((e) => e is Iterable).length;
+ List<StringBuffer> result = new List<StringBuffer>(outputCount);
+ for (int i = 0; i < outputCount; i++) {
+ result[i] = new StringBuffer();
+ }
+ for (var chunk in updates) {
+ if (chunk is Iterable) {
+ int segmentCount = 0;
+ for (var segment in chunk) {
+ result[segmentCount++].write(segment);
+ }
+ if (segmentCount != outputCount) {
+ throw new ArgumentError(
+ "Expected ${outputCount} segments, "
+ "but found ${segmentCount} in $chunk");
+ }
+ } else {
+ for (StringBuffer buffer in result) {
+ buffer.write(chunk);
+ }
+ }
+ }
+
+ return result.map((e) => '$e').toList();
+}
« no previous file with comments | « dart/tests/try/poi/library_updater_test.dart ('k') | dart/tests/try/poi/source_update_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698