Chromium Code Reviews| 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..d6a6a6dd431ed878bfa8bb872ef9be3da9944d0e 100644 |
| --- a/pkg/intl/test/data_directory.dart |
| +++ b/pkg/intl/test/data_directory.dart |
| @@ -5,21 +5,48 @@ |
| /** |
| * 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'; |
| - |
| -String get _sep => Platform.pathSeparator; |
| +import "package:pathos/path.dart" as path; |
| 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}'; |
| + return path.join(intlDirectory, datesRelativeToIntl); |
| +} |
| + |
| +bool foundIntl; |
|
Emily Fortuna
2013/03/13 18:54:43
shadowed?
Alan Knight
2013/03/14 17:49:05
Deleted.
|
| +bool _checkForIntl() { |
|
Emily Fortuna
2013/03/13 18:54:43
can this function be deleted?
Alan Knight
2013/03/14 17:49:05
Done.
|
| + |
| +} |
| + |
| +get intlDirectory { |
|
Emily Fortuna
2013/03/13 18:54:43
Can you list the return types for these getters?
Alan Knight
2013/03/14 17:49:05
Done.
|
| + var components = path.split(path.current); |
| + var foundIntl = false; |
| + |
| + /** |
| + * 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 checkForIntl(String each) { |
|
Emily Fortuna
2013/03/13 18:54:43
rename suggestion "checkForIntlDir" just to more c
Alan Knight
2013/03/14 17:49:05
Done.
|
| + if (foundIntl) return false; |
| + foundIntl = (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(checkForIntl).toList(); |
| + // We assume that if we're not somewhere underneath the intl hierarchy |
| + // that we are in the dart root. |
| + if (foundIntl) { |
| + 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}'; |
| } |
| + |
| +get datesRelativeToIntl => path.join('lib', 'src', 'data', 'dates'); |