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

Unified Diff: pkg/intl/test/data_directory.dart

Issue 12733003: Adds facilities for extracting Intl.message calls and generating code from translations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes from review comments, also made tests more robust, removed scheduled_test dependency Created 7 years, 9 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: pkg/intl/test/data_directory.dart
diff --git a/pkg/intl/test/data_directory.dart b/pkg/intl/test/data_directory.dart
index 96fa450d7abf3619aac659b866712636a160cd78..9cf6253dfa6a4e7abd0d9d18093366e4e8c79bd9 100644
--- a/pkg/intl/test/data_directory.dart
+++ b/pkg/intl/test/data_directory.dart
@@ -5,21 +5,43 @@
/**
* A utility function for test and tools that compensates (at least for very
* simple cases) for file-dependent programs being run from different
- * directories.
+ * directories. The important cases are
+ * -running in the directory that contains the test itself, i.e.
+ * pkg/intl/test or a sub-directory.
+ * -running in pkg/intl, which is where the editor will run things by default
+ * -running in the top-level dart directory, where the build tests run
*/
library data_directory;
-import 'dart:io';
+import "package:pathos/path.dart" as path;
-String get _sep => Platform.pathSeparator;
+String get dataDirectory {
+ return path.join(intlDirectory, datesRelativeToIntl);
+}
+
+String get intlDirectory {
+ var components = path.split(path.current);
+ var foundIntlDir = false;
-get dataDirectory {
- var current = new Directory.current().path;
- if (new RegExp('.*${_sep}test').hasMatch(current)) {
- return '..${_sep}lib${_sep}src${_sep}data${_sep}dates${_sep}';
+ /**
+ * A helper function that returns false (indicating we should stop iterating)
+ * if the argument to the previous call was 'intl' and also sets
+ * the outer scope [foundIntl].
+ */
+ bool checkForIntlDir(String each) {
+ if (foundIntlDir) return false;
+ foundIntlDir = (each == 'intl') ? true : false;
+ return true;
}
- if (new RegExp('.*${_sep}intl').hasMatch(current)) {
- return 'lib${_sep}src${_sep}data${_sep}dates${_sep}';
+
+ var pathUpToIntl = components.takeWhile(checkForIntlDir).toList();
+ // We assume that if we're not somewhere underneath the intl hierarchy
+ // that we are in the dart root.
+ if (foundIntlDir) {
+ return path.joinAll(pathUpToIntl);
+ } else {
+ return path.join(path.current, 'pkg', 'intl');
}
- return 'pkg${_sep}intl${_sep}lib${_sep}src${_sep}data${_sep}dates${_sep}';
}
+
+String get datesRelativeToIntl => path.join('lib', 'src', 'data', 'dates');

Powered by Google App Engine
This is Rietveld 408576698