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 |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 test_equals_samePath() { | 40 test_equals_samePath() { |
41 expect(file == entityForPath(join(tempPath, 'file.txt')), isTrue); | 41 expect(file == entityForPath(join(tempPath, 'file.txt')), isTrue); |
42 } | 42 } |
43 | 43 |
44 test_hashCode_samePath() { | 44 test_hashCode_samePath() { |
45 expect(file.hashCode, entityForPath(join(tempPath, 'file.txt')).hashCode); | 45 expect(file.hashCode, entityForPath(join(tempPath, 'file.txt')).hashCode); |
46 } | 46 } |
47 | 47 |
48 test_path() { | 48 test_path() { |
49 expect(file.uri, fileSystem.context.toUri(path)); | 49 expect(file.uri, context.toUri(path)); |
50 } | 50 } |
51 | 51 |
52 test_readAsBytes_badUtf8() async { | 52 test_readAsBytes_badUtf8() async { |
53 // A file containing invalid UTF-8 can still be read as raw bytes. | 53 // A file containing invalid UTF-8 can still be read as raw bytes. |
54 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8 | 54 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8 |
55 file.writeAsBytesSync(bytes); | 55 file.writeAsBytesSync(bytes); |
56 expect(await file.readAsBytes(), bytes); | 56 expect(await file.readAsBytes(), bytes); |
57 } | 57 } |
58 | 58 |
59 test_readAsBytes_doesNotExist() { | 59 test_readAsBytes_doesNotExist() { |
(...skipping 19 matching lines...) Expand all Loading... |
79 var s = 'contents'; | 79 var s = 'contents'; |
80 file.writeAsStringSync(s); | 80 file.writeAsStringSync(s); |
81 expect(await file.readAsString(), s); | 81 expect(await file.readAsString(), s); |
82 } | 82 } |
83 | 83 |
84 test_readAsString_utf8() async { | 84 test_readAsString_utf8() async { |
85 file.writeAsBytesSync([0xe2, 0x82, 0xac]); // Unicode € symbol, in UTF-8 | 85 file.writeAsBytesSync([0xe2, 0x82, 0xac]); // Unicode € symbol, in UTF-8 |
86 expect(await file.readAsString(), '\u20ac'); | 86 expect(await file.readAsString(), '\u20ac'); |
87 } | 87 } |
88 | 88 |
| 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 |
89 test_writeAsBytesSync_modifyAfterRead() async { | 115 test_writeAsBytesSync_modifyAfterRead() async { |
90 file.writeAsBytesSync([1]); | 116 file.writeAsBytesSync([1]); |
91 (await file.readAsBytes())[0] = 2; | 117 (await file.readAsBytes())[0] = 2; |
92 expect(await file.readAsBytes(), [1]); | 118 expect(await file.readAsBytes(), [1]); |
93 } | 119 } |
94 | 120 |
95 test_writeAsBytesSync_modifyAfterWrite() async { | 121 test_writeAsBytesSync_modifyAfterWrite() async { |
96 var bytes = [1]; | 122 var bytes = [1]; |
97 file.writeAsBytesSync(bytes); | 123 file.writeAsBytesSync(bytes); |
98 bytes[0] = 2; | 124 bytes[0] = 2; |
(...skipping 16 matching lines...) Expand all Loading... |
115 file.writeAsStringSync('\u20ac'); // Unicode € symbol | 141 file.writeAsStringSync('\u20ac'); // Unicode € symbol |
116 expect(await file.readAsBytes(), [0xe2, 0x82, 0xac]); | 142 expect(await file.readAsBytes(), [0xe2, 0x82, 0xac]); |
117 } | 143 } |
118 } | 144 } |
119 | 145 |
120 abstract class MemoryFileSystemTestMixin extends _BaseTest { | 146 abstract class MemoryFileSystemTestMixin extends _BaseTest { |
121 Uri tempUri; | 147 Uri tempUri; |
122 | 148 |
123 setUp() { | 149 setUp() { |
124 super.setUp(); | 150 super.setUp(); |
125 tempUri = fileSystem.context.toUri(tempPath); | 151 tempUri = context.toUri(tempPath); |
126 } | 152 } |
127 | 153 |
128 test_currentDirectory_trailingSlash() { | 154 test_currentDirectory_trailingSlash() { |
129 // The currentDirectory should already end in a trailing slash. | 155 // The currentDirectory should already end in a trailing slash. |
130 expect(fileSystem.currentDirectory.path, endsWith('/')); | 156 expect(fileSystem.currentDirectory.path, endsWith('/')); |
131 // A trailing slash should automatically be appended when creating a | 157 // A trailing slash should automatically be appended when creating a |
132 // MemoryFileSystem. | 158 // MemoryFileSystem. |
133 var path = fileSystem.currentDirectory.path; | 159 var path = fileSystem.currentDirectory.path; |
134 var currentDirectoryWithoutSlash = fileSystem.currentDirectory | 160 var currentDirectoryWithoutSlash = fileSystem.currentDirectory |
135 .replace(path: path.substring(0, path.length - 1)); | 161 .replace(path: path.substring(0, path.length - 1)); |
136 expect( | 162 expect(new MemoryFileSystem(currentDirectoryWithoutSlash).currentDirectory, |
137 new MemoryFileSystem(fileSystem.context, currentDirectoryWithoutSlash) | |
138 .currentDirectory, | |
139 fileSystem.currentDirectory); | 163 fileSystem.currentDirectory); |
140 // If the currentDirectory supplied to the MemoryFileSystem constructor | 164 // If the currentDirectory supplied to the MemoryFileSystem constructor |
141 // already has a trailing slash, no further trailing slash should be added. | 165 // already has a trailing slash, no further trailing slash should be added. |
142 expect( | 166 expect(new MemoryFileSystem(fileSystem.currentDirectory).currentDirectory, |
143 new MemoryFileSystem(fileSystem.context, fileSystem.currentDirectory) | |
144 .currentDirectory, | |
145 fileSystem.currentDirectory); | 167 fileSystem.currentDirectory); |
146 } | 168 } |
147 | 169 |
148 test_entityForPath_absolutize() { | 170 test_entityForPath_absolutize() { |
149 expect(entityForPath('file.txt').uri, | 171 expect(entityForPath('file.txt').uri, |
150 fileSystem.currentDirectory.resolve('file.txt')); | 172 fileSystem.currentDirectory.resolve('file.txt')); |
151 } | 173 } |
152 | 174 |
153 test_entityForPath_normalize_dot() { | 175 test_entityForPath_normalize_dot() { |
154 expect(entityForPath(join(tempPath, '.', 'file.txt')).uri, | 176 expect(entityForPath(join(tempPath, '.', 'file.txt')).uri, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 228 |
207 @reflectiveTest | 229 @reflectiveTest |
208 class MemoryFileSystemTestPosix extends _BaseTestPosix | 230 class MemoryFileSystemTestPosix extends _BaseTestPosix |
209 with MemoryFileSystemTestMixin {} | 231 with MemoryFileSystemTestMixin {} |
210 | 232 |
211 @reflectiveTest | 233 @reflectiveTest |
212 class MemoryFileSystemTestWindows extends _BaseTestWindows | 234 class MemoryFileSystemTestWindows extends _BaseTestWindows |
213 with MemoryFileSystemTestMixin {} | 235 with MemoryFileSystemTestMixin {} |
214 | 236 |
215 abstract class _BaseTest { | 237 abstract class _BaseTest { |
| 238 pathos.Context get context; |
216 MemoryFileSystem get fileSystem; | 239 MemoryFileSystem get fileSystem; |
217 | 240 |
218 String get tempPath; | 241 String get tempPath; |
219 | 242 |
220 MemoryFileSystemEntity entityForPath(String path) => | 243 MemoryFileSystemEntity entityForPath(String path) => |
221 fileSystem.entityForUri(fileSystem.context.toUri(path)); | 244 fileSystem.entityForUri(context.toUri(path)); |
222 | 245 |
223 String join(String path1, String path2, [String path3, String path4]); | 246 String join(String path1, String path2, [String path3, String path4]); |
224 | 247 |
225 void setUp(); | 248 void setUp(); |
226 } | 249 } |
227 | 250 |
228 class _BaseTestNative extends _BaseTest { | 251 class _BaseTestNative extends _BaseTest { |
| 252 final pathos.Context context = pathos.context; |
229 MemoryFileSystem fileSystem; | 253 MemoryFileSystem fileSystem; |
230 String tempPath; | 254 String tempPath; |
231 | 255 |
232 String join(String path1, String path2, [String path3, String path4]) => | 256 String join(String path1, String path2, [String path3, String path4]) => |
233 pathos.join(path1, path2, path3, path4); | 257 pathos.join(path1, path2, path3, path4); |
234 | 258 |
235 setUp() { | 259 setUp() { |
236 tempPath = pathos.join(io.Directory.systemTemp.path, 'test_file_system'); | 260 tempPath = pathos.join(io.Directory.systemTemp.path, 'test_file_system'); |
237 fileSystem = new MemoryFileSystem( | 261 fileSystem = new MemoryFileSystem(pathos.toUri(io.Directory.current.path)); |
238 pathos.context, pathos.toUri(io.Directory.current.path)); | |
239 } | 262 } |
240 } | 263 } |
241 | 264 |
242 class _BaseTestPosix extends _BaseTest { | 265 class _BaseTestPosix extends _BaseTest { |
| 266 final pathos.Context context = pathos.posix; |
243 MemoryFileSystem fileSystem; | 267 MemoryFileSystem fileSystem; |
244 String tempPath; | 268 String tempPath; |
245 | 269 |
246 String join(String path1, String path2, [String path3, String path4]) => | 270 String join(String path1, String path2, [String path3, String path4]) => |
247 pathos.posix.join(path1, path2, path3, path4); | 271 pathos.posix.join(path1, path2, path3, path4); |
248 | 272 |
249 void setUp() { | 273 void setUp() { |
250 tempPath = '/test_file_system'; | 274 tempPath = '/test_file_system'; |
251 fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///cwd')); | 275 fileSystem = new MemoryFileSystem(Uri.parse('file:///cwd')); |
252 } | 276 } |
253 } | 277 } |
254 | 278 |
255 class _BaseTestWindows extends _BaseTest { | 279 class _BaseTestWindows extends _BaseTest { |
| 280 final pathos.Context context = pathos.windows; |
256 MemoryFileSystem fileSystem; | 281 MemoryFileSystem fileSystem; |
257 String tempPath; | 282 String tempPath; |
258 | 283 |
259 String join(String path1, String path2, [String path3, String path4]) => | 284 String join(String path1, String path2, [String path3, String path4]) => |
260 pathos.windows.join(path1, path2, path3, path4); | 285 pathos.windows.join(path1, path2, path3, path4); |
261 | 286 |
262 void setUp() { | 287 void setUp() { |
263 tempPath = r'c:\test_file_system'; | 288 tempPath = r'c:\test_file_system'; |
264 fileSystem = | 289 fileSystem = new MemoryFileSystem(Uri.parse('file:///c:/cwd')); |
265 new MemoryFileSystem(pathos.windows, Uri.parse('file:///c:/cwd')); | |
266 } | 290 } |
267 } | 291 } |
OLD | NEW |