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 // Dart test program for testing FileSystemEntity.absolute |
| 6 |
| 7 import "package:expect/expect.dart"; |
| 8 import 'dart:io'; |
| 9 |
| 10 main() { |
| 11 if (Platform.isWindows) { |
| 12 testWindows(); |
| 13 try { |
| 14 Directory.current = 'C:\\'; |
| 15 } catch (e) { |
| 16 return; |
| 17 } |
| 18 testWindows(); |
| 19 } else { |
| 20 testPosix(); |
| 21 Directory.current = '.'; |
| 22 testPosix(); |
| 23 Directory.current = '/'; |
| 24 testPosix(); |
| 25 |
| 26 } |
| 27 } |
| 28 |
| 29 testWindows() { |
| 30 String current = Directory.current.path; |
| 31 for (String relative in ['abd', '..', '.', 'efg/hij', 'abc/']) { |
| 32 if (current.endsWith('\\')) { |
| 33 Expect.equals(new File(relative).absolute.path, '$current$relative'); |
| 34 } else { |
| 35 Expect.equals(new File(relative).absolute.path, '$current\\$relative'); |
| 36 } |
| 37 Expect.isTrue(new File(relative).absolute.isAbsolute); |
| 38 } |
| 39 for (String absolute in ['c:/abd', 'D:\\rf', '\\\\a_share\\folder', |
| 40 '\\\\?\\c:\\prefixed\path\\']) { |
| 41 Expect.isTrue(new File(absolute).absolute.path == absolute); |
| 42 Expect.isTrue(new File(absolute).absolute.isAbsolute); |
| 43 } |
| 44 } |
| 45 |
| 46 testPosix() { |
| 47 String current = Directory.current.path; |
| 48 print(Directory.current.path); |
| 49 for (String relative in ['abd', '..', '.', 'efg/hij', 'abc/']) { |
| 50 if (current.endsWith('/')) { |
| 51 Expect.equals(new File(relative).absolute.path, '$current$relative'); |
| 52 } else { |
| 53 Expect.equals(new File(relative).absolute.path, '$current/$relative'); |
| 54 } |
| 55 Expect.isTrue(new File(relative).absolute.isAbsolute); |
| 56 Expect.equals(new Directory(relative).absolute.path, |
| 57 new Link(relative).absolute.path); |
| 58 Expect.isTrue(new File(relative).absolute is File); |
| 59 Expect.isTrue(new Directory(relative).absolute is Directory); |
| 60 Expect.isTrue(new Link(relative).absolute is Link); |
| 61 } |
| 62 for (String absolute in ['/abd', '/', '/./..\\', '/efg/hij', '/abc/']) { |
| 63 Expect.equals(new File(absolute).absolute.path, absolute); |
| 64 Expect.isTrue(new File(absolute).absolute.isAbsolute); |
| 65 } |
| 66 } |
OLD | NEW |