OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 // SharedOptions=--supermixin | 4 // SharedOptions=--supermixin |
5 | 5 |
6 library front_end.test.memory_file_system_test; | 6 library front_end.test.memory_file_system_test; |
7 | 7 |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
10 | 10 |
| 11 import 'package:front_end/file_system.dart' show FileSystemException; |
11 import 'package:front_end/memory_file_system.dart'; | 12 import 'package:front_end/memory_file_system.dart'; |
12 import 'package:path/path.dart' as pathos; | 13 import 'package:path/path.dart' as pathos; |
13 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
15 | 16 |
16 main() { | 17 main() { |
17 defineReflectiveSuite(() { | 18 defineReflectiveSuite(() { |
18 defineReflectiveTests(MemoryFileSystemTestNative); | 19 defineReflectiveTests(MemoryFileSystemTestNative); |
19 defineReflectiveTests(MemoryFileSystemTestPosix); | 20 defineReflectiveTests(MemoryFileSystemTestPosix); |
20 defineReflectiveTests(MemoryFileSystemTestWindows); | 21 defineReflectiveTests(MemoryFileSystemTestWindows); |
21 defineReflectiveTests(FileTest); | 22 defineReflectiveTests(FileTest); |
22 }); | 23 }); |
23 } | 24 } |
24 | 25 |
| 26 const Matcher _throwsFileSystemException = |
| 27 const Throws(const isInstanceOf<FileSystemException>()); |
| 28 |
25 @reflectiveTest | 29 @reflectiveTest |
26 class FileTest extends _BaseTestNative { | 30 class FileTest extends _BaseTestNative { |
27 String path; | 31 String path; |
28 MemoryFileSystemEntity file; | 32 MemoryFileSystemEntity file; |
29 | 33 |
30 setUp() { | 34 setUp() { |
31 super.setUp(); | 35 super.setUp(); |
32 path = join(tempPath, 'file.txt'); | 36 path = join(tempPath, 'file.txt'); |
33 file = entityForPath(path); | 37 file = entityForPath(path); |
34 } | 38 } |
35 | 39 |
36 test_equals_differentPaths() { | 40 test_equals_differentPaths() { |
37 expect(file == entityForPath(join(tempPath, 'file2.txt')), isFalse); | 41 expect(file == entityForPath(join(tempPath, 'file2.txt')), isFalse); |
38 } | 42 } |
39 | 43 |
40 test_equals_samePath() { | 44 test_equals_samePath() { |
41 expect(file == entityForPath(join(tempPath, 'file.txt')), isTrue); | 45 expect(file == entityForPath(join(tempPath, 'file.txt')), isTrue); |
42 } | 46 } |
43 | 47 |
| 48 test_exists_doesNotExist() async { |
| 49 expect(await file.exists(), false); |
| 50 } |
| 51 |
| 52 test_exists_exists() async { |
| 53 file.writeAsStringSync('x'); |
| 54 expect(await file.exists(), true); |
| 55 } |
| 56 |
44 test_hashCode_samePath() { | 57 test_hashCode_samePath() { |
45 expect(file.hashCode, entityForPath(join(tempPath, 'file.txt')).hashCode); | 58 expect(file.hashCode, entityForPath(join(tempPath, 'file.txt')).hashCode); |
46 } | 59 } |
47 | 60 |
| 61 test_lastModified_doesNotExist() async { |
| 62 expect(file.lastModified(), _throwsFileSystemException); |
| 63 } |
| 64 |
| 65 test_lastModified_increasesOnEachChange() async { |
| 66 file.writeAsStringSync('x'); |
| 67 var mod1 = await file.lastModified(); |
| 68 file.writeAsStringSync('y'); |
| 69 var mod2 = await file.lastModified(); |
| 70 expect(mod2.isAfter(mod1), isTrue); |
| 71 |
| 72 var file2 = entityForPath(join(tempPath, 'file2.txt')); |
| 73 file2.writeAsStringSync('z'); |
| 74 var mod3 = await file2.lastModified(); |
| 75 expect(mod3.isAfter(mod2), isTrue); |
| 76 } |
| 77 |
48 test_path() { | 78 test_path() { |
49 expect(file.uri, context.toUri(path)); | 79 expect(file.uri, context.toUri(path)); |
50 } | 80 } |
51 | 81 |
52 test_readAsBytes_badUtf8() async { | 82 test_readAsBytes_badUtf8() async { |
53 // A file containing invalid UTF-8 can still be read as raw bytes. | 83 // A file containing invalid UTF-8 can still be read as raw bytes. |
54 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8 | 84 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8 |
55 file.writeAsBytesSync(bytes); | 85 file.writeAsBytesSync(bytes); |
56 expect(await file.readAsBytes(), bytes); | 86 expect(await file.readAsBytes(), bytes); |
57 } | 87 } |
58 | 88 |
59 test_readAsBytes_doesNotExist() { | 89 test_readAsBytes_doesNotExist() { |
60 expect(file.readAsBytes(), throwsException); | 90 expect(file.readAsBytes(), _throwsFileSystemException); |
61 } | 91 } |
62 | 92 |
63 test_readAsBytes_exists() async { | 93 test_readAsBytes_exists() async { |
64 var s = 'contents'; | 94 var s = 'contents'; |
65 file.writeAsStringSync(s); | 95 file.writeAsStringSync(s); |
66 expect(await file.readAsBytes(), UTF8.encode(s)); | 96 expect(await file.readAsBytes(), UTF8.encode(s)); |
67 } | 97 } |
68 | 98 |
69 test_readAsString_badUtf8() { | 99 test_readAsString_badUtf8() { |
70 file.writeAsBytesSync([0xc0, 0x40]); // Invalid UTF-8 | 100 file.writeAsBytesSync([0xc0, 0x40]); // Invalid UTF-8 |
71 expect(file.readAsString(), throwsException); | 101 expect(file.readAsString(), _throwsFileSystemException); |
72 } | 102 } |
73 | 103 |
74 test_readAsString_doesNotExist() { | 104 test_readAsString_doesNotExist() { |
75 expect(file.readAsString(), throwsException); | 105 expect(file.readAsString(), _throwsFileSystemException); |
76 } | 106 } |
77 | 107 |
78 test_readAsString_exists() async { | 108 test_readAsString_exists() async { |
79 var s = 'contents'; | 109 var s = 'contents'; |
80 file.writeAsStringSync(s); | 110 file.writeAsStringSync(s); |
81 expect(await file.readAsString(), s); | 111 expect(await file.readAsString(), s); |
82 } | 112 } |
83 | 113 |
84 test_readAsString_utf8() async { | 114 test_readAsString_utf8() async { |
85 file.writeAsBytesSync([0xe2, 0x82, 0xac]); // Unicode € symbol, in UTF-8 | 115 file.writeAsBytesSync([0xe2, 0x82, 0xac]); // Unicode € symbol, in UTF-8 |
86 expect(await file.readAsString(), '\u20ac'); | 116 expect(await file.readAsString(), '\u20ac'); |
87 } | 117 } |
88 | 118 |
89 test_exists_doesNotExist() async { | |
90 expect(await file.exists(), false); | |
91 } | |
92 | |
93 test_exists_exists() async { | |
94 file.writeAsStringSync('x'); | |
95 expect(await file.exists(), true); | |
96 } | |
97 | |
98 test_lastModified_doesNotExist() async { | |
99 expect(file.lastModified(), throwsException); | |
100 } | |
101 | |
102 test_lastModified_increasesOnEachChange() async { | |
103 file.writeAsStringSync('x'); | |
104 var mod1 = await file.lastModified(); | |
105 file.writeAsStringSync('y'); | |
106 var mod2 = await file.lastModified(); | |
107 expect(mod2.isAfter(mod1), isTrue); | |
108 | |
109 var file2 = entityForPath(join(tempPath, 'file2.txt')); | |
110 file2.writeAsStringSync('z'); | |
111 var mod3 = await file2.lastModified(); | |
112 expect(mod3.isAfter(mod2), isTrue); | |
113 } | |
114 | |
115 test_writeAsBytesSync_modifyAfterRead() async { | 119 test_writeAsBytesSync_modifyAfterRead() async { |
116 file.writeAsBytesSync([1]); | 120 file.writeAsBytesSync([1]); |
117 (await file.readAsBytes())[0] = 2; | 121 (await file.readAsBytes())[0] = 2; |
118 expect(await file.readAsBytes(), [1]); | 122 expect(await file.readAsBytes(), [1]); |
119 } | 123 } |
120 | 124 |
121 test_writeAsBytesSync_modifyAfterWrite() async { | 125 test_writeAsBytesSync_modifyAfterWrite() async { |
122 var bytes = [1]; | 126 var bytes = [1]; |
123 file.writeAsBytesSync(bytes); | 127 file.writeAsBytesSync(bytes); |
124 bytes[0] = 2; | 128 bytes[0] = 2; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 String tempPath; | 286 String tempPath; |
283 | 287 |
284 String join(String path1, String path2, [String path3, String path4]) => | 288 String join(String path1, String path2, [String path3, String path4]) => |
285 pathos.windows.join(path1, path2, path3, path4); | 289 pathos.windows.join(path1, path2, path3, path4); |
286 | 290 |
287 void setUp() { | 291 void setUp() { |
288 tempPath = r'c:\test_file_system'; | 292 tempPath = r'c:\test_file_system'; |
289 fileSystem = new MemoryFileSystem(Uri.parse('file:///c:/cwd')); | 293 fileSystem = new MemoryFileSystem(Uri.parse('file:///c:/cwd')); |
290 } | 294 } |
291 } | 295 } |
OLD | NEW |