| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 void testFromUri() { | 10 void testFromUri() { |
| 11 asyncStart(); | 11 asyncStart(); |
| 12 Directory originalWorkingDirectory = Directory.current; |
| 12 Directory.systemTemp.createTemp('directory_uri').then((temp) { | 13 Directory.systemTemp.createTemp('directory_uri').then((temp) { |
| 13 String dirname = temp.path + '/from_uri'; | 14 String dirname = temp.path + '/from_uri'; |
| 14 Uri dirUri = new Uri.file(dirname); | 15 Uri dirUri = new Uri.file(dirname); |
| 15 Directory dir = new Directory.fromUri(dirUri); | 16 Directory dir = new Directory.fromUri(dirUri); |
| 16 Expect.isTrue(dirUri.isAbsolute); | 17 Expect.isTrue(dirUri.isAbsolute); |
| 17 Expect.isTrue(dirUri.path.startsWith('/')); | 18 Expect.isTrue(dirUri.path.startsWith('/')); |
| 18 dir.createSync(); | 19 dir.createSync(); |
| 19 Expect.isTrue(new Directory.fromUri(dirUri).existsSync()); | 20 Expect.isTrue(new Directory.fromUri(dirUri).existsSync()); |
| 20 Expect.isTrue( | 21 Expect.isTrue( |
| 21 new Directory.fromUri(Uri.base.resolveUri(dirUri)).existsSync()); | 22 new Directory.fromUri(Uri.base.resolveUri(dirUri)).existsSync()); |
| 22 Directory.current = temp.path; | 23 Directory.current = temp.path; |
| 23 Expect.isTrue(new Directory.fromUri(Uri.parse('from_uri')).existsSync()); | 24 Expect.isTrue(new Directory.fromUri(Uri.parse('from_uri')).existsSync()); |
| 24 Expect.isTrue( | 25 Expect.isTrue( |
| 25 new Directory.fromUri(Uri.base.resolve('from_uri')).existsSync()); | 26 new Directory.fromUri(Uri.base.resolve('from_uri')).existsSync()); |
| 27 Directory.current = originalWorkingDirectory; |
| 26 dir.deleteSync(); | 28 dir.deleteSync(); |
| 27 temp.deleteSync(recursive: true); | 29 temp.deleteSync(recursive: true); |
| 28 asyncEnd(); | 30 asyncEnd(); |
| 29 }); | 31 }); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void testFromUriUnsupported() { | 34 void testFromUriUnsupported() { |
| 33 Expect.throws( | 35 Expect.throws( |
| 34 () => new Directory.fromUri( | 36 () => new Directory.fromUri( |
| 35 Uri.parse('http://localhost:8080/index.html')), | 37 Uri.parse('http://localhost:8080/index.html')), |
| 36 (e) => e is UnsupportedError); | 38 (e) => e is UnsupportedError); |
| 37 Expect.throws( | 39 Expect.throws( |
| 38 () => new Directory.fromUri(Uri.parse('ftp://localhost/tmp/xxx')), | 40 () => new Directory.fromUri(Uri.parse('ftp://localhost/tmp/xxx')), |
| 39 (e) => e is UnsupportedError); | 41 (e) => e is UnsupportedError); |
| 40 Expect.throws(() => new Directory.fromUri(Uri.parse('name#fragment')), | 42 Expect.throws(() => new Directory.fromUri(Uri.parse('name#fragment')), |
| 41 (e) => e is UnsupportedError); | 43 (e) => e is UnsupportedError); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void main() { | 46 void main() { |
| 45 testFromUri(); | 47 testFromUri(); |
| 46 testFromUriUnsupported(); | 48 testFromUriUnsupported(); |
| 47 } | 49 } |
| OLD | NEW |