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

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

Issue 814013002: Support functions for testing multiple files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42455. 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 | « no previous file | 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
index 6bd2395276262a3dc661c49242eaf8b98c7e45ab..571311d703dbf6298e8572b0b0dbe961226a5c7f 100644
--- a/dart/tests/try/poi/source_update.dart
+++ b/dart/tests/try/poi/source_update.dart
@@ -39,3 +39,76 @@ List<String> expandUpdates(List updates) {
return result.map((e) => '$e').toList();
}
+
+/// Returns [files] split into mulitple named files. The keys in the returned
+/// map are filenames, the values are the files' content.
+///
+/// Names are indicated by a line on the form "==> filename <==". Spaces are
+/// significant. For example, given this input:
+///
+/// ==> file1.dart <==
+/// First line of file 1.
+/// Second line of file 1.
+/// Third line of file 1.
+/// ==> empty.dart <==
+/// ==> file2.dart <==
+/// First line of file 2.
+/// Second line of file 2.
+/// Third line of file 2.
+///
+/// This function would return:
+///
+/// {
+/// "file1.dart": """
+/// First line of file 1.
+/// Second line of file 1.
+/// Third line of file 1.
+/// """,
+///
+/// "empty.dart":"",
+///
+/// "file2.dart":"""
+/// First line of file 2.
+/// Second line of file 2.
+/// Third line of file 2.
+/// """
+/// }
+Map<String, String> splitFiles(String files) {
+ Map<String, String> result = <String, String>{};
+ String currentName;
+ List<String> content;
+ void finishFile() {
+ if (currentName != null) {
+ if (result.containsKey(currentName)) {
+ throw new ArgumentError("Duplicated filename $currentName in $files");
+ }
+ result[currentName] = content.join('');
+ }
+ content = null;
+ }
+ void processDirective(String line) {
+ finishFile();
+ if (line.length < 8 || !line.endsWith(" <==\n")) {
+ throw new ArgumentError(
+ "Malformed line: expected '==> ... <==', but got: '$line'");
+ }
+ currentName = line.substring(4, line.length - 5);
+ content = <String>[];
+ }
+ for (String line in splitLines(files)) {
+ if (line.startsWith("==>")) {
+ processDirective(line);
+ } else {
+ content.add(line);
+ }
+ }
+ finishFile();
+ return result;
+}
+
+/// Split [text] into lines preserving trailing newlines (unlike
+/// String.split("\n"). Also, if [text] is empty, return an empty list (unlike
+/// String.split("\n")).
+List<String> splitLines(String text) {
+ return text.split(new RegExp('^', multiLine: true));
+}
« no previous file with comments | « no previous file | dart/tests/try/poi/source_update_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698