|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a
|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
5 |
| -import 'dart:async'; |
6 |
| -import 'dart:io'; |
7 |
| -import 'dart:typed_data'; |
| 5 | +import "dart:async"; |
| 6 | +import "dart:io"; |
| 7 | +import "dart:typed_data"; |
8 | 8 |
|
9 |
| -import 'package:test/test.dart'; |
| 9 | +import "package:expect/expect.dart"; |
10 | 10 |
|
11 |
| -Future main() async { |
12 |
| - var asyncFile; |
13 |
| - var syncFile; |
| 11 | +testAsync() async { |
| 12 | + final tmp = await Directory.systemTemp.createTemp("non_utf8_file_test_async"); |
14 | 13 |
|
15 |
| - test('Non-UTF8 Filename', () async { |
16 |
| - final tmp = await Directory.systemTemp.createTemp( |
17 |
| - 'non_utf8_file_test_async', |
18 |
| - ); |
19 |
| - try { |
20 |
| - final rawPath = new Uint8List.fromList([182]); |
21 |
| - asyncFile = new File.fromRawPath(rawPath); |
22 |
| - if (Platform.isMacOS || Platform.isIOS) { |
23 |
| - try { |
24 |
| - await asyncFile.create(); |
25 |
| - } on FileSystemException catch (e) { |
26 |
| - // Macos doesn't support non-UTF-8 paths. |
27 |
| - await tmp.delete(recursive: true); |
28 |
| - return; |
29 |
| - } |
30 |
| - } else { |
| 14 | + try { |
| 15 | + final rawPath = new Uint8List.fromList([182]); |
| 16 | + final asyncFile = new File.fromRawPath(rawPath); |
| 17 | + if (Platform.isMacOS || Platform.isIOS) { |
| 18 | + try { |
31 | 19 | await asyncFile.create();
|
| 20 | + } on FileSystemException catch (e) { |
| 21 | + // Macos doesn"t support non-UTF-8 paths. |
| 22 | + await tmp.delete(recursive: true); |
| 23 | + return; |
32 | 24 | }
|
33 |
| - expect(await asyncFile.exists(), isTrue); |
| 25 | + } else { |
| 26 | + await asyncFile.create(); |
| 27 | + } |
| 28 | + Expect.isTrue(await asyncFile.exists()); |
34 | 29 |
|
35 |
| - for (final file in tmp.listSync()) { |
36 |
| - // FIXME(bkonyi): reenable when rawPath is exposed. |
37 |
| - /* |
38 |
| - if (Platform.isWindows) { |
39 |
| - // Windows replaces invalid characters with � when creating file system |
40 |
| - // entities. |
41 |
| - final raw = file.rawPath; |
42 |
| - expect(raw.sublist(raw.length - 3), [239, 191, 189]); |
43 |
| - } else { |
44 |
| - expect(file.rawPath.last, 182); |
45 |
| - } |
46 |
| - */ |
47 |
| - // FIXME(bkonyi): this isn't true on some versions of MacOS. Why? |
48 |
| - if (!Platform.isMacOS && !Platform.isIOS) { |
49 |
| - expect(file.path.endsWith('�'), isTrue); |
50 |
| - } |
| 30 | + for (final file in tmp.listSync()) { |
| 31 | + // FIXME(bkonyi): reenable when rawPath is exposed. |
| 32 | + /* |
| 33 | + if (Platform.isWindows) { |
| 34 | + // Windows replaces invalid characters with � when creating file system |
| 35 | + // entities. |
| 36 | + final raw = file.rawPath; |
| 37 | + Expect.listEquals(raw.sublist(raw.length - 3), [239, 191, 189]); |
| 38 | + } else { |
| 39 | + Expect.equals(file.rawPath.last, 182); |
| 40 | + } |
| 41 | + */ |
| 42 | + // FIXME(bkonyi): this isn"t true on some versions of MacOS. Why? |
| 43 | + if (!Platform.isMacOS && !Platform.isIOS) { |
| 44 | + Expect.isTrue(file.path.endsWith("�")); |
51 | 45 | }
|
52 |
| - await asyncFile.delete(); |
53 |
| - } finally { |
54 |
| - await tmp.delete(recursive: true); |
55 | 46 | }
|
56 |
| - }); |
| 47 | + await asyncFile.delete(); |
| 48 | + } finally { |
| 49 | + await tmp.delete(recursive: true); |
| 50 | + } |
| 51 | +} |
57 | 52 |
|
58 |
| - test('Non-UTF8 Filename Sync', () { |
59 |
| - final tmp = Directory.systemTemp.createTempSync('non_utf8_file_test_sync'); |
60 |
| - try { |
61 |
| - final rawPath = new Uint8List.fromList([182]); |
62 |
| - syncFile = new File.fromRawPath(rawPath); |
| 53 | +testSync() { |
| 54 | + final tmp = Directory.systemTemp.createTempSync("non_utf8_file_test_sync"); |
| 55 | + try { |
| 56 | + final rawPath = new Uint8List.fromList([182]); |
| 57 | + final syncFile = new File.fromRawPath(rawPath); |
63 | 58 |
|
64 |
| - if (Platform.isMacOS || Platform.isIOS) { |
65 |
| - try { |
66 |
| - syncFile.createSync(); |
67 |
| - } on FileSystemException catch (e) { |
68 |
| - // Macos doesn't support non-UTF-8 paths. |
69 |
| - tmp.deleteSync(recursive: true); |
70 |
| - return; |
71 |
| - } |
72 |
| - } else { |
| 59 | + if (Platform.isMacOS || Platform.isIOS) { |
| 60 | + try { |
73 | 61 | syncFile.createSync();
|
| 62 | + } on FileSystemException catch (e) { |
| 63 | + // Macos doesn"t support non-UTF-8 paths. |
| 64 | + tmp.deleteSync(recursive: true); |
| 65 | + return; |
74 | 66 | }
|
75 |
| - expect(syncFile.existsSync(), isTrue); |
| 67 | + } else { |
| 68 | + syncFile.createSync(); |
| 69 | + } |
| 70 | + Expect.isTrue(syncFile.existsSync()); |
76 | 71 |
|
77 |
| - for (final file in tmp.listSync()) { |
78 |
| - // FIXME(bkonyi): reenable when rawPath is exposed. |
79 |
| - /* |
80 |
| - if (Platform.isWindows) { |
81 |
| - // Windows replaces invalid characters with � when creating file system |
82 |
| - // entities. |
83 |
| - final raw = file.rawPath; |
84 |
| - expect(raw.sublist(raw.length - 3), [239, 191, 189]); |
85 |
| - } else { |
86 |
| - expect(file.rawPath.last, 182); |
87 |
| - } |
88 |
| - */ |
89 |
| - // FIXME(bkonyi): this isn't true on some versions of MacOS. Why? |
90 |
| - if (!Platform.isMacOS && !Platform.isIOS) { |
91 |
| - expect(file.path.endsWith('�'), isTrue); |
92 |
| - } |
| 72 | + for (final file in tmp.listSync()) { |
| 73 | + // FIXME(bkonyi): reenable when rawPath is exposed. |
| 74 | + /* |
| 75 | + if (Platform.isWindows) { |
| 76 | + // Windows replaces invalid characters with � when creating file system |
| 77 | + // entities. |
| 78 | + final raw = file.rawPath; |
| 79 | + Expect.listEquals(raw.sublist(raw.length - 3), [239, 191, 189]); |
| 80 | + } else { |
| 81 | + Expect.equals(file.rawPath.last, 182); |
| 82 | + } |
| 83 | + */ |
| 84 | + // FIXME(bkonyi): this isn"t true on some versions of MacOS. Why? |
| 85 | + if (!Platform.isMacOS && !Platform.isIOS) { |
| 86 | + Expect.isTrue(file.path.endsWith("�")); |
93 | 87 | }
|
94 |
| - syncFile.deleteSync(); |
95 |
| - } finally { |
96 |
| - tmp.deleteSync(recursive: true); |
97 | 88 | }
|
98 |
| - }); |
| 89 | + syncFile.deleteSync(); |
| 90 | + } finally { |
| 91 | + tmp.deleteSync(recursive: true); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +main() async { |
| 96 | + await testAsync(); |
| 97 | + testSync(); |
99 | 98 | }
|
0 commit comments