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 import 'dart:io'; | 5 import 'dart:io'; |
6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
7 | 7 |
8 main() { | 8 main() { |
9 ReceivePort port = new ReceivePort(); | 9 ReceivePort port = new ReceivePort(); |
10 | 10 |
11 // On MacOS you get the decomposed utf8 form of file and directory | 11 // On MacOS you get the decomposed utf8 form of file and directory |
12 // names from the system. Therefore, we have to check for both here. | 12 // names from the system. Therefore, we have to check for both here. |
13 var precomposed = 'æøå'; | 13 var precomposed = 'æøå'; |
14 var decomposed = new String.fromCharCodes([47, 230, 248, 97, 778]); | 14 var decomposed = new String.fromCharCodes([47, 230, 248, 97, 778]); |
15 | 15 |
16 new Directory('').createTemp().then((tempDir) { | 16 new Directory('').createTemp().then((tempDir) { |
17 Directory nonAsciiDir = new Directory('${tempDir.path}/æøå'); | 17 Directory nonAsciiDir = new Directory('${tempDir.path}/æøå'); |
18 nonAsciiDir.create().then((nonAsciiDir) { | 18 nonAsciiDir.create().then((nonAsciiDir) { |
19 nonAsciiDir.exists().then((result) { | 19 nonAsciiDir.exists().then((result) { |
20 Expect.isTrue(result); | 20 Expect.isTrue(result); |
21 File nonAsciiFile = new File('${nonAsciiDir.path}/æøå.txt'); | 21 File nonAsciiFile = new File('${nonAsciiDir.path}/æøå.txt'); |
22 nonAsciiFile.open(FileMode.WRITE).then((opened) { | 22 nonAsciiFile.writeAsString('æøå').then((_) { |
23 opened.writeString('æøå').then((_) { | 23 nonAsciiFile.exists().then((result) { |
24 opened.close().then((_) { | 24 Expect.isTrue(result); |
25 nonAsciiFile.exists().then((result) { | 25 nonAsciiFile.readAsString().then((contents) { |
26 Expect.isTrue(result); | 26 // The contents of the file is precomposed utf8. |
27 nonAsciiFile.readAsString().then((contents) { | 27 Expect.equals(precomposed, contents); |
28 // The contents of the file is precomposed utf8. | 28 nonAsciiFile.create().then((_) { |
29 Expect.equals(precomposed, contents); | 29 nonAsciiFile.directory().then((d) { |
30 nonAsciiFile.create().then((_) { | 30 Expect.isTrue(d.path.endsWith(precomposed) || |
31 nonAsciiFile.directory().then((d) { | 31 d.path.endsWith(decomposed)); |
32 Expect.isTrue(d.path.endsWith(precomposed) || | 32 nonAsciiFile.length().then((length) { |
33 d.path.endsWith(decomposed)); | 33 Expect.equals(6, length); |
34 nonAsciiFile.length().then((length) { | 34 nonAsciiFile.lastModified().then((_) { |
35 Expect.equals(6, length); | 35 nonAsciiFile.fullPath().then((path) { |
36 nonAsciiFile.lastModified().then((_) { | 36 Expect.isTrue(path.endsWith('${precomposed}.txt') || |
37 nonAsciiFile.fullPath().then((path) { | 37 path.endsWith('${decomposed}.txt')); |
38 Expect.isTrue(path.endsWith('${precomposed}.txt') || | 38 tempDir.delete(recursive: true).then((_) { |
39 path.endsWith('${decomposed}.txt')); | 39 port.close(); |
40 tempDir.delete(recursive: true).then((_) { | |
41 port.close(); | |
42 }); | |
43 }); | |
44 }); | 40 }); |
45 }); | 41 }); |
46 }); | 42 }); |
47 }); | 43 }); |
48 }); | 44 }); |
49 }); | 45 }); |
50 }); | 46 }); |
51 }); | 47 }); |
52 }); | 48 }); |
53 }); | 49 }); |
54 }); | 50 }); |
55 }); | 51 }); |
56 } | 52 } |
OLD | NEW |