OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:io'; |
| 6 |
| 7 import "package:async_helper/async_helper.dart"; |
| 8 import "package:expect/expect.dart"; |
| 9 |
| 10 void testFromUri() { |
| 11 asyncStart(); |
| 12 Directory.systemTemp.createTemp('file_uri').then((temp) { |
| 13 String filename = temp.path + '/from_uri'; |
| 14 Uri fileUri = new Uri.file(filename); |
| 15 File file = new File.fromUri(fileUri); |
| 16 Expect.isTrue(fileUri.isAbsolute); |
| 17 Expect.isTrue(fileUri.path.startsWith('/')); |
| 18 file.createSync(); |
| 19 Expect.isTrue(new File.fromUri(fileUri).existsSync()); |
| 20 Expect.isTrue(new File.fromUri(Uri.base.resolveUri(fileUri)).existsSync()); |
| 21 Directory.current = temp.path; |
| 22 Expect.isTrue(new File.fromUri(Uri.parse('from_uri')).existsSync()); |
| 23 Expect.isTrue(new File.fromUri(Uri.base.resolve('from_uri')).existsSync()); |
| 24 file.deleteSync(); |
| 25 temp.deleteSync(recursive: true); |
| 26 asyncEnd(); |
| 27 }); |
| 28 } |
| 29 |
| 30 void testFromUriUnsupported() { |
| 31 Expect.throws( |
| 32 () => new File.fromUri( |
| 33 Uri.parse('http://localhost:8080/index.html')), |
| 34 (e) => e is UnsupportedError); |
| 35 Expect.throws(() => new File.fromUri(Uri.parse('ftp://localhost/tmp/xxx')), |
| 36 (e) => e is UnsupportedError); |
| 37 Expect.throws(() => new File.fromUri(Uri.parse('name#fragment')), |
| 38 (e) => e is UnsupportedError); |
| 39 } |
| 40 |
| 41 void main() { |
| 42 testFromUri(); |
| 43 testFromUriUnsupported(); |
| 44 } |
OLD | NEW |