Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A utility function for test and tools that compensates (at least for very | 6 * A utility function for test and tools that compensates (at least for very |
| 7 * simple cases) for file-dependent programs being run from different | 7 * simple cases) for file-dependent programs being run from different |
| 8 * directories. | 8 * directories. The important cases are |
| 9 * -running in the directory that contains the test itself, i.e. | |
| 10 * pkg/intl/test or a sub-directory. | |
| 11 * -running in pkg/intl, which is where the editor will run things by default | |
| 12 * -running in the top-level dart directory, where the build tests run | |
| 9 */ | 13 */ |
| 10 library data_directory; | 14 library data_directory; |
| 11 | 15 |
| 12 import 'dart:io'; | 16 import "package:pathos/path.dart" as path; |
| 13 | |
| 14 String get _sep => Platform.pathSeparator; | |
| 15 | 17 |
| 16 get dataDirectory { | 18 get dataDirectory { |
| 17 var current = new Directory.current().path; | 19 return path.join(intlDirectory, datesRelativeToIntl); |
| 18 if (new RegExp('.*${_sep}test').hasMatch(current)) { | 20 } |
| 19 return '..${_sep}lib${_sep}src${_sep}data${_sep}dates${_sep}'; | 21 |
| 22 bool foundIntl; | |
|
Emily Fortuna
2013/03/13 18:54:43
shadowed?
Alan Knight
2013/03/14 17:49:05
Deleted.
| |
| 23 bool _checkForIntl() { | |
|
Emily Fortuna
2013/03/13 18:54:43
can this function be deleted?
Alan Knight
2013/03/14 17:49:05
Done.
| |
| 24 | |
| 25 } | |
| 26 | |
| 27 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.
| |
| 28 var components = path.split(path.current); | |
| 29 var foundIntl = false; | |
| 30 | |
| 31 /** | |
| 32 * A helper function that returns false (indicating we should stop iterating) | |
| 33 * if the argument to the previous call was 'intl' and also sets | |
| 34 * the outer scope [foundIntl]. | |
| 35 */ | |
| 36 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.
| |
| 37 if (foundIntl) return false; | |
| 38 foundIntl = (each == 'intl') ? true : false; | |
| 39 return true; | |
| 20 } | 40 } |
| 21 if (new RegExp('.*${_sep}intl').hasMatch(current)) { | 41 |
| 22 return 'lib${_sep}src${_sep}data${_sep}dates${_sep}'; | 42 var pathUpToIntl = components.takeWhile(checkForIntl).toList(); |
| 43 // We assume that if we're not somewhere underneath the intl hierarchy | |
| 44 // that we are in the dart root. | |
| 45 if (foundIntl) { | |
| 46 return path.joinAll(pathUpToIntl); | |
| 47 } else { | |
| 48 return path.join(path.current, 'pkg', 'intl'); | |
| 23 } | 49 } |
| 24 return 'pkg${_sep}intl${_sep}lib${_sep}src${_sep}data${_sep}dates${_sep}'; | |
| 25 } | 50 } |
| 51 | |
| 52 get datesRelativeToIntl => path.join('lib', 'src', 'data', 'dates'); | |
| OLD | NEW |